0

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?

Yoz
  • 707
  • 6
  • 20
  • Can't test now, but since your `w` expr is unbounded, it overshoots the input width. Change it to `min((N*10)+10\,iw)` – Gyan Oct 13 '21 at 15:09
  • hi @Gyan thanks for the suggestion. Unfortunately iw/ih is not available in sendcmd, but that would still not solve the issue as it appears wrong even earlier before width is overshooted. I actually think sendcmd.w for crop is broken and reported on https://trac.ffmpeg.org/ticket/9454 for the time being I am using overlay alternative - see my own answer – Yoz Oct 15 '21 at 06:36
  • re: sendcmd, leave out '[expr]` and use the constants in the crop filter. – Gyan Oct 15 '21 at 08:29
  • Leaving out `[expr]` in `sendcmd` does not let me use iw in 4.4 – Yoz Oct 18 '21 at 07:17

2 Answers2

0

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

Yoz
  • 707
  • 6
  • 20
0

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]
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Hi Gyan, thanks for your suggestions. I just tried adding `scale=eval=frame` still produces the same artefacts here on my side. Do you see different using 4.4 or other version? – Yoz Oct 18 '21 at 07:16
  • Btw. I just explored `fillborders` as a solid alternative – Yoz Oct 18 '21 at 07:16