ffmpeg time lapse "overwrite" error - may be a globbing/shell issue?

1

1

I'm having some trouble with what I think should be a simple FFMPEG script. I'm just trying to take all the jpg files in a given directory and fill them into a time lapse video. I'm comfortable with all the encoder options and that stuff in ffmpeg, but I can't seem to get the syntax right.

The line I'm trying should (yeah, I know... "should") just take all the .JPG images in the directory, and encode them as "out.mp4". But if you look at the bottom, what I get is a prompt to overwrite GOPR3974.JPG -- which is the second file in the directory. This implies that for some reason it's not globbing all the files correctly... I've tried single quotes, double quotes, I've tried

ffmpeg -i GOPR%04d.JPG out.mp4

so there has to be something somewhere that works. If it matters, this is being run on a cygwin environment using bash...

[lwobker:/dtop/hack]$ /usr/local/bin/ffmpeg.exe -i GOPR*.JPG out.mp4
ffmpeg version N-64919-ga613257 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 23 2014 00:35:22 with gcc 4.8.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads
--enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-gnutls --enable-iconv --enable-libass --enable-libbluray
--enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
--enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr
--enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab
--enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264
--enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink
--enable-zlib
  libavutil      52. 92.101 / 52. 92.101
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.101 / 55. 48.101
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, image2, from 'GOPR3973.JPG':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg), 1920x1440 [SAR 72:72 DAR
4:3], 25 tbr, 25 tbn, 25 tbc
File 'GOPR3974.JPG' already exists. Overwrite ? [y/N]

ljwobker

Posted 2014-11-08T17:09:56.940

Reputation: 256

Answers

4

Method 1: Use sequence patterns

What you really need is this, if your first image is called GOPR0001.JPG:

ffmpeg.exe -i "GOPR%04d.JPG" -pix_fmt yuv420p out.mp4

Or if the first image is called GOPR3973.JPG, you need to give ffmpeg the start number to look for:

ffmpeg.exe -start_number 3973 -i "GOPR%04d.JPG" -pix_fmt yuv420p out.mp4

Method 2: Use globbing patterns

If your ffmpeg version has support for globbing (which the Windows builds do not have, I think), then you can simply do:

ffmpeg.exe -pattern_type glob -i "GOPR*.JPG" -pix_fmt yuv420p out.mp4

This is preferred if you don't know the start number or simply don't care for precise control.

Why it doesn't work

ffmpeg.exe -i GOPR*.JPG out.mp4

This does not work because it will expand to something like this (assuming your first image is called GOPR0001.JPG):

ffmpeg.exe -i GOPR0001.JPG GOPR0002.JPG … out.mp4

Since ffmpeg treats the last unnamed argument option (i.e. anything without a leading -) as the output file name, GOPR2.JPG would be the output, and anything until out.mp4 will not be applied.

Some hints

  • -pix_fmt yuv420p is needed to convert from the JPEG's YUV 4:2:2 colorspace to 4:2:0 subsampling. Otherwise, some (most non-FFmpeg-based) players will not be able to show the video

  • Control the quality by setting the -crf 23 option, and choosing something between 18 and 28, where lower means better quality.

  • You may want to set the framerate according to which the input frames (images) were captured. Do this by running ffmpeg.exe -framerate 30 -start_number …. If you don't specify the framerate, ffmpeg will assume that your original frames were recorded at 25 Hz.

  • Read the image2 demuxer part of the manual.

  • Double quotes are always good to use to prevent shell expansion of patterns.

slhck

Posted 2014-11-08T17:09:56.940

Reputation: 182 472