FFmpeg animated crop produces artefacts

326 Views Asked by At

Using ffmpeg 4.4, I am trying to crop video and actually animate the width in time using sendcmd + crop. This however leaves artefacts (either green color or the video being repainted repeatedly horizontally/vertically) rendered outside of the cropped area.

Commands to replicate:

ffmpeg -f lavfi -i color=color=0xff0000:size=1280x720:rate=25 -filter_complex_script filter.txt -map [v] -t 4 out.mp4 -y

filter.txt

movie=video.mp4,sendcmd=c='0 [expr] crop w (N*10)+10',crop[v];
[0][v]overlay=x=n:eof_action=pass:eval=frame[v]

Any idea how to get rid of these artefacts?

enter image description here

Or maybe there is some alternative ffmpeg filter that would do the crop work with eval=frame instead of sendcmd?

2

There are 2 best solutions below

0
On

I ended up using little overlay hack to simulate crop:

ffmpeg -f lavfi -i color=color=0xff0000:size=1280x720:rate=25 -filter_complex_script overlay-filter.txt -map [v] -t 4 output/overlay.mp4 -y

fiter.txt

movie=input/video.mp4[v];
color=c=#000000:s=2x2:rate=25[c];
[c][v]scale2ref=flags=neighbor:eval=frame[c][v];
[c]scale=flags=neighbor:w=n*10+10:h=ih:eval=frame[c];
[c][v]overlay=x=(main_w-overlay_w)/2:eval=frame:eof_action=endall[v];
[0][v]overlay=x=n:eof_action=pass:eval=frame[v]

Issue with crop reported on https://trac.ffmpeg.org/ticket/9454

2
On

While I debug what's happening, use this filtergraph.

movie=video.mp4,sendcmd=c='0 [expr] crop w (N*10)+10',crop,scale=eval=frame[v];
[0][v]overlay=x=n:eof_action=pass:eval=frame[v]