Activity › Forums › Compression Techniques › FFMPEG: Add black frames at start and end of video
-
FFMPEG: Add black frames at start and end of video
Posted by Thomas Demirian on June 11, 2014 at 9:21 amIm trying to add 10 second of black frames to the beginning of my clip and 30 seconds of black frames at end of clip. This is what I got so far.
————————————————————-
ffmpeg -i XX.mp4 -vf "
color=c=black:s=720x576:d=10 [pre] ;
color=c=black:s=720x576:d=30 [post] ;
[pre] [in] [post] concat=n=3" -an -vcodec mpeg2video -pix_fmt yuv422p -s 720v576 -aspect 16:9 -r 25 -minrate 30000k -maxrate 30000k -b 30000k output.mpg————————————————————-
It works in some cases. But Only on specific material with right “SAR” values. But most of the time I get this error.
————————————————————-
Input link in1:v0 parameters (size 720x576, SAR 35:24) do not match the corresponding output link in0:v0 parameters (720x576, SAR 1:1)
[Parsed_concat_2 @ 0x7f9853d048c0] Failed to configure output pad on Parsed_concat_2————————————————————-
Is there a way to complement my code or another way to do this?
Lou Logan replied 4 years, 11 months ago 6 Members · 22 Replies -
22 Replies
-
Thomas Demirian
June 12, 2014 at 8:15 amThanks but it does not work.
This code:
ffmpeg -aspect 16:9 -i Italy_169_5sec.mxf -vf "
color=c=black:s=720x576:d=10 [pre] ;
color=c=black:s=720x576:d=30 [post] ;
[pre] [in] [post] concat=n=3" -an -vcodec mpeg2video -pix_fmt yuv422p -s 720v576 -aspect 16:9 -r 25 -minrate 30000k -maxrate 30000k -b 30000k output.mpgGives me this error:
Option aspect (set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)) cannot be applied to input file Italy_169_5sec.mxf -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for input file Italy_169_5sec.mxf.
Error opening input files: Invalid argument -
Jim Sustacek
June 12, 2014 at 12:37 pm -
Lou Logan
June 13, 2014 at 7:27 pmPlease include the complete ffmpeg console output that results from the command that does not work as expected.
-
Reuben Martin
June 14, 2014 at 3:44 amI’m surprised you can’t override the aspect ratio of the input. You can do that for other several other properties.
You can do a stream copy to a new file first and force the 16:9 aspect, and then use the new file on place of the older one. I’ve done this with mp4 files. Not sure if it will work or not the mxf files.
For mp4 I do this:
ffmpeg -i inputfile.mp4 -c:v copy -aspect 16:9 -ca: copy -f mp4 outputfile.mp4
It gives a small warning about doing that, but it’s never cause problems for me. You can try it with mxf and see if it works. I don’t have much mxf content to test with, and there is a small chance that it may not work due to how the format stores its data.
ffmpeg -i inputfile.mxf -c:v copy -aspect 16:9 -ca: copy -f mxf outputfile.mxf
-
Thomas Demirian
June 15, 2014 at 7:12 pmLast login: Sun Jun 15 21:10:12 on ttys000
Thomas-MacBook-Pro:~ Thomas$ cd /Users/Thomas/Desktop/Redmine\ and\ Others/6676
Thomas-MacBook-Pro:6676 Thomas$ ffmpeg -i filesquare.mov -vf "
> color=c=black:s=720x576:d=10 [pre] ;
> color=c=black:s=720x576:d=30 [post] ;
> [pre] [in] [post] concat=n=3" -an -vcodec mpeg2video -minrate 30000k -maxrate 30000k -b 30000k xx.mpg
ffmpeg version 2.2.3 Copyright (c) 2000-2014 the FFmpeg developers
built on Jun 4 2014 15:38:57 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libass --enable-libbluray --enable-gnutls --enable-fontconfig --enable-libfreetype --disable-indev=jack --disable-outdev=xv --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --enable-vda --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libavresample 1. 2. 0 / 1. 2. 0
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'filesquare.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2014-06-09 15:24:21
Duration: 00:00:10.00, start: 0.000000, bitrate: 31619 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 788x576, 30077 kb/s, SAR 1023:788 DAR 341:192, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
Metadata:
creation_time : 2014-06-09 15:24:21
handler_name : Apple Alias Data Handler
timecode : 00:00:40:16
Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
creation_time : 2014-06-09 15:24:21
handler_name : Apple Alias Data Handler
timecode : 00:00:40:16
Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
creation_time : 2014-06-09 15:24:33
handler_name : Apple Alias Data Handler
timecode : 00:00:40:16
Please use -b:a or -b:v, -b is ambiguous
[Parsed_concat_2 @ 0x7f8061425040] Input link in1:v0 parameters (size 788x576, SAR 1023:788) do not match the corresponding output link in0:v0 parameters (720x576, SAR 1:1)
[Parsed_concat_2 @ 0x7f8061425040] Failed to configure output pad on Parsed_concat_2
Error opening filters!
Conversion failed!
Thomas-MacBook-Pro:6676 Thomas$
Thats the whole console output. Is there maybe someway that the “unsafe” filter can be implemented to fix this?
-
Lou Logan
June 15, 2014 at 8:06 pm- Use “-filter_complex” instead of “-vf” when filtering multiple inputs and/or multiple outputs.
- Make the blank video have the same parameters as the main video.
- Since concat required that all input timestamps start at zero it is usually a good idea to add the setpts filter to do so.
- If you’re declaring a video bitrate, use “-b:v” instead of “-b”, but since you’re only outputting video in this case it does not really matter.
Explicitly list the values for “n”, “v”, and “a” in concat instead of relying on the defaults.
ffmpeg -i input -f lavfi -i "color=c=black:s=720x576:r=25:sar=1023/788" -filter_complex \
"[0:v] setpts=PTS-STARTPTS [main]; \
[1:v] trim=end=10,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 -
Thomas Demirian
June 26, 2014 at 2:23 pmI have looked at your example and it makes sense. But I cant get it to work.
[Parsed_color_0 @ 0x103c00000] Option 'setsar' not found
[lavfi @ 0x103004800] Error initializing filter 'color' with args 'c=black:s=1920x1080:r=25:setsar=1/1'
color=c=black:s=1920x1080:r=25:setsar=1/1: Option not found
Conversion failed!Im trying to make a universal “code” that will add black no matter what Sar or Dar is inputted. Its very strange that it cant generate black at start and end on all materials whiteout knowing its SAR/DAR. It should be able to read it from the file and just create black with the same properties.
Isn’t there a way whiteout “Concat” so no muxing is taking place. Just pure and simply generate black at start and end for the encoded outfile? In other words, add the black in the transcoding to a new file.
-
Lou Logan
June 26, 2014 at 3:11 pmSorry, but setsar should be sar (I edited the example). I was unable to test the example at the time I wrote it, and unfortunately I’m also unable to test now.
-
Thomas Demirian
August 20, 2014 at 11:20 amHello. Im back again with a working command. 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.
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,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.mpgThis works by it self.
ffmpeg -f lavfi -i color=c=blue:s=1280x720:d=0.5 -vf \
"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:" \
text1.mp4And this one works by itself. Now how can I combine them?
Reply to this Discussion! Login or Sign Up