0

ffmpeg noob here, trying to help my mother with some videos for real estate walkthroughs. I'd like to set up a simple pipeline that I can run videos through and have outputted as such:

  • 5 second (silent) title card ->
  • xfade transition ->
  • property walk through ->
  • xfade transition ->
  • 5 second (silent) title card

Considerations:

  • The intro / outro card will be the same content.
  • The input walkthrough videos will be of variable length so, if possible, a dynamic solution accounting for this would be ideal. If this requires me to script something using ffprobe, I can do that - just need to gain an understanding of the syntax and order of operations.
  • The video clip will come in with some audio already overlaid. I would like for the title cards to be silent, and have the video/audio clip fade in/out together.

I have gotten a sample working without the transitions:

ffmpeg -loop 1 -t 5 -i title_card.jpg \
    -i walkthrough.MOV \
    -f lavfi -t 0.1 -i anullsrc \
    -filter_complex "[0][2][1:v][1:a][0][2]concat=n=3:v=1:a=1[v][a]" \
    -map "[v]" -map "[a]" \
    -vcodec libx265 \
    -crf 18 \
    -vsync 2 \
    output_without_transitions.mp4

I have been unable to get it to work with transitions. See below for the latest iteration:

ffmpeg -loop 1 -t 5 -r 60 -i title_card.jpg \
    -r 60 -i walkthrough.MOV \
    -f lavfi -t 0.1 -i anullsrc \
    -filter_complex \
    "[0][1:v]xfade=transition=fade:duration=0.5:offset=4.5[v01]; \
    [v01][0]xfade=transition=fade:duration=0.5:offset=12.8[v]" \
    -map "[v]" \
    -vcodec libx265 \
    -crf 18 \
    -vsync 2 \
    output_with_transitions.mp4

This half-works, resulting in the initial title card, fading into the video, but the second title card never occurs. Note, I also removed any references to audio, in an effort to get the transitions alone to work.

I have been beating my head against the wall on this, so help would be appreciated :)

createchange
  • 79
  • 2
  • 9

1 Answers1

0

Assuming walkthrough.MOV is 10 seconds long:

ffmpeg -loop 1 -t 5 -framerate 30 -i title_card.jpg -i walkthrough.MOV -filter_complex "[0]settb=AVTB,split[begin][end];[1:v]settb=AVTB[main];[begin][main]xfade=transition=fade:duration=1:offset=4[xf];[xf][end]xfade=transition=fade:duration=1:offset=13,format=yuv420p[v];[1:a]adelay=4s:all=1,afade=t=in:start_time=4:duration=1,afade=t=out:start_time=13:duration=1,apad=pad_dur=4[a]" -map "[v]" -map "[a]" -c:v libx265 -crf 18 -movflags +faststart output.mp4
  • You will need to upgrade your ffmpeg for this to work. The current release version (4.3 as of this answer) is too old, so get a build from the git master branch. See FFmpeg Download for links to builds for your OS, or see FFmpeg Wiki: Compile Guide.
  • title_card.jpg frame rate, width, and height must match walkthrough.MOV.
  • See Merging multiple video files with ffmpeg and xfade filter to see how to calculate xfade and afade offsets.
  • See FFmpeg Filter documentation for details on each filter.
  • See How to get video duration in seconds? which can help you automate this via scripting.
  • apad is supposed to automatically work with -shortest, but it doesn't with -filter_complex. So pad_dur is used to add the additional silence to the last title image, but whole_dur can be used instead if that is easier for you. Another method is to use anullsrc as in your question, then concatenate audio only with the concat filter, but I wanted to show adelay+apad as a viable alternative.
llogan
  • 121,796
  • 28
  • 232
  • 243