在@Gyan的帮助下,我想出了以下FFMPEG命令,它将4个视频同时传输到4个独立的RTMP端点,无限循环播放视频并保持音频和视频同步:
ffmpeg \
-filter_complex \
"movie=01.mp4:loop=0[v1];[v1]setpts=N/FRAME_RATE/TB[v1];
amovie=01.mp4:loop=0[a1];[a1]asetpts=N/SR/TB[a1];
movie=02.mp4:loop=0[v2];[v2]setpts=N/FRAME_RATE/TB[v2];
amovie=02.mp4:loop=0[a2];[a2]asetpts=N/SR/TB[a2];
movie=03.mp4:loop=0[v3];[v3]setpts=N/FRAME_RATE/TB[v3];
amovie=03.mp4:loop=0[a3];[a3]asetpts=N/SR/TB[a3];
movie=04.mp4:loop=0[v4];[v4]setpts=N/FRAME_RATE/TB[v4];
amovie=04.mp4:loop=0[a4];[a4]asetpts=N/SR/TB[a4]" \
-map "[v1]" -map "[a1]" \
-c:a libfdk_aac \
-c:v libx264 -preset ultrafast \
-b:v 500k -b:a 32k \
-f flv rtmp://output/01 \
-map "[v2]" -map "[a2]" \
-c:a libfdk_aac \
-c:v libx264 -preset ultrafast \
-b:v 500k -b:a 32k \
-f flv rtmp://output/02 \
-map "[v3]" -map "[a3]" \
-c:a libfdk_aac \
-c:v libx264 -preset ultrafast \
-b:v 500k -b:a 32k \
-f flv rtmp://output/03 \
-map "[v4]" -map "[a4]" \
-c:a libfdk_aac \
-c:v libx264 -preset ultrafast \
-b:v 500k -b:a 32k \
-f flv rtmp://output/04
几乎完美,除了它的帧速率加倍:
frame=20822 fps= 46 q=32.0 q=34.0 q=29.0 q=32.0 size= 57617kB time=00:14:28.39 bitrate= 543.5kbits/s speed=1.92x
注意speed=1.92x
位。这也导致实时流以双倍速度播放。
(原始视频大约是24 fps)