Search code examples
windowsffmpegvideo-processing

invalid frame size error while using WxH in ffmpeg


I am trying to convert a video to images.

ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg 

But every time it shows error in Windows CMD :

Invalid frame size: WxH.

The full Error code is posted below

C:\Users\HP\Desktop\New folder>ffmpeg -i "C:\Users\HP\Desktop\foo.mp4" -r 1 -s WxH -f image2 afoo-%03d.jpeg
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\HP\Desktop\foo.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:45.05, start: 0.000000, bitrate: 1163 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 854x480 [SAR 1:1 DAR 427:240], 1032 kb/s, 25.02 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Invalid frame size: WxH.

I tried with multiple video formats and video sizes but still not working :(

I've checked whether it is really 'x' and I typed it by hand. This question implies about the 'x' problem and mine is different.


Solution

  • As Gyan mentioned, you need to specify the actual width (W) and (x) height (H).

    You should also update your ancient FFMPEG version.

    ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
    

    should be changed to (assuming you want 1280x720):

    ffmpeg -i foo.avi -r 1 -s 1280x720 -f image2 foo-%03d.jpeg
    

    You can also specify the size like this:

    ffmpeg -i foo.avi -r 1 -filter:v "scale=1280:720" -f image2 foo-%03d.jpeg
    

    If you want to Not force both a width And height and keep the aspect ratio you could use:

    ffmpeg -i foo.avi -r 1 -filter:v "scale=1280:-2" -f image2 foo-%03d.jpeg
    
    ffmpeg -i foo.avi -r 1 -filter:v "scale=-2:720" -f image2 foo-%03d.jpeg
    

    The -2 will auto resize that dimension (W or H) to the correct size (Mod 2) to maintain the aspect ratio.

    This page may be worth reading: FFMPEG Scaling