在ffmpeg中具有混合音轨的文件上添加其他音频 [英] Add another audio over a file with mixed audio tracks in ffmpeg

查看:123
本文介绍了在ffmpeg中具有混合音轨的文件上添加其他音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过串联三个不同文件形成的文件: a.mp4 b.mp4 c.mp4 ./p>

I have a file that was formed by concatenating three different files: a.mp4, b.mp4 and c.mp4.

do ffmpeg -f concat -i "concat-file.txt" -map 0:v -map 0:a -c:v libx264 -crf 23 -fflags +genpts joined-file.mp4"

此后,我运行以下命令:

After that I run this command, mentioned here: How to add a new audio (not mixing) into a video using ffmpeg?

ffmpeg -i joined-file.mp4 -i audio.mp3 -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -ac 2 -shortest output.mp4

是什么原因导致此问题?

What is causing this issue?

谢谢.:)

更新:

这是我一直在运行的命令:

Here are the commands that I have been running:

ffmpeg -i "middle/b.mp4" -c:v copy -video_track_timescale 30k -c:a aac -ac 6 -ar 44100 -shortest "wrap/b.mp4"
ffmpeg -f concat -i "concat-file.txt" -map 0:v -map 0:a -c:v libx264 -crf 23 -fflags +genpts "joined/abc.mp4"
ffmpeg -i "joined/abc.mp4" -i audio.mp3 -filter_complex "[0:a:0][1:a:0]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -ac 2 -shortest "final/abc-cmplt.mp4"

这是"concat-file.txt":

Here is the "concat-file.txt":

file 'bits/a.mp4'
file 'wrap/b.mp4'
file 'bits/c.mp4'

所有视频文件 a.mp4 b.mp4 c.mp4 均具有其原始音频.运行上述命令后,联合视频 abc-cmplt.mp4 组合了第一部分(a.mp4)和最后部分(c.mp4)的音频(audio.mp3加上他们自己的).但是,中间部分只有自己的音频,而我尝试添加的额外音频似乎没有与最终联合文件中的 b.mp4 音频合并.

All the video files a.mp4, b.mp4 and c.mp4 have their original audio. After I run the commands above, the joint video abc-cmplt.mp4 has combined audio (audio.mp3 plus their own) for the first (a.mp4) and last parts (c.mp4). However, the middle part only has its own audio and the extra audio I am trying to add does not seem to merge with the audio of b.mp4 in the final joint file.

ffmpeg -i bits/a.mp4 -i wrap/b.mp4 -i bits/c.mp4 的输出:

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bits/a.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2021-03-10T08:50:04.000000Z
  Duration: 00:00:01.05, start: 0.000000, bitrate: 1846 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1080x1920 [SAR 1:1 DAR 9:16], 1462 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2021-03-10T08:50:04.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2021-03-10T08:50:04.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'wrap/b.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:27.93, start: 0.000000, bitrate: 234 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1080x1920, 231 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'bits/c.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2021-03-10T08:42:52.000000Z
  Duration: 00:00:01.05, start: 0.000000, bitrate: 1829 kb/s
    Stream #2:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1080x1920 [SAR 1:1 DAR 9:16], 1320 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2021-03-10T08:42:52.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : AVC Coding
    Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2021-03-10T08:42:52.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler

推荐答案

要由这些相同的属性. b.mp4 具有不同的H.264配置文件,并且没有音频.解决该问题:

All files to be concatenated by the concat demuxer must have these same attributes. b.mp4 has a different H.264 profile and lacks audio. Fix that:

ffmpeg -i "middle/b.mp4" -f lavfi -i anullsrc=cl=stereo:r=48000 -c:v libx264 -profile:v main -video_track_timescale 30k -shortest "wrap/b.mp4"

然后连接并混合音频:

ffmpeg -f concat -i "concat-file.txt" -i audio.mp3 -c:v libx264 -crf 23 -filter_complex "[0:a:0][1:a:0]amerge=inputs=2" -ac 2 "joined/abc.mp4"

<身体>
选项说明
-f lavfi 告诉ffmpeg以下输入是过滤器而不是文件.
-i anullsrc = cl = stereo:r = 48000 使用 anullsrc 过滤器生成48000采样率的无声立体声音频./td>
-profile:v main H.264配置文件设置为 Main .
-video_track_timescale 30k 时间比例设置为30k,以匹配其他视频( 30000 tbn ).
Option Description
-f lavfi Tell ffmpeg the following input is a filter instead of a file.
-i anullsrc=cl=stereo:r=48000 Use the anullsrc filter to generate silent stereo audio with 48000 sample rate.
-profile:v main Set H.264 Profile to Main.
-video_track_timescale 30k Set timescale to 30k to match the other videos (30k tbn).

这篇关于在ffmpeg中具有混合音轨的文件上添加其他音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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