简化FFmpeg合并和批量定制


9

我有3个连续的FFmpeg命令,这些命令将自定义音频的音量,自定义视频的音量以及amerge音频和视频到最终输出。

第一条命令,编辑mp3文件的音量

  ffmpeg -i music.mp3 -vol 100 music2.mp3

第二条命令,编辑mp4文件的音量

ffmpeg -i video.mp4 -vol 200 video2.mp4

第三命令,合并music2.mp3video2.mp4

ffmpeg -i music2.mp3 -i ruby.mp4 -filter_complex \
    "[0:a][1:a]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]" \
    -map 1:v -map "[out]" -c:v copy -c:a libfdk_aac -shortest video2.mp4

有没有简单的方法可以将流程简化和分解为一个流程/命令?

我已经尝试过了,但是没有用:

ffmpeg -i music.mp3 -vol 100 -i video.mp4 -vol 200 -filter_complex \
    "[0:a][1:a]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]" \
    -map 1:v -map "[out]" -c:v copy -c:a libfdk_aac -shortest output.mp4

错误日志:

    ffmpeg version N-60332-ga0d5204 Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb  4 2014 21:31:51 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 49.101 / 55. 49.101
  libavformat    55. 29.101 / 55. 29.101
  libavdevice    55.  7.100 / 55.  7.100
  libavfilter     4.  1.102 /  4.  1.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mp3, from 'adele.mp3':
  Metadata:
    title           : Chasing Pavements
    artist          : Adele
    track           : 3
    album           : 19 (Deluxe Edition)
    date            : 2008
  Duration: 00:03:30.55, start: 0.025056, bitrate: 160 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 159 kb/s
    Stream #0:1: Video: mjpeg, yuvj420p(pc), 600x600 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
    Metadata:
      title           : 
      comment         : Other
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'Ruby on Rails 101- What is Ruby on Rails_.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2013-12-21 07:56:20
  Duration: 00:05:42.40, start: 0.000000, bitrate: 1214 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1020 kb/s, 30 fps, 30 tbr, 60 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      creation_time   : 2013-12-21 07:56:23
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
[Parsed_pan_1 @ 0x7fcd23d00680] This syntax is deprecated. Use '|' to separate the list items.
-vol has been deprecated. Use the volume audio filter instead.
-vol is forwarded to lavfi similarly to -af volume=0.781250.
-vol has been deprecated. Use the volume audio filter instead.
-vol is forwarded to lavfi similarly to -af volume=0.781250.
File 'output.mp4' already exists. Overwrite ? [y/N] y
[Parsed_amerge_0 @ 0x7fcd23d00000] No channel layout for input 1
    Last message repeated 1 times
[AVFilterGraph @ 0x7fcd23c0f5a0] The following filters could not choose their formats: Parsed_amerge_0
Consider inserting the (a)format filter near their input or output.

请提供完整的未剪切命令行输出,而不仅仅是您认为相关的部分。谢谢。
slhck

是的,我编辑了我的帖子。
emfolorncynosure

Answers:


14

一个命令绑定它们

您可以使用volume音频过滤器代替旧-vol选项(如控制台输出中所述),在一个命令中执行此操作:

ffmpeg -i music.mp3 -i videowithaudio.mp4 -filter_complex \
"[0:a]volume=0.390625[a1];[1:a]volume=0.781250[a2]; \
 [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]" \
-map 1:v -map "[out]" -c:v copy -c:a libfdk_aac -shortest output.mp4

您可能需要调整的值volume


潜在问题

不赞成使用语法

[Parsed_pan_4 @ 0x244c980] This syntax is deprecated. Use '|' to separate the list items.

不用担心-您可以忽略此消息。

无法选择其格式

[AVFilterGraph @ 0x26549a0] The following filters could not choose their formats: Parsed_amerge_3
Consider inserting the (a)format filter near their input or output.

所有输入的采样率和格式必须相同amerge。如果它们不同,则必须使用aformat音频过滤器:

ffmpeg -i music.mp3 -i videowithaudio.mp4 -filter_complex \
"[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1]; \
 [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2]; \
 [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]" \
-map 1:v -map "[out]" -c:v copy -c:a libfdk_aac -shortest output.mp4

1
@LordNeckbeard,您好,[AVFilterGraph @ 0x7f951b42a080] The following filters could not choose their formats: Parsed_amerge_5 Consider inserting the (a)format filter near their input or output.即使我使用了aformat样本,它仍然显示。
emfolorncynosure

我有相同的用例,并且出现“输入1的通道没有布局”错误
Lukasz Madon 2014年

@lukas您可以显示ffmpeg命令并完成控制台输出吗?您可以使用pastebin服务并提供链接。
llogan 2014年

@LordNeckbeard gist.github.com/lukasz-madon/508d76d6fd5ff3635494具有与抱怨libfdk_aac完全相同的命令
Lukasz Madon

@lukas您可以下载并测试更新的版本吗?您的版本已过时。
llogan 2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.