1

I want to reduce video dimension to 720:480 & keep original aspect ration when input video width > 720 else, keep original dimension and aspect ratio.

I am trying to reproduce this script in a Windows batch file and it fails:

Resizing videos with ffmpeg/avconv to fit into static sized player

set $width=720
set $height=480
ffmpeg -i file8.3gp -vcodec libx264 -preset slow -crf 20 -filter:v "scale=iw*min($width/iw,$height/ih):ih*min($width/iw,$height/ih), pad=$width:$height:($width-iw*min($width/iw,$height/ih))/2:($height-ih*min($width/iw,$height/ih))/2" -threads 0 -acodec libvo_aacenc -b:a 128k out.mp4

The errors I'm getting:

ffmpeg -i file8.3gp -vcodec libx264 -preset slow
-crf 20 -filter:v "scale=iw*min($width/iw,$height/ih):ih*min($width/iw,$height/i
h), pad=$width:$height:($width-iw*min($width/iw,$height/ih))/2:($height-ih*min($
width/iw,$height/ih))/2" -threads 0 -acodec libvo_aacenc -b:a 128k out.mp4
ffmpeg version N-54691-g7f4a1fd Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 12 2013 16:31:48 with gcc 4.7.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
enable-libxvid --enable-zlib
  libavutil      52. 39.100 / 52. 39.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.102 / 55. 12.102
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 80.101 /  3. 80.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file8.3gp':
  Metadata:
    major_brand     : 3gp5
    minor_version   : 256
    compatible_brands: 3gp53gp4
    creation_time   : 2005-10-28 17:36:40
  Duration: 00:00:04.93, start: 0.000000, bitrate: 46 kb/s
    Stream #0:0(eng): Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, flt, 8 k
b/s
    Metadata:
      creation_time   : 2005-10-28 17:36:40
      handler_name    : Apple Sound Media Handler
    Stream #0:1(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p
, 176x144 [SAR 1:1 DAR 11:9], 35 kb/s, 15 fps, 15 tbr, 600 tbn, 1k tbc
    Metadata:
      creation_time   : 2005-10-28 17:36:40
      handler_name    : Apple Video Media Handler
File 'out.mp4' already exists. Overwrite ? [y/N] y
[Parsed_scale_0 @ 0000000000318640] Invalid size 'iw*min($width/iw'
[AVFilterGraph @ 00000000024c0540] Error initializing filter 'scale' with args '
iw*min($width/iw:flags=0x4'
Error opening filters!
kheya
  • 159

1 Answers1

1

I don’t have ffmpeg on my machine, so I can’t test this, but starting with the observation that Command Prompt doesn’t use dollar signs, I applied the following transformations:

  • Change set $var=$value to set var=$value.
  • Change $var to %var%.

and I restored the backslashes from slhck♦’s answer, and I came up with:

@echo off set width=720 set height=480
ffmpeg -i file8.3gp -vcodec libx264 -preset slow -crf 20 -filter:v "scale=iw*min(%width%/iw\,%height%/ih):ih*min(%width%/iw\,%height%/ih), pad=%width%:%height%:(%width%-iw*min(%width%/iw\,%height%/ih))/2:(%height%-ih*min(%width%/iw\,%height%/ih))/2" -threads 0 -acodec libvo_aacenc -b:a 128k out.mp4

(Blank line added for clarity.)  For further clarity, you can break up that long line something like this:

ffmpeg -i file8.3gp -vcodec libx264 -preset slow -crf 20 -filter:v ^     "scale=iw*min(%width%/iw\,%height%/ih):ih*min(%width%/iw\,%height%/ih), pad=%width%:%height%:(%width%-iw*min(%width%/iw\,%height%/ih))/2:(%height%-ih*min(%width%/iw\,%height%/ih))/2" ^     -threads 0 -acodec libvo_aacenc -b:a 128k out.mp4

I’m not sure whether you can do that inside the quoted string.  Good luck!