1

I try to create a command that will add the intro to the start of an arbitrary video file. But that file can have arbitrary size, aspect ratio, even pixel format.

So I need to resize intro and add pads if necessary before concatenation, then concatenate intro and the file, then convert with right codec and pixel format (using -codec and -pix_fmt for this).

I suppose that the video file can be absolutely any dimension and aspect ratio: wide, square, even vertical. So I need to fit the intro into the target dimension by adding paddings.

There is what I use:

ffmpeg -i intro.mp4 -i video.mp4 -filter_complex \
    "[0][1]scale2ref=iw:ih:force_original_aspect_ratio=decrease[intro][main], \
    [intro]pad=ow:oh:(ow-iw)/2:(oh-ih)/2[0:v]; [0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" \
    -map '[v]' -map '[a]' -sws_flags spline -vcodec libx264 -movflags +faststart \
    -r 25 -g 50 -crf 18 -me_method umh -pix_fmt yuv420p -trellis 0 -bf 8 -acodec aac 
    -strict -2 -ar 44100 -ab 128k -f mp4 out.mp4 -y

But still can't figure out...

Now there is the error:

Filter scale2ref:ref has an unconnected output

FFmpeg version:

ffmpeg version git-2019-10-19-31aafda Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20191010

Thank you!

1 Answer 1

2

The scale2ref declaration should be terminated with a semi-colon, not a comma. Since it's a separate filterchain from the one with the pad that follows it.

A filter_complex declares a filtergraph, which is composed of one or more filterchains. If a filter's inputs are exactly the same as the outputs of the filter preceding it, then they can be part of the same filterchain and the preceding filter may be terminated with a comma. In this case, the pad only accepts a single input - the resized intro but not the reference main video. The main video from the scale2ref has to be either consumed by another filter or sent out for standalone encoding. In this case, it should have gone to the concat filter (not used 1:v)

In any case, the syntax error was masking a logic error. The pad has no reference for what the output size should be - its width and height expressions are circular. The task has to be carried out a different way. First, one copy of the intro has to be resized to the exact size of the main video and painted fully black, then another copy has to use the resized first copy as reference and scale to best fit. Then the second copy is overlaid in the center. This result can then be joined with the main video.

Use

ffmpeg -i intro.mp4 -i video.mp4 -filter_complex "[0][1]scale2ref=iw:ih[intro][main];[intro]drawbox=t=fill[intro-bg];[0][intro-bg]scale2ref=iw:ih:force_original_aspect_ratio=decrease:flags=spline[intro][intro-bg];[intro-bg][intro]overlay=x='(W-w)/2':y='(H-h)/2'[intro-resized]; [intro-resized][0:a][main][1:a]concat=n=2:v=1:a=1:unsafe=1[v][a]" -map '[v]' -map '[a]' -c:v libx264 -movflags +faststart -r 25 -g 50 -crf 18 -me_method umh -pix_fmt yuv420p -trellis 0 -bf 8 -acodec aac -ar 44100 -ab 128k -f mp4 out.mp4 -y

3
  • Thank you, Gyan. I updated the post with some lines from log. Still have some errors, If you can see any point of the issue there? Thx. Commented Oct 30, 2019 at 6:28
  • Updated command.
    – Gyan
    Commented Oct 30, 2019 at 8:02
  • Thanks a lot!!! Your help was really the escape for me today :-) Thank you, Gyan! Commented Oct 30, 2019 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .