我想编写一个自定义的bash脚本,该脚本将对流的运行状况起作用,并且在出现错误的情况下将尝试修复或重新启动流
我正在尝试使用以下命令流式传输实时视频:
ffmpeg -re -i input.ts or .m3u8 -c:v libx264 -c:a libmp3lame -ar 44100 -ac 1 -f flv rtmp://ip/application name/stream key
一段时间后,我的流自动关闭,并显示以下错误:
[flv @ 0x5c1d580] Failed to update header with correct duration. [flv @ 0x5c1d580] Failed to update header with correct filesize.
下面是完整的错误详细信息-
[flv @ 0x5c1d580] Failed to update header with correct duration. [flv @ 0x5c1d580] Failed to update header with correct filesize. frame= 2810 fps= 11 q=-1.0 Lsize= 23375kB time=00:01:52.43 bitrate=1703.1kbits/s speed=0.45x video:22374kB audio:879kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.527018% [libx264 @ 0x5c27400] frame I:13 Avg QP:18.87 size: 78912 [libx264 @ 0x5c27400] frame P:871 Avg QP:22.12 size: 17876 [libx264 @ 0x5c27400] frame B:1926 Avg QP:27.19 size: 3279 [libx264 @ 0x5c27400] consecutive B-frames: 4.9% 9.5% 5.2% 80.4% [libx264 @ 0x5c27400] mb I I16..4: 9.2% 72.5% 18.3% [libx264 @ 0x5c27400] mb P I16..4: 2.3% 6.3% 0.7% P16..4: 42.3% 11.9% 6.6% 0.0% 0.0% skip:30.0% [libx264 @ 0x5c27400] mb B I16..4: 0.1% 0.2% 0.0% B16..8: 38.6% 2.7% 0.5% direct: 0.6% skip:57.2% L0:43.8% L1:52.9% BI: 3.4% [libx264 @ 0x5c27400] 8x8 transform intra:67.8% inter:78.0% [libx264 @ 0x5c27400] coded y,uvDC,uvAC intra: 48.8% 68.1% 23.0% inter: 8.1% 10.7% 0.7% [libx264 @ 0x5c27400] i16 v,h,dc,p: 17% 40% 17% 26% [libx264 @ 0x5c27400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 25% 29% 4% 6% 5% 6% 4% 6% [libx264 @ 0x5c27400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 24% 20% 4% 7% 7% 6% 5% 5% [libx264 @ 0x5c27400] i8c dc,h,v,p: 51% 26% 18% 5% [libx264 @ 0x5c27400] Weighted P-Frames: Y:0.0% UV:0.0% [libx264 @ 0x5c27400] ref P L0: 69.6% 13.2% 13.8% 3.5% [libx264 @ 0x5c27400] ref B L0: 91.3% 7.7% 1.1% [libx264 @ 0x5c27400] ref B L1: 97.8% 2.2% [libx264 @ 0x5c27400] kb/s:1630.03
请帮我调试一下吗?
答案 0 :(得分:0)
您可以从此脚本开始,它将尝试10次流命令并报告成功或失败:
#!/bin/bash
RETRY=10
RUN_STREAM="ffmpeg -re -i input.ts or .m3u8 -c:v libx264 -c:a libmp3lame -ar 44100 -ac 1 -f flv rtmp://ip/a"
EXIT_CODE=1
for i in $(seq 1 $RETRY)
do
$RUN_STREAM
if [ $? -eq 0 ]; then
echo Stream sent Ok
EXIT_CODE=0
break
else
echo Try number $i failed, will try again
continue
fi
done
if [ $EXIT_CODE -eq 1 ]; then
echo Streaming failed.
fi