使用FFMPEG

时间:2018-12-19 16:24:32

标签: audio video ffmpeg concat

我目前有一个脚本,可以生成多个仅音频和仅视频文件。

我的目标是拍摄这些片段,然后合并每个音频片段,同时合并到音频片段中。

我以为这很容易,但是我一直找不到能够工作的好例子。

FFMPEG.org建议使用movie/amovie输入语法是最好的选择..但是渴望更多的doco。 FFMPEG关于该主题的信息是@ https://www.ffmpeg.org/ffmpeg-filters.html#Examples-124。它建议“将两个部分连接起来,分别处理音频和视频”,我们应该能够使用“电影资源”,并包括以下示例:

movie=part1.mp4, scale=512:288 [v1] ; amovie=part1.mp4 [a1] ;
movie=part2.mp4, scale=512:288 [v2] ; amovie=part2.mp4 [a2] ;
[v1] [v2] concat [outv] ; [a1] [a2] concat=v=0:a=1 [outa]

我自己尝试过此尝试,但未成功:

-f lavfi
-i amovie=/clips/1-0.mp3 [a0];
   movie=/clips/1-1-overlayed.mp4 [v1];
   amovie=/clips/1-2.mp3 [a2];
   movie=/clips/1-3-overlayed.mp4 [v3];
   amovie=/clips/1-4.mp3 [a4];
   movie=/clips/1-5-overlayed.mp4 [v5];
   [v1] [v3] [v5] concat=n=3 "[outv]" ; [a0] [a2] [a4] concat=n=3:v=0:a=1 "[outa]"
-map "[outv]"
-map "[outa]"
output.mp4

给予:

"[outa]": Invalid argument

关于如何使它工作的任何想法? (不必使用相同的电影/电影结构,我的主要要求是我要拥有一系列物品,并需要从中产生一个视频,即每个视频的结合部分,以及每个音频的合并部分。 / p>

...

当我使用常规concat时,出现此错误:

[mp3 @ 0x7fd200003a00] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '/clips/1-0.mp3':
  Duration: 00:00:04.27, start: 0.000000, bitrate: 32 kb/s
    Stream #0:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/clips/1-1-overlayed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:04.28, start: 0.000000, bitrate: 28 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 3:4 DAR 4:3], 24 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
[mp3 @ 0x7fd20080ac00] Estimating duration from bitrate, this may be inaccurate
Input #2, mp3, from '/clips/1-2.mp3':
  Duration: 00:00:14.38, start: 0.000000, bitrate: 32 kb/s
    Stream #2:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '/clips/1-3-overlayed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:14.36, start: 0.000000, bitrate: 530 kb/s
    Stream #3:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 528 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
[mp3 @ 0x7fd20100d200] Estimating duration from bitrate, this may be inaccurate
Input #4, mp3, from '/clips/1-4.mp3':
  Duration: 00:00:02.78, start: 0.000000, bitrate: 32 kb/s
    Stream #4:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Input #5, mov,mp4,m4a,3gp,3g2,mj2, from '/clips/1-5-overlayed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:02.80, start: 0.000000, bitrate: 34 kb/s
    Stream #5:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 3:4 DAR 4:3], 29 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream specifier ':a' in filtergraph description [0:a][1:v][2:a][3:v][4:a][5:v]concat=n=3:v=1:a=1[v][a] matches no streams.

输入(通过NodeJS包装器)如下:

FFmpeg {
  options:
   [ '-hide_banner',
     '-y',
     '-i',
     '/clips/1-0.mp3',
     '-i',
     '/clips/1-1-overlayed.mp4',
     '-i',
     '/clips/1-2.mp3',
     '-i',
     '/clips/1-3-overlayed.mp4',
     '-i',
     '/clips/1-4.mp3',
     '-i',
     '/clips/1-5-overlayed.mp4',
     '-filter_complex',
     '[0:a][1:v][2:a][3:v][4:a][5:v]concat=n=3:v=1:a=1[v][a]',
     '-map',
     '[v]',
     '-map',
     '[a]',
     '/projects/1.mp4' ],
  outputFilename: '' }

1 个答案:

答案 0 :(得分:0)

不需要(a)movie或两个concat。只需正常列出每个输入即可:

ffmpeg -i input-a.mp4 -i input-a.mp3 -i input-b.mp4 -i input-b.mp3 -filter_complex "[0:v][1:a][2:v][3:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4