条件表达式在ffmpeg中不起作用?

时间:2017-04-08 05:13:04

标签: ffmpeg

我遇到条件表达式在ffmpeg中生成错误的问题。以下是问题的示例,该问题取自ffmpeg documentation for the blend filter

ffmpeg -i lyt1s.mp4 -i lyt1r.mp4 -filter_complex \
    'blend=all_expr=if(eq(mod(X,2),mod(Y,2)),A,B)' lytx.mp

生成以下输出:

ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
built with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads         --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --disable-doc --arch=x86_64 --enable-runtime-cpudetect``
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'lyt1s.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.101
  Duration: 00:00:40.04, start: 0.000000, bitrate: 4337 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 4202 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'lyt1r.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.101
  Duration: 00:00:40.04, start: 0.000000, bitrate: 2410 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2275 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
  handler_name    : SoundHandler
[AVFilterGraph @ 0x7fc7f1d0a6a0] No such filter: '2)'
Error initializing complex filters.
Invalid argument

如果我将all_expr参数替换为不包含条件表达式的东西(例如A * 0.5 + B * 0.5),则混合滤波器会执行它应该执行的操作,而不会出现任何错误。

谁能告诉我这里发生了什么?

2 个答案:

答案 0 :(得分:2)

这是在过滤器表达式中转义特殊字符的问题。你似乎在* nix上,用filter_complex周围的单引号判断。

尝试

'blend=all_expr=if(eq(mod(X\,2)\,mod(Y\,2))\,A\,B)'

答案 1 :(得分:0)

对于在if中使用pad条件的情况,我用单引号引用了if表达式,并用双引号包裹了整个过滤器。

ffmpeg -i $1 -vf "pad='if(lt(a,16/9),ih*16/9,iw)':\
                      'if(lt(a,16/9),ih,iw*9/16)':\
                      'if(lt(a,16/9),(ow-iw)/2,0)':\
                      'if(lt(a,16/9),0,(oh-ih)/2)':\
                      black" resized_$1

此处理是必需的,因为逗号用于分隔过滤器链。这个想法来自https://trac.ffmpeg.org/wiki/FilteringGuide#Escapingcharacters