October 30, 2016
ffmpeg: concatenating with image sequences and audio
How to assemble multiple image sequences and audio files into 1 video file.
Assumptions
-
all my images in image sequences are the same dimensions and format (I grabbed a sample video from http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5)
-
all my audio files are the same format
-
ffmpeg version info is:
ffmpeg version N-82143-gbf14393-tessus Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-version3 --disable-ffplay --disable-indev=qtkit --disable-indev=x11grab_xcb libavutil 55. 35.100 / 55. 35.100 libavcodec 57. 65.100 / 57. 65.100 libavformat 57. 57.100 / 57. 57.100 libavdevice 57. 2.100 / 57. 2.100 libavfilter 6. 66.100 / 6. 66.100 libswscale 4. 3.100 / 4. 3.100 libswresample 2. 4.100 / 2. 4.100 libpostproc 54. 2.100 / 54. 2.100 Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Convert Video to Image Sequence:
I need images to work with, so make some!
- images will go into the
frames
directory with names likeframe_0001.png
,frame_0002.png
etc
ffmpeg -i test7.mp4 frames/frame_%04d.png
Convert Image Sequence back to Video
https://ffmpeg.org/pipermail/ffmpeg-devel/2005-August/000523.html
-c:v libx264
sets the video codec-crf 23
sets the quality-pix_fmt yuv420p
sets the pixel format to something QuickTime can read-r 24
sets input and output framerates- input framerate is how fast the images and the sequence are meant to be played back
- output framerate sets how much time between frames in the output video
- fast input and slow output results in a slideshow or timelapse
- slow input and fast output results in duplicate frames (I think)
-y
to overwrite files without asking
ffmpeg -r 30 -i frames/frame_%04d.png -c:v libx264 -pix_fmt yuv420p -crf 23 -r 30 -y video-from-frames.mp4
Convert Image Sequence to Video + add audio track
http://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
-i Bonobo - Kong.mp3
specifies another input stream-c:a aac
converts audio to AAC format-shortest
limits the length of the output video to the shortest audio or video stream (in this case, the video stream is shorter)
ffmpeg -r 24 -i frames/frame_%04d.png -i "Bonobo - Kong.mp3" -c:v libx264 -c:a aac -pix_fmt yuv420p -crf 23 -r 24 -shortest -y video-from-frames.mp4
Concatenate multiple image sequences with 1 audio track
Put this into video-input-list.txt
. The images in the image sequences must all be the same size and format
file './intro/frame_%04d.png'
file './frames/frame_%04d.png'
file './outro/frame_%04d.png'
then run the command:
-f concat
tells ffmpeg to use the concat filter-safe 0
has something to do with letting ffmpeg read relative paths in the text file
ffmpeg -r 24 -f concat -safe 0 -i video-input-list.txt -i "Bonobo - Kong.mp3" -c:v libx264 -c:a aac -pix_fmt yuv420p -crf 23 -r 24 -shortest -y video-from-frames.mp4
Concatenate multiple images sequences and concatenate multiple audio tracks
Put this into audio-input-list.txt
.
file 'big_trash_tv_hit.aif.mp3'
file 'recording.mp3'
file 'vocoded-note.aif.mp3'
file 'Bonobo - Kong.mp3'
then run the command:
- remember to specify
-f concat -safe 0
again before the second input source-i audio-input-list.txt
ffmpeg -r 24 -f concat -safe 0 -i video-input-list.txt -f concat -safe 0 -i audio-input-list.txt -c:a aac -pix_fmt yuv420p -crf 23 -r 24 -shortest -y video-from-frames.mp4
This does what I am looking for!
References
This page is helpful: https://trac.ffmpeg.org/wiki/Concatenate