Ceci est une ancienne révision du document !
h1. FFMPEG usage
h2. useful links
https://www.ffmpeg.org/ffmpeg-devices.html#decklink
http://ffmpeg.org/releases/ffmpeg-3.3.3.tar.bz2
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
h2. Configuration d'ubuntu
<pre> sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev \
libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \ libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev x264 libx264-dev
</pre>
<pre> sudo apt-get install yasm </pre>
h2. Compilation
<pre> PATH=“$HOME/bin:$PATH” PKG_CONFIG_PATH=“$HOME/ffmpeg_build/lib/pkgconfig” ./configure \
- -prefix=“$HOME/ffmpeg_build” \
- -pkg-config-flags=“–static” \
- -extra-cflags=“-I$HOME/ffmpeg_build/include” \
- -extra-ldflags=“-L$HOME/ffmpeg_build/lib” \
- -bindir=“$HOME/bin” \
- -enable-gpl \
- -enable-libass \
- -enable-libfdk-aac \
- -enable-libfreetype \
- -enable-libmp3lame \
- -enable-libopus \
- -enable-libtheora \
- -enable-libvorbis \
- -enable-libvpx \
- -enable-libx264 \
- -enable-nonfree \
- -enable-decklink \
- -extra-cflags=-I/home/damien/Blackmagic_DeckLink_SDK_10.9.5/Linux/include
make -j 8 sudo make install
</pre>
h2. Usage
h3. List output devices
ffmpeg -i test.avi -f decklink -list_devices 1 dummy
h3. List supported formats:
ffmpeg -i test.avi -f decklink -list_formats 1 'DeckLink Mini Monitor'
h3. Play video clip:
ffmpeg -i test.avi -f decklink -pix_fmt uyvy422 'DeckLink Mini Monitor'
h3. Play video clip with non-standard framerate or video size:
ffmpeg -i test.avi -f decklink -pix_fmt uyvy422 -s 720x486 -r 24000/1001 'DeckLink Mini Monitor'
h3. List output devices
ffmpeg -f decklink -list_devices 1 dummy -i big_buck_bunny_1080p_stereo.avi
h3. List supported formats
ffmpeg -f decklink -list_formats 1 'DeckLink Quad (1)' -i big_buck_bunny_1080p_stereo.avi
h3. Play video clip
ffmpeg -f decklink -pix_fmt uyvy422 'DeckLink Quad (1)' -i big_buck_bunny_1080p_stereo.avi
mplayer capture.raw -demuxer rawvideo -rawvideo fps=29.97:w=1920:h=1080:uyvy
h3. List input devices:
ffmpeg -f decklink -list_devices 1 -i dummy
h3. List supported formats:
ffmpeg -f decklink -list_formats 1 -i 'Intensity Pro'
h3. Capture video clip at 1080i50:
ffmpeg -format_code Hi50 -f decklink -i 'Intensity Pro' -acodec copy -vcodec copy output.avi
h3. Capture video clip at 1080i50 10 bit:
ffmpeg -bm_v210 1 -format_code Hi50 -f decklink -i 'UltraStudio Mini Recorder' -acodec copy -vcodec copy output.avi
h3. Capture video clip at 1080i50 with 16 audio channels:
ffmpeg -channels 16 -format_code Hi50 -f decklink -i 'UltraStudio Mini Recorder' -acodec copy -vcodec copy output.avi
ffmpeg -format_code Hp29 -f decklink -i 'DeckLink Quad (8)' -vcodec copy output.avi ffmpeg -format_code Hp29 -f decklink -i 'DeckLink Quad (8)' -vcodec h264 output.avi
h3. Compression h.264
ffmpeg -i video_720p-16Mbps.mp4 -c:v libx264 -preset fast -crf 10 -profile:v high -level 4.0 video_opengl_scaled_720p_compressé_2.mp4
The option -crf gives the quality of the resulting video. The lowest, the better the quality is. The options are documented in the ffmpeg site.
h3. Crop and pad filters
ffmpeg -i video_720p-16Mbps.mp4 -vf "crop=1024:720 [cropout]; [cropout] pad=1024:768:0:24" -c:v libx264 -preset fast -crf 10 -profile:v high -level 4.0 video_opengl_scaled_720p_compressé_2.mp4
h3. display terratec G1 (USB composite capture). Display the captured input in a window
ffmpeg -input_format rgb565 -i /dev/video0 -f opengl "window title"
h3. Display blackmagic input on a opengl window
ffmpeg -format_code hp50 -f decklink -i 'DeckLink Quad (1)' -vcodec rawvideo -pix_fmt rgba -f sdl "window"
h3. Test frames generation
ffmpeg -f lavfi -i testsrc2=duration=100:size=1280x720:rate=60 -c:v libx264 -preset fast -crf 0 -level 4.0 test2_720p60.mp4
with white box in the first second
ffmpeg -f decklink -pix_fmt uyvy422 'DeckLink Quad (1)' -i test.mp4
ffmpeg -format_code Hp29 -f decklink -i 'DeckLink Quad (8)' -vcodec h264 output.avi ~/bin/ffplay output.avi
ffmpeg -f lavfi -i testsrc2=duration=10:size=1280x720:rate=60000/1000 -vf "drawbox=enable='between(n,0,60)':x=iw/10:y=8*ih/10:w=iw/10:h=ih/10:color=white:t=50" -c:v libx264 -preset fast -crf 0 -level 4.0 test2_720p60.mp4
ffmpeg -f lavfi -i testsrc2=duration=10:size=1280x720:rate=50000/1000 -vf "drawbox=enable='between(n,0,50)':x=iw/10:y=8*ih/10:w=iw/10:h=ih/10:color=white:t=iw/10" -c:v libx264 -preset fast -crf 0 -level 4.0 test2_720p50.mp4
ffmpeg -f lavfi -i testsrc2=duration=10:size=1920x1080:rate=25000/1000 -vf "drawbox=enable='between(n,0,25)':x=iw/10:y=8*ih/10:w=iw/10:h=ih/10:color=white:t=iw/10" -c:v libx264 -preset fast -crf 0 -level 4.0 test2_1080p25.mp4
ffmpeg -f lavfi -i testsrc2=duration=10:size=1920x1080:rate=30000/1000 -vf "drawbox=enable='between(n,0,30)':x=iw/10:y=8*ih/10:w=iw/10:h=ih/10:color=white:t=iw/10" -c:v libx264 -preset fast -crf 0 -level 4.0 test2_1080p30.mp4
ffmpeg -f lavfi -i testsrc2=duration=10:size=720x576:rate=25000/1000 -vf "drawbox=enable='between(n,0,25)':x=iw/10:y=8*ih/10:w=iw/10:h=ih/10:color=white:t=iw/10" -c:v libx264 -preset fast -crf 0 -level 4.0 test2_pal.mp4
ffmpeg -f lavfi -i testsrc2=duration=10:size=720x486:rate=30000/1001 -vf "drawbox=enable='between(n,0,30)':x=iw/10:y=8*ih/10:w=iw/10:h=ih/10:color=white:t=iw/10" -c:v libx264 -preset fast -crf 0 -level 4.0 test2_ntsc.mp4
frei0r filers
ffmpeg -f lavfi -i frei0r_src=size=1920x1080:framerate=30:filter_name=partik0l:filter_params=1234 -c:v libx264 -preset fast -crf 0 -level 4.0 test3_1080p30.mp4
overlay of the filer on an input
ffmpeg -f lavfi -i testsrc2=duration=10:size=1920x1080:rate=30 -vf "frei0r_src=size=1920x1080:framerate=10:filter_name=partik0l:filter_params=1234 [overlay]; [in][overlay] overlay" -c:v libx264 -preset fast -crf 0 -level 4.0 test5_1080p30.mp4
h3. Other examples
<pre> stream = ffmpeg.input('DeckLink Quad (8)') stream = ffmpeg.output(stream, 'dummy.mp4') ffmpeg.run(stream, format='decklink', format_code='Hp29', vcodec='h264') ffmpeg.run(stream, format='decklink', format_code='Hp29', vcodec='h264') </pre>
ffmpeg -i test.mp4 -filter_complex "loop=2:2500" -vcodec h264 output.avi
use -ss 1 to avoid the recording of the Colored Mire at the beginning <pre> ffmpeg -format_code 24ps -ss 1 -f decklink -i 'DeckLink Quad (8)' -vcodec h264 -y output.avi ffplay output.avi
[decklink @ 0x3f08560] Supported formats for 'DeckLink Quad (8)':
format_code description
ntsc 720x486 at 30000/1001 fps (interlaced, lower field first)
pal 720x576 at 25000/1000 fps (interlaced, upper field first)
23ps 1920x1080 at 24000/1001 fps
24ps 1920x1080 at 24000/1000 fps
Hp25 1920x1080 at 25000/1000 fps
Hp29 1920x1080 at 30000/1001 fps
Hp30 1920x1080 at 30000/1000 fps
Hi50 1920x1080 at 25000/1000 fps (interlaced, upper field first)
Hi59 1920x1080 at 30000/1001 fps (interlaced, upper field first)
Hi60 1920x1080 at 30000/1000 fps (interlaced, upper field first)
Hp50 1920x1080 at 50000/1000 fps
Hp59 1920x1080 at 60000/1001 fps
Hp60 1920x1080 at 60000/1000 fps
hp50 1280x720 at 50000/1000 fps
hp59 1280x720 at 60000/1001 fps
hp60 1280x720 at 60000/1000 fps
</pre>
<pre> stream = ffmpeg.input('DeckLink Quad (8)') stream = ffmpeg.output(stream, 'dummy.mp4') ffmpeg.run(stream, format='decklink', format_code='Hp29', vcodec='h264') ffmpeg.run(stream, format='decklink', format_code='Hp29', vcodec='h264') </pre>
ffmpeg -i test.mp4 -filter_complex "loop=2:2500" -vcodec h264 output.avi
<pre> # play sequence in loop # (ffmpeg.input('test.mp4').filter_('loop', “-1”, “125”) # .output('DeckLink Quad (1)', pix_fmt='uyvy422', format='decklink') # .run() # ) </pre>
ffmpeg -f dekclink -pix_fmt uyvy422 'DeckLink Quad (1)' -i /bigdata/damien/video_samples/testsrc_rawvideo_uyvy422_1920x1080_30.0_5_markup_box.avi -filter_complex "loop=-1:3000"
adds black frames at the beginning
<pre> in_file = ffmpeg.input('test.mp4') marker = ffmpeg.input('color=c=black:s=1920×1080:r=24:d=1', format='lavfi') ffmpeg.concat(
marker.trim(start_frame=0, end_frame=10),
in_file
).output('test_marker.mp4', vcodec='h264').run()
</pre>
ffmpeg -f decklink -pix_fmt uyvy422 'DeckLink Quad (1)' -i /bigdata/damien/video_samples/testsrc_rawvideo_uyvy422_1920x1080_30.0_5_markup_box.avi
play in loop a video sample - max nframes is 32767
ffmpeg -f decklink -pix_fmt uyvy422 'DeckLink Quad (1)' -i /bigdata/damien/video_samples/testsrc_rawvideo_uyvy422_1920x1080_30.0_5_markup_box.avi -filter_complex "loop=-1:3000"
record that sample in row format
ffmpeg -format_code Hp30 -ss 1 -f decklink -i 'DeckLink Quad (8)' -vcodec copy decklink_testsrc_rawvideo_uyvy422_1920x1080_30.0_5_markup_box.avi
