ffmpeg

Loads of pain converting simulation output (ppm and TIF) time series into a movie format that a journal likes has led me to start this page. Heres a list of standard ffmpeg (Mac OSX 10.12.3, Terminal) tools used on Terminal with standard tools. You might need to install some of them if you are on some flavour of Linux (or not).

Combining movies and adding text to them

For a recent paper we had to concatenate few movies and add text to them. These are the commands that worked for me:

  1. Combining 3 movies horizontally:
    ffmpeg -i MovieS2A-sm.mov -i MovieS2B-sm.mov -i MovieS2C-sm.mov -filter_complex hstack=inputs=3 MovieS2ABC.mov
    For vertical replace hstack with vstack.
    Inputs=3 indicates the number of input files
  2. Finding the file size using VLC: SIZE 1440×482 (pixels)
  3. Adding a text legend to them in sequence
    ffmpeg -i MovieS2ABC.mov -vf "drawtext=text='A':x=10:y=10:fontsize=24:fontcolor=black" -c:a copy MovieS2ABC-Atxt.mov
    ffmpeg -i MovieS2ABC-Atxt.mov -vf "drawtext=text='B':x=490:y=10:fontsize=24:fontcolor=black" -c:a copy MovieS2ABC-Btxt.mov
    ffmpeg -i MovieS2ABC-Btxt.mov -vf "drawtext=text='C':x=970:y=10:fontsize=24:fontcolor=black" -c:a copy MovieS2ABC-Ctxt.mov

Fin! Samapt! Submit!

Installing FFMPEG

Caveat: I’m using a MAC OSX 10.12.5 (Sierra) with Xcode and multiple gnu developer tools installed using Mac Ports.

1) Convert .avi files to MAC readable (not just VLC) .mp4 files:

ffmpeg.exe -i %d.png -f mp4 -vcodec libx264 -pix_fmt yuv420p test.mp4

The .png file could be an input .avi file (in which case drop %d.png for your file series)

Convert to MOV using QuickTime->Export.

2) Convert pre-existing movie files in Quicktime .mov format to uncompressed AVI or even MAC compatible .mov

ffmpeg -i terasaki.mov -vcodec rawvideo -y terasaki.avi

I recently needed this to make Supplementary Materials files ImageJ readable and neeed UNCOMPRESSED avi files (all compression codecs seemed to trip up ImageJ). The output looks like this:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Jun 12 2013 13:46:16 with Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --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-libfreetype --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid
libavutil      52. 18.100 / 52. 18.100
libavcodec     54. 92.100 / 54. 92.100
libavformat    54. 63.104 / 54. 63.104
libavdevice    54.  3.103 / 54.  3.103
libavfilter     3. 42.103 /  3. 42.103
libswscale      2.  2.100 /  2.  2.100
libswresample   0. 17.102 /  0. 17.102
libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'terasaki-mk0780641002.mov':
Metadata:
major_brand     : qt
minor_version   : 0
compatible_brands: qt
creation_time   : 2017-06-19 06:11:05
encoder         : Mac OS X v? (AVF 1046.9.12, CM 1731.15.207, x86_64)
encoder-eng     : Mac OS X v? (AVF 1046.9.12, CM 1731.15.207, x86_64)
Duration: 00:00:04.67, start: 0.000000, bitrate: 926 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 370x220 [SAR 1:1 DAR 37:22], 924 kb/s, 6 fps, 6 tbr, 60 tbn, 120 tbc
Metadata:
creation_time   : 2017-06-19 06:11:05
handler_name    : Core Media Data Handler
Output #0, avi, to 'terasaki-mk0780641002.avi':
Metadata:
major_brand     : qt
minor_version   : 0
compatible_brands: qt
encoder-eng     : Mac OS X v? (AVF 1046.9.12, CM 1731.15.207, x86_64)
ISFT            : Lavf54.63.104
Stream #0:0(eng): Video: rawvideo (I420 / 0x30323449), yuv420p, 370x220 [SAR 1:1 DAR 37:22], q=2-31, 200 kb/s, 6 tbn, 6 tbc
Metadata:
creation_time   : 2017-06-19 06:11:05
handler_name    : Core Media Data Handler
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> rawvideo)
Press [q] to stop, [?] for help
frame=   28 fps=0.0 q=0.0 Lsize=    3345kB time=00:00:04.66 bitrate=5871.8kbits/s
video:3339kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.188078%

For the mac OSX compatible movie files (quicktime playable), a small conversion with decocer fix:

>>ffmpeg -i videoS2.mov -pix_fmt yuv420p videoS2-v3.mov

Falls under the entry Encodingfordumbplayers


References:

1) Stackoverflow: http://stackoverflow.com/questions/14430593/encoding-a-readable-movie-by-quicktime-using-ffmpeg

2) FFMPEG User-List http://www.ffmpeg-archive.org/Uncompressed-AVI-to-Uncompressed-Quicktime-td941357.html

3) https://trac.ffmpeg.org/wiki/Encode/H.264#Encodingfordumbplayers

This entry was posted in Blog, Movies, Scientific computing, ffmpeg, scientific_writing and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>