Cannot use input file in filter_complex_script (movie filter)

Viewed 46

I am trying to edit some video footage using ffmpeg rather than a GUI editor.

This example works, to read a PNG file and overlay a resized video on top of it:

ffmpeg -y \
 -loop 1 -i 'Title.png' \
 -i 'Presentation.mp4' \
 -filter_complex_script 'my.nodes'  \
 -map "[video]" -map 1:a -codec:a copy output.mkv

The file my.nodes contains:

[1:v]scale=430:240[a];
[1:v]scale=1280:720[b];
[0:v][a]overlay=0:0[c];
[c][b]overlay=overlay_w*2:overlay_h:shortest=1[video]

However rather than referring to the input files as numbers (1:v etc.) I wanted to use the "movie" filter to input the files as a source filter, like this:

ffmpeg -y \
 -filter_complex_script 'my_improved.nodes'  \
 -map "[video]" output.mkv

The file my_improved.nodes contains:

movie=Title.png[title];
movie=Presentation.mp4[talk];
[talk]scale=430:240[a];
[talk]scale=1280:720[b];
[title][a]overlay=0:0[c];
[c][b]overlay=overlay_w*2:overlay_h:shortest=1[video]

This gives the error:

Invalid file index 0 in filtergraph description movie=Title.png[title];
movie=Presentation.mp4[talk];
[talk]scale=430:240[a];
[talk]scale=1280:720[b];
[title][a]overlay=0:0[c];
[c][b]overlay=overlay_w*2:overlay_h:shortest=1[video]
.

How can I embed video/image names into the filter itself?

1 Answers

I worked it out, but I think the error message was a tad obscure.

This works:

movie=Title.png[title];
movie=Presentation.mp4, split=2[talk1][talk2];
[talk1]scale=430:240[a];
[talk2]scale=1280:720[b];
[title][a]overlay=0:0[c];
[c][b]overlay=overlay_w*2:overlay_h:shortest=1[video]

In the non-working example I had the input movie=Presentation.mp4[talk]; giving one output node [talk].

This was then used twice in the "scale" lines, so effectively the first input was consumed, and the second one wasn't available (it seems).

By adding split=2[talk1][talk2] to the second line, I got two output nodes, which could then be consumed by the "scale" lines.

It seems inconsistent that I could use [1:v] twice as inputs in the working version in the question, but not [talk] twice as inputs in the non-working version.

Related