树莓派

树莓派推流脚本

2018-10-14  本文已影响0人  飞鱼ll
#!/bin/sh 

# get rid of the cursor so we don't see it when videos are running 
setterm -cursor off 

# set here the path to the directory containing your videos 
VIDEOPATH="/home/pi/Videos/360p" 

# you can normally leave this alone 
SERVICE="ffmpeg -re -i"
#SERVICE2="-vcodec libx264 -acodec copy -vf scale=360:640 -b:v 400k -b:a 120k -f flv rtmp://www.chaisz.xyz/live/livestream"
SERVICE2="-c copy -f flv rtmp://www.xxx.com/room"

for entry in $VIDEOPATH/* 
    do 
     clear 
    $SERVICE $entry $SERVICE2 > /dev/null 

    while ps ax | grep -v grep | grep $SERVICE > /dev/null 
    do 
     sleep 5; 
    done 
done 

这段代码的作用是把/home/pi/Videos/360p目录下的视频推到rtmp://www.xxx.com/room 这个地址
服务器带宽只有1Mb,也就360p的可以流畅播放了。

树莓派3B安装ffmpeg

1。 安装sdl2

sudo apt-get install libsdl2-dev

2。安装x264

git clone git://git.videolan.org/x264.git
cd x264

./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl --enable-shared

make -j4
sudo make install

【增加选项 –enable-shared可避免安装 ffmpeg 时出现错误 ERROR: libx264 not found】
树莓派是4核CPU,编译时加上 -j4可以加快编译速度
3。安装ffmpeg

git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg

./configure --arch=armv7l --target-os=linux \
--enable-gpl --enable-libx264 \
--enable-nonfree \
\
--enable-omx \
--enable-omx-rpi \
--enable-encoder=h264_omx \
\
--enable-mmal \
--enable-hwaccel=h264_mmal \
--enable-decoder=h264_mmal

make -j2
sudo make install

报错——ERROR: OMX_Core.h not found.
解决——sudo apt-get install libomxil-bellagio-dev

树莓派omxplayer可以流畅播放1080p的视频
安装

sudo apt-get install omxplayer

使用

omxplayer -r -o local videopath

播放脚本

#!/bin/sh 

# get rid of the cursor so we don't see it when videos are running 
setterm -cursor off 

# set here the path to the directory containing your videos 
VIDEOPATH="/home/pi/Videos/1080p" 

# you can normally leave this alone 
SERVICE="omxplayer -r -o local" 

for entry in $VIDEOPATH/* 
    do 
     clear 
    $SERVICE $entry > /dev/null 

    while ps ax | grep -v grep | grep $SERVICE > /dev/null 
    do 
     sleep 5; 
    done 
done 
上一篇下一篇

猜你喜欢

热点阅读