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!
5
  • Hi slhck: I tried the command you had in another post but it fails in windows batch. Please see my update above under edit.
    – kheya
    Commented Jul 15, 2013 at 22:16
  • The command you given fails badly in windows. Lots of syntax errors.
    – kheya
    Commented Jul 15, 2013 at 22:24
  • 1
    Look at the error messages you are getting: Invalid size 'iw*min($width/iw'. That suggests that ffmpeg is breaking your scale=iw*min($width/iw,$height/ih) expression into pieces at the comma. Now look at your command, and look at the command that you claim to be copying from –– it has backslashes before the commas. Backslash often means that the following character is special –– for example, that a comma is part of an expression, rather than a separator. Commented Jul 15, 2013 at 23:41
  • And, your conversion of slhck♦’s Unix command into Windows Command Prompt command language is flawed. Commented Jul 15, 2013 at 23:41
  • I reopened the question as it's now merely a Windows scripting issue. Please, in the future, ping the username with @slhck in order to have me get a notification. Thanks!
    – slhck
    Commented Jul 16, 2013 at 9:09

1 Answer 1

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .