Precise image overlay over video using ffmpeg

2019-06-14 17:41发布

I want to overlay various icon-images over a given video (which is created using the sequence of images) in a time and position precise manner. I am using FFmpeg for the same. Here are the commands I am using:

Image to video conversion command

ffmpeg -framerate 5 -start_number 0 -i images/img%04d.png -vframes 1000 -r 30 -vcodec libx264 -crf 25  -pix_fmt yuv420p out.mp4 -y

Images superimpose over video command

ffmpeg -analyzeduration 10000 -hwaccel auto -i out.mp4 -i icons/up.png -i icons/down.png -i icons/left.png -i icons/right.png -i icons/top.png -i icons/bottom.png -i icons/side.png -filter_complex [0:v]setpts=PTS-STARTPTS[0];
[1:v]setpts=PTS-STARTPTS[i1];
[2:v]setpts=PTS-STARTPTS[i2];
[3:v]setpts=PTS-STARTPTS[i3];
[4:v]setpts=PTS-STARTPTS[i4];
[5:v]setpts=PTS-STARTPTS[i5];
[6:v]setpts=PTS-STARTPTS[i6];
[0][i1]overlay=211.875:319.916:enable='between(t,0.610,0.910)'[1];
[1][i2]overlay=212.344:309.516:enable='between(t,1.810,2.110)'[2];
[2][i3]overlay=37.969:332.396:enable='between(t,2.775,3.075)'[3];
[3][i4]overlay=202.500:307.436:enable='between(t,3.626,3.926)'[4];
[4][i5]overlay=37.734:296.203:enable='between(t,4.531,4.831)'[5];
[5][i6]overlay=208.359:313.676:enable='between(t,5.602,5.902)'[6];
[6][i7]overlay=34.688:383.150:enable='between(t,6.733,7.033)'[7];
-map [7] -y -movflags +faststart superimposed.mp4

My problem is that I am not getting precision in time. i.e. if there is an icon to be overlayed at 0.61 sec, it doesn't come exactly at 0.61 sec. Sometimes it comes at 1.0 sec, sometimes at 0.30 sec and sometimes at some other unpredictable time.

I have an HTML5 video player where the user is allowed to seek the video with 100-millisecond precision. The user expects the icon to see precisely at 0.61 sec. However, above inaccuracy limits the capabilities of my video player.

Please suggest what could be wrong in my implementation/command.

标签: ffmpeg
0条回答
登录 后发表回答