Activity › Forums › Compression Techniques › FFMPEG: Add black frames at start and end of video
-
FFMPEG: Add black frames at start and end of video
Lou Logan replied 6 years, 8 months ago 6 Members · 22 Replies
-
Lou Logan
August 20, 2014 at 7:41 pm[Thomas Demirian] “But now I have to mix these two together so that its 10 seconds of text at the start. Then the video. And lastly 30 seconds of black.”
You can connect a sequence of filters with commas. This is called a filterchain. You can connect a sequence of filterchains with semicolons, and the whole thing is called a filtergraph:
ffmpeg -i Input.mov -f lavfi -i "color=c=black:s=720x576:r=25:sar=1050/720" -filter_complex \
"[0:v] setpts=PTS-STARTPTS [main]; \
[1:v] trim=end=10,drawtext=fontfile=/Library/Fonts/Georgia.ttf:text='Text to write':fontsize=30:fontcolor=white:x=(w-text_w)/2:y=(h-text_h-line_h)/2,setpts=PTS-STARTPTS [pre]; \
[1:v] trim=end=30,setpts=PTS-STARTPTS [post]; \
[pre][main][post] concat=n=3:v=1:a=0 [out]" \
-map "[out]" -vcodec mpeg2video -maxrate 30000k -b:v 30000k Output.mpg -
Faraz Ahmed
March 7, 2019 at 1:14 pmHello @Lou Logan,
Its work but output is without audio.
Can we use Input.mov audio in output video “Output.mpg”?
I have tried many ways but not succeeded as i am new to FFMPEGThanks,
Faraz -
Lou Logan
March 7, 2019 at 8:12 pmThere is a better, easier method now using the tpad and adelay filters. This example will add 10 seconds of black video and delay the audio by 10 seconds:
ffmpeg -i input -filter_complex "[0:v]tpad=start_duration=10:color=black[v];[0:a]adelay=10000|10000[a]" -map "[v]" -map "[a]" outputThe tpad filter is newer than any release version, and release versions don’t get new features backported, so it won’t be in any release until version 4.2. This is one reason why general users are recommended to always use a recent build from the git master branch. See the FFmpeg Download page for links to already compiled builds from the git master branch for Linux, macOS, and Windows.
-
Faraz Ahmed
March 8, 2019 at 10:07 amHello @Lou Logan,
Thanks for your reply can you please let me know how i install latest version on windows i have installed latest version by downloading from https://ffmpeg.zeranoe.com/builds/ on my windows but it gives me error “no such filter: tpad”
Thanks,
Faraz -
Lou Logan
March 8, 2019 at 7:51 pmI’m guessing you downloaded the release version 4.1.1. As I mentioned no release has tpad.
Download the “nightly get version” instead. It will be named something like “20190308-9645147”.
-
Andrew Baldinger
October 9, 2019 at 5:46 pmHi Lou,
That was a big help! I appreciate you sharing. Could you help me modify that to add the 10 seconds to the end instead of the beginning?Thanks!
Andrew -
Andrew Baldinger
October 9, 2019 at 6:27 pmActually, I think I answered my own question:
ffmpeg -i input -filter_complex “[0:v]tpad=stop_duration=10:color=black[v]” -map “[v]” output
Right?
-
Lou Logan
October 9, 2019 at 6:35 pmWith just video:
ffmpeg -i input -filter_complex "tpad=stop_duration=10" outputWith video and audio:
ffmpeg -i input -filter_complex "[0:v]tpad=stop_duration=10[v];[0:a]apad[a]" -map "[v]" -map "[a]" -shortest outputHowever, this second example will not work. I believe there is an existing bug so this command will encode indefinitely (at least at the time I wrote this, but it will probably be fixed eventually).
So you can add the -t option instead of -shortest:
ffmpeg -i input -filter_complex "[0:v]tpad=stop_duration=10[v];[0:a]apad[a]" -map "[v]" -map "[a]" -t 60 outputIf you want to script it use ffprobe to get the input duration and -t should be input duration + stop_duration.
Alternatively, use the color source filter and anullsrc filter to create 10 second black video and silent audio, then concatenate with the concat filter or concat demuxer. Note that all parameters must match the input for proper concatenation, so it can be tricky. If you do it right you can avoid re-encoding if you use the concat demuxer.
Reply to this Discussion! Login or Sign Up