Search code examples
windowsbatch-fileffmpegdrawtext

Merging\Joining three FFMPEG Commands (Drawtext / -filter_complex overlay / anullsrc=channel_layout)


Currently I am using three different commands to create three mp4s only to delete the two "temporary" videos using this code.

@ECHO OFF
ffmpeg -f lavfi -i color=size=1280x720:duration=5:rate=25:color=Black -vf "drawtext=fontfile='GothamRnd-Book.otf':line_spacing=15:fontsize=15:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:text=Stack Exchange" "out1.mp4"
ffmpeg -i "out1.mp4" -i logo.png -filter_complex "overlay=x=10:y=10" "out2.mp4"
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 -i "out2.mp4" -c:v copy -c:a aac -shortest "out3.mp4"
del "out1.mp4"
del "out2.mp4"
pause

The nearest I have come is moving the anullsrc=channel_layout into the -filter_complex but that results in a long encode that I dont really understand what it is going because if I ctrl-c to cancel the batch still creates out3.mp4 correctly.

ffmpeg -f lavfi -i color=size=1280x720:duration=5:rate=25:color=Black -vf "drawtext=fontfile='GothamRnd-Book.otf':line_spacing=15:fontsize=15:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:text=Stack Exchange" "out1.mp4"
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000  -i "out1.mp4" -i logo.png -filter_complex "overlay=x=10:y=10" "out3.mp4"

It seems like this could be streamlined to not create the temporary files. But maybe this is the only way to do this. Thank you for any assistance and sorry if the answer is obvious.

Rory


Solution

  • Use

    ffmpeg -f lavfi -i color=s=1280x720:d=5:r=25:color=black -i logo.png -f lavfi -i anullsrc=cl=stereo:d=5:r=48000 -filter_complex "[0]drawtext=fontfile='GothamRnd-Book.otf':line_spacing=15:fontsize=15:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:text=Stack Exchange[vid];[vid][1]overlay=x=10:y=10" -c:v libx264 -c:a aac "out3.mp4"