ffmpeg 2.3 blend视频叠加输出文件时间长度问题
2014 11 16
输入文件:
480x480.3gp: 480x480,20fps,00:00:10
rain01.mp4: 480x480,25fps,00:00:03
ffmpeg -y -i 480x480.3gp -i rain01.mp4 -filter_complex blend=all_expr='if(eq(mod(X,2),mod(Y,2)),A,B)' -c:v libx264 -an -strict -2 -qp 30 blend.3gp
得到的输出视频长度是10秒
而
ffmpeg -y -i 480x480.3gp -i rain01.mp4 -filter_complex blend=all_expr='if(eq(mod(X,2),mod(Y,2)),A,B)' -c:v libx264 -an -strict -2 -qp 30 blend.3gp
得到的输出视频长度是3秒
分析:
根据www.ffmpeg.org 上的文档: It takes two input streams and outputs one stream, the first input is the "top" layer and second input is "bottom" layer,
进一步分析,blend模块内部并没有停止。因为在 ff_dualinput_init函数里,in[0].after = EXT_INFINITY;表示top结束后整个模块并不停止。并且ff_framesync_get_frame(&s->fs, 0, &mainpic, 1)调用ff_framesync_get_frame函数时,get等于1,pts_next=INT64_MAX,所以会av_frame_clone最后一帧。
进一步跟踪,发现是do_video_out函数进入了nb_frames=0的分支,而将其drop了,具体原因可能是时间戳的问题,需要进一步分析。