使用FFMPEG合并和合并多个音频和视频文件 [英] Merge and Concat Multiple Audio and Video files using FFMPEG

查看:107
本文介绍了使用FFMPEG合并和合并多个音频和视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a script at present that results in several audio-only and video-only files.

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

My goal is to take these and then concat each video clip whilst merging in the audio-clips.

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

I thought this would be easy but I have not been able to find a good example to work from.

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

FFMPEG.org suggests that the movie/amovie input syntax could be the best option.. but am craving more doco. FFMPEG's information on the topic is @ https://www.ffmpeg.org/ffmpeg-filters.html#Examples-124. It suggests that to "...Concatenate two parts, handling audio and video separately" we should be able to use the "(a)movie sources" and includes this example:

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]

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

I have tried this myself without any success:

-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

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

Any ideas on how to get this working? (doesn't have to use the same movie/amovie constructs, my main requirement is that I have an array of items and need to produce a video from them, that is a concat of each video, and a merge of each audio.

...

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

When I use regular concat, I get this error:

[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包装器)如下所示:

The input (via NodeJS wrapper) looks like this:

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: '' }

推荐答案

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

No need for (a)movie or two concats. Just list each input normally:

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

这篇关于使用FFMPEG合并和合并多个音频和视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆