附加 MP4 会丢失第二个文件的声音

附加 MP4 会丢失第二个文件的声音

当我尝试使用 ffmpeg 将两个 MP4 合并在一起时,第一个文件播放正常并且有声音,但第二个文件失去了所有声音并且变得更加不连贯。

我使用 Handbrake 对 MKV 中的两个文件进行了编码,并且使用了完全相同的设置。

我已经为此工作了大约 14 个小时,但我不知道该怎么做。有什么想法吗?

编辑:这是我的命令和输出:

命令:ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts

输出:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 17 2013 20:00:17 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2013-08-06 07:16:18
    encoder         : HandBrake 0.9.9 2013051800
  Duration: 00:57:27.65, start: 0.000000, bitrate: 561 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 512x384 [SAR 1:1 DAR 4:3], 473 kb/s, 30 fps, 30 tbr, 90k tbn, 180k tbc
    Metadata:
      creation_time   : 2013-08-06 07:16:18
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 82 kb/s
    Metadata:
      creation_time   : 2013-08-06 07:16:18
Output #0, mpegts, to 'intermediate1.ts':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf54.63.104
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 512x384 [SAR 1:1 DAR 4:3], q=2-31, 473 kb/s, 30 fps, 90k tbn, 90k tbc
    Metadata:
      creation_time   : 2013-08-06 07:16:18
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, 82 kb/s
    Metadata:
      creation_time   : 2013-08-06 07:16:18
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[adts @ 0x7fad9b821800] Encoder did not produce proper pts, making some up.
frame= 7555 fps=0.0 q=-1.0 size=   19456kB time=00:04:11.93 bitrate= 632.6kbits/frame=15468 fps=15382 q=-1.0 size=   35385kB time=00:08:35.76 bitrate= 562.0kbitframe=24569 fps=16108 q=-1.0 size=   58371kB time=00:13:39.06 bitrate= 583.8kbitframe=38483 fps=18998 q=-1.0 size=   93146kB time=00:21:22.99 bitrate= 594.7kbitframe=49764 fps=19691 q=-1.0 size=  125242kB time=00:27:39.15 bitrate= 618.4kbitframe=57427 fps=18970 q=-1.0 size=  145969kB time=00:31:54.67 bitrate= 624.5kbitframe=69520 fps=19544 q=-1.0 size=  174084kB time=00:38:37.58 bitrate= 615.3kbitframe=75654 fps=18647 q=-1.0 size=  192548kB time=00:42:02.19 bitrate= 625.4kbitframe=78126 fps=17100 q=-1.0 size=  199829kB time=00:43:24.58 bitrate= 628.5kbitframe=82251 fps=16227 q=-1.0 size=  212075kB time=00:45:42.23 bitrate= 633.5kbitframe=87163 fps=15341 q=-1.0 size=  224289kB time=00:48:25.93 bitrate= 632.3kbitframe=91012 fps=14715 q=-1.0 size=  237568kB time=00:50:34.15 bitrate= 641.4kbitframe=96450 fps=14248 q=-1.0 size=  252123kB time=00:53:35.49 bitrate= 642.3kbitframe=103130 fps=14160 q=-1.0 size=  266333kB time=00:57:18.13 bitrate= 634.6kbiframe=103426 fps=14187 q=-1.0 Lsize=  266833kB time=00:57:27.65 bitrate= 634.0kbits/s    
video:199222kB audio:34638kB subtitle:0 global headers:0kB muxing overhead 14.099408%

命令:ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts

输出:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 17 2013 20:00:17 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2013-08-06 12:15:23
    encoder         : HandBrake 0.9.9 2013051800
  Duration: 00:03:16.46, start: 0.000000, bitrate: 652 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 512x384, 521 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Metadata:
      creation_time   : 2013-08-06 12:15:23
    Stream #0:1(jpn): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s
    Metadata:
      creation_time   : 2013-08-06 12:15:23
Output #0, mpegts, to 'intermediate2.ts':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf54.63.104
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 512x384, q=2-31, 521 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
    Metadata:
      creation_time   : 2013-08-06 12:15:23
    Stream #0:1(jpn): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 125 kb/s
    Metadata:
      creation_time   : 2013-08-06 12:15:23
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[adts @ 0x7f80ec03b600] Encoder did not produce proper pts, making some up.
frame= 5887 fps=0.0 q=-1.0 Lsize=   17671kB time=00:03:16.46 bitrate= 736.8kbits/s    
video:12502kB audio:3020kB subtitle:0 global headers:0kB muxing overhead 13.845737%

命令:ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4

输出:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 17 2013 20:00:17 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[mpegts @ 0x7ff718806600] max_analyze_duration 5000000 reached at 5014800 microseconds
Input #0, mpegts, from 'concat:intermediate1.ts|intermediate2.ts':
  Duration: 00:03:16.44, start: 1.400000, bitrate: 11864 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 512x384 [SAR 1:1 DAR 4:3], 30 tbr, 90k tbn, 180k tbc
    Stream #0:1[0x101](jpn): Audio: aac ([15][0][0][0] / 0x000F), 22050 Hz, stereo, fltp, 88 kb/s
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf54.63.104
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 512x384 [SAR 1:1 DAR 4:3], q=2-31, 90k tbn, 90k tbc
    Stream #0:1(jpn): Audio: aac ([64][0][0][0] / 0x0040), 22050 Hz, stereo, 88 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 6852 fps=0.0 q=-1.0 size=   16005kB time=00:03:48.34 bitrate= 574.2kbits/frame=18284 fps=18283 q=-1.0 size=   37212kB time=00:10:09.36 bitrate= 500.3kbitframe=30997 fps=20664 q=-1.0 size=   64882kB time=00:17:13.13 bitrate= 514.5kbitframe=44215 fps=22107 q=-1.0 size=   94363kB time=00:24:33.73 bitrate= 524.5kbitframe=53566 fps=21144 q=-1.0 size=  119825kB time=00:29:45.43 bitrate= 549.8kbitframe=66513 fps=21926 q=-1.0 size=  146324kB time=00:36:57.00 bitrate= 540.7kbitframe=75414 fps=21303 q=-1.0 size=  168300kB time=00:41:53.70 bitrate= 548.5kbitframe=87198 fps=21583 q=-1.0 size=  197198kB time=00:48:26.50 bitrate= 555.8kbitframe=97641 fps=21506 q=-1.0 size=  224716kB time=00:54:14.60 bitrate= 565.6kbitframe=107076 fps=21245 q=-1.0 size=  245085kB time=01:01:30.87 bitrate= 544.0kbiframe=109313 fps=21094 q=-1.0 Lsize=  253887kB time=01:04:00.53 bitrate= 541.6kbits/s    
video:212399kB audio:38223kB subtitle:0 global headers:0kB muxing overhead 1.303254%

但现在,音频和视频都停止了,而文件仍在播放。每次我做同样的事情,就会发生不同的事情......

答案1

如果您想连接输入文件而不重新编码,则两个文件应具有相同的音频采样率。第一个文件中的音频采样率为 22050 Hz,第二个文件中的音频采样率为 44100 Hz。您需要对其中一个文件中的音频进行重新编码,以匹配另一个文件。

答案2

使用此页上的 concat 解复用器:https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files

对我有用!希望这能有所帮助...

ffmpeg -f concat -i mylist.txt -c copy output

Mylist.txt 应具有以下形式:

# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

相关内容