将 Unix 脚本转换为 Windows 批处理以进行 FFmpeg 大小调整

将 Unix 脚本转换为 Windows 批处理以进行 FFmpeg 大小调整

我想将视频尺寸缩小到 720:480 并保持原始宽高比,当输入视频宽度 > 720 时,否则保持原始尺寸和宽高比。

我尝试在 Windows 批处理文件中重现此脚本但失败了:

使用 ffmpeg/avconv 调整视频大小以适合静态大小的播放器

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

我收到的错误:

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!

答案1

我的机器上没有这个ffmpeg,所以我无法测试这个,但是从命令提示符不使用美元符号的观察开始,我应用了以下转换:

  • 改成。​set $var=$valueset var=$value
  • 改成。​$var%var%

我恢复了slhck♦ 的回答,我想到了:

@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

(为清楚起见添加了空行。)为了进一步清楚,你可以将该长行拆分成如下形式:

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

我不确定你是否可以在引号字符串中做到这一点。祝你好运!

相关内容