Converting series of images with ffmpeg results in black video
2013-08
I've just downloaded ffmpeg since it seems to perfectly match my needs (make a video from a set of pictures). I'm currently playing around with some examples just to get started and there's something weird happening that I can't explain. I'm trying this command (provided in the official documentation):
ffmpeg -f image2 -pattern_type glob -i 'foo-*.jpeg' -r 12 -s WxH foo.avi
on a data set of 10 jpg pictures (of course I changed the pattern with '*.jpg'). The video seems to be encoded correctly but it's simply too fast to be sure about that (anyway it stops on the last frame that corresponds to the last picture). In order to get a longer video i thought to low the frame rate from 12 to 1 (one sec each picture) or 0.5 (2 sec each one) and so on.. no way! with low rate values even if the video is played the pictures are simply not displayed. The player (VLC in my case) just shows a blank/empty video for a few seconds.
Am I making something wrong or have I misunderstood the -r parameter? Is it something related to codecs involved? Finally.. How can i get each picture displayed for 1 or 2 seconds?
Here's the output:
MacBook-Pro$ ffmpeg -f image2 -pattern_type glob -i '*.jpg' -r 1 -s 200x300 foo.avi
ffmpeg version N-52517-g1e4f75d Copyright (c) 2000-2013 the FFmpeg developers
built on Apr 27 2013 19:41:11 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --disable-yasm
libavutil 52. 27.101 / 52. 27.101
libavcodec 55. 6.100 / 55. 6.100
libavformat 55. 3.100 / 55. 3.100
libavdevice 55. 0.100 / 55. 0.100
libavfilter 3. 61.100 / 3. 61.100
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
Input #0, image2, from '*.jpg':
Duration: 00:00:00.40, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj422p, 2560x1920 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn, 25 tbc
File 'foo.avi' already exists. Overwrite ? [y/N] y
Output #0, avi, to 'foo.avi':
Metadata:
ISFT : Lavf55.3.100
Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 200x300 [SAR 2:1 DAR 4:3], q=2-31, 200 kb/s, 1 tbn, 1 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg -> mpeg4)
Press [q] to stop, [?] for help
frame= 2 fps=0.0 q=2.0 Lsize= 43kB time=00:00:02.00 bitrate= 177.1kbits/s dup=0 drop=8
video:38kB audio:0kB subtitle:0 global headers:0kB muxing overhead 15.099197%
MacBook-Pro$
I am trying to insert an audio channel with a video:
first of all I extract the audio from the original video for processing:
ffmpeg -i lotr.mp4 lotr.wav
I then extract all frames for later processing too:
ffmpeg -i lotr.mp4 -f image2 %d.jpg
When done processing audio and video streams, I try to create the video
ffmpeg -f image2 -r 15 -i %d.jpg new.mp4
then merge with the audio:
ffmpeg -i new.mp4 -i lotr.wav -map 0:0 -map 1:0 new_w_audio.mp4
Result: CPU activity = 100%, the process hangs and never returns. PS: I even tried it without modifying the images or the audio (so just trying to unpack then repack the video) but still the same output
FFmpeg version SVN-r26400, Copyright (c) 2000-2011 the FFmpeg developers
built on Jan 18 2011 04:07:05 with gcc 4.4.2
configuration: --enable-gpl --enable-version3 --enable-libgsm --enable-libvorb
is --enable-libtheora --enable-libspeex --enable-libmp3lame --enable-libopenjpeg
--enable-libschroedinger --enable-libopencore_amrwb --enable-libopencore_amrnb
--enable-libvpx --disable-decoder=libvpx --arch=x86 --enable-runtime-cpudetect -
-enable-libxvid --enable-libx264 --enable-librtmp --extra-libs='-lrtmp -lpolarss
l -lws2_32 -lwinmm' --target-os=mingw32 --enable-avisynth --enable-w32threads --
cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign-hack
libavutil 50.36. 0 / 50.36. 0
libavcore 0.16. 1 / 0.16. 1
libavcodec 52.108. 0 / 52.108. 0
libavformat 52.93. 0 / 52.93. 0
libavdevice 52. 2. 3 / 52. 2. 3
libavfilter 1.74. 0 / 1.74. 0
libswscale 0.12. 0 / 0.12. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'new.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
creation_time : 1970-01-01 00:00:00
encoder : Lavf52.93.0
Duration: 00:00:29.66, start: 0.000000, bitrate: 193 kb/s
Stream #0.0(und): Video: mpeg4, yuv420p, 200x134 [PAR 1:1 DAR 100:67], 192 k
b/s, 15 fps, 15 tbr, 15 tbn, 15 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
[wav @ 01fed010] max_analyze_duration reached
Input #1, wav, from 'lotr.wav':
Duration: 00:00:29.90, bitrate: 176 kb/s
Stream #1.0: Audio: pcm_s16le, 11025 Hz, 1 channels, s16, 176 kb/s
File 'new_w_audio.mp4' already exists. Overwrite ? [y/N] y
[buffer @ 01b03820] w:200 h:134 pixfmt:yuv420p
Output #0, mp4, to 'new_w_audio.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
creation_time : 1970-01-01 00:00:00
encoder : Lavf52.93.0
Stream #0.0(und): Video: mpeg4, yuv420p, 200x134 [PAR 1:1 DAR 100:67], q=2-3
1, 200 kb/s, 15 tbn, 15 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
Stream #0.1: Audio: aac, 11025 Hz, 1 channels, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Press [q] to stop encoding
Could be several things. A hang in general with video editing happens a lot when dealing with uncompressed video codecs. Not sure if I read up there that original video is in yuv420p codec. It maybe gets hanged trying to handle a lot of memory or when compressing directly the images to mp4. One thing I can think of is converting first to avi, ie, outputting to an avi but forcing a lossless codec like camtasia / camstudio (I think ffmpeg supports it) , so it is not so "heavy", and then do a second operation to convert to mp4. Other matter is... -r15 ? You surely know better which fps is having the original video, but it uses to be 24fps or so, isn't it?
Also... You might force as well the output codec, not just the format. MP4 works pretty well with .h264 codec, which gives a lot of quality and incredible small size. If I remember well ffmpeg also supports it. (you might want to try this first of all...)
Edit: Remember -codecs gives you the list of codecs, in command line. You can of course, for example in Win console, ffmpeg -codecs > codecs.txt for easier reading, searching etc. Healthy to do also with -formats, etc.
Try updating to the latest version of ffmpeg.