ffmpeg crashes into batch file but allright in command line

Questions involving a Windows version of FFmpeg.
Post Reply
gamuti
Posts: 2
Joined: Sun Jul 02, 2017 7:00 pm

ffmpeg crashes into batch file but allright in command line

Post by gamuti » Sun Jul 02, 2017 7:23 pm

Hi there,

I would like to create animated gif since MOV video file.
I use this command line, it works perfectly :

Code: Select all

c:\ffmpeg\bin\ffmpeg.exe -i MVI_5233.MOV -r 1 videos/temp/essais%4d.png
A lot of files named "essais????.png" are created into videos/temp directory.

But, If I use this same command line into a batch file, then, ffmpeg crashes and a single image is created, named "essaisd.png".
See result :

Code: Select all

ffmpeg version N-58037-g355cea8 Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 11 2013 18:07:36 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 52.100 / 52. 52.100
  libavcodec     55. 41.100 / 55. 41.100
  libavformat    55. 21.100 / 55. 21.100
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.102 /  3. 90.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'MVI_5233.MOV':
  Metadata:
    major_brand     : qt
    minor_version   : 537331968
    compatible_brands: qt  CAEP
    creation_time   : 2016-07-05 14:53:43
  Duration: 00:01:02.62, start: 0.000000, bitrate: 22272 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 640x480, 20731 kb/s, 50 fps, 50 tbr, 50k tbn, 100k tbc (d
efault)
    Metadata:
      creation_time   : 2016-07-05 14:53:43
    Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2016-07-05 14:53:43
[swscaler @ 00000000003147e0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'essaid.png':
  Metadata:
    major_brand     : qt
    minor_version   : 537331968
    compatible_brands: qt  CAEP
    encoder         : Lavf55.21.100
    Stream #0:0(eng): Video: png, rgb24, 640x480, q=2-31, 200 kb/s, 90k tbn, 1 tbc (default)
    Metadata:
      creation_time   : 2016-07-05 14:53:43
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
[image2 @ 000000000283f460] Could not get frame filename number 2 from pattern 'essaid.png' (either set updatefirst or use a pattern like %03d within the filena
me pattern)
av_interleaved_write_frame(): Invalid argument
How can I fix this problem ?

Nota Bene : Computer running windows 7 professional-SP1.

User avatar
Zeranoe
Site Admin
Posts: 703
Joined: Sat May 07, 2011 7:12 pm
Contact:

Re: ffmpeg crashes into batch file but allright in command line

Post by Zeranoe » Mon Jul 03, 2017 8:13 pm

You should include the entire batch script.

gamuti
Posts: 2
Joined: Sun Jul 02, 2017 7:00 pm

Re: ffmpeg crashes into batch file but allright in command line

Post by gamuti » Mon Jul 03, 2017 9:14 pm

Of course :

Code: Select all

@ECHO OFF
md videos
md videos\temp
c:\ffmpeg\bin\ffmpeg.exe -i MVI_5233.MOV -r 1 videos/temp/essais%4d.png
Expected result : multiple file ("essais0001.png essais0002.png ...)
Unexpected result : one file named "essaisd.png"

I have a solution :

Code: Select all

c:\ffmpeg\bin\ffmpeg.exe -i MVI-5233.MOV -r 1 videos/temp/essais.gif
Then, it directly creates an animated gif in a single file.

Complexity causes crashs <-----> Simplexity causes expected result.

pepoluan
Posts: 4
Joined: Sun Aug 27, 2017 6:02 am

Re: ffmpeg crashes into batch file but allright in command line

Post by pepoluan » Mon Sep 25, 2017 4:19 pm

The cause is that, within batch files, "%" is used to indicate a variable. So the line:

Code: Select all

c:\ffmpeg\bin\ffmpeg.exe -i MVI_5233.MOV -r 1 videos/temp/essais%4d.png
gets interpreted as:

Code: Select all

c:\ffmpeg\bin\ffmpeg.exe -i MVI_5233.MOV -r 1 videos/temp/essaisd.png
and ffmpeg crashes because it does not see the required "%<number>d" template.

You have to double up on the percent sign, like this:

Code: Select all

c:\ffmpeg\bin\ffmpeg.exe -i MVI_5233.MOV -r 1 videos/temp/essais%%4d.png

Post Reply
'