如何将 3g2 转换为 mp4 而不丢失音频?

如何将 3g2 转换为 mp4 而不丢失音频?

如何从命令行成功将 .3g2 转换为 .mp4?我使用如下 ffmpeg 命令:

ffmpeg -i input.3g2 -acodec copy -vcodec libx264 output.mp4
ffmpeg -i input.3g2 -acodec ac3 -vcodec libx264 output.mp4

这些命令会产生视频,但不会产生音频。以下是 ffmpeg 的输出:

ffmpeg -i input.3g2 -acodec ac3 -vcodec libx264 input.mp4
ffmpeg version 0.10.2.git Copyright (c) 2000-2012 the FFmpeg developers
  built on Jun 13 2012 05:18:13 with gcc 4.4.5
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-nonfree --enable-version3
  libavutil      51. 58.100 / 51. 58.100
  libavcodec     54. 25.100 / 54. 25.100
  libavformat    54.  6.101 / 54.  6.101
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 78.101 /  2. 78.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Guessed Channel Layout for  Input Stream #0.1 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.3g2':
  Metadata:
    major_brand     : 3g2a
    minor_version   : 0
    compatible_brands: 3g2a
    creation_time   : 2006-02-03 22:54:07
  Duration: 00:00:15.14, start: 0.000000, bitrate: 94 kb/s
    Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 176x144 [SAR 1:1 DAR 11:9], 79 kb/s, SAR 12:11 DAR 4:3, 15 fps, 15 tbr, 15 tbn, 15 tbc
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: qcelp (mp4a / 0x6134706D), 8000 Hz, mono, flt, 14 kb/s
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : AudioHandler
[buffer @ 0xa820b40] w:176 h:144 pixfmt:yuv420p tb:1/15 fr:15/1 sar:12/11 sws_param:flags=2
[ffmpeg_buffersink @ 0xa820ea0] No opaque field provided
[libx264 @ 0xa81fb00] using SAR=12/11
[libx264 @ 0xa81fb00] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0xa81fb00] profile High, level 1.0
[libx264 @ 0xa81fb00] 264 - core 118 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=15 scenecut=40 Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : 3g2a
    minor_version   : 0
    compatible_brands: 3g2a
    creation_time   : 2006-02-03 22:54:07
    encoder         : Lavf54.6.101
    Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 176x144 [SAR 12:11 DAR 4:3], q=-1--1, 15 tbn, 15 tbc
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: ac3 ([165][0][0][0] / 0x00A5), 8000 Hz, mono, flt, 96 kb/s
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : AudioHandler
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 -> libx264)
  Stream #0:1 -> #0:1 (qcelp -> ac3)
Press [q] to stop, [?] for help
frame=  225 fps=214 q=-1.0 Lsize=     327kB time=00:00:14.86 bitrate= 180.4kbits/s
video:146kB audio:178kB global headers:0kB muxing overhead 0.950448%
[libx264 @ 0xa81fb00] frame I:1     Avg QP:23.26  size:  1021
[libx264 @ 0xa81fb00] frame P:218   Avg QP:23.35  size:   671
[libx264 @ 0xa81fb00] frame B:6     Avg QP:26.62  size:   356
[libx264 @ 0xa81fb00] consecutive B-frames: 95.1%  3.6%  1.3%  0.0%
[libx264 @ 0xa81fb00] mb I  I16..4: 11.1% 87.9%  1.0%
[libx264 @ 0xa81fb00] mb P  I16..4:  0.8%  7.4%  0.2%  P16..4: 64.1% 17.4%  6.0%  0.0%  0.0%    skip: 4.1%
[libx264 @ 0xa81fb00] mb B  I16..4:  0.8%  5.2%  0.2%  B16..8: 52.4% 10.4%  1.3%  direct: 2.7%  skip:26.9%  L0:68.5% L1:21.0% BI:10.5%
[libx264 @ 0xa81fb00] 8x8 transform intra:88.3% inter:83.3%
[libx264 @ 0xa81fb00] coded y,uvDC,uvAC intra: 78.7% 80.3% 16.7% inter: 36.2% 30.9% 0.7%
[libx264 @ 0xa81fb00] i16 v,h,dc,p: 16% 12% 55% 17%
[libx264 @ 0xa81fb00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 18% 37%  3%  3%  3%  5%  4%  4%
[libx264 @ 0xa81fb00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 14% 18%  3%  8%  9%  6% 10%  2%
[libx264 @ 0xa81fb00] i8c dc,h,v,p: 58% 16% 19%  6%
[libx264 @ 0xa81fb00] Weighted P-Frames: Y:3.2% UV:0.0%
[libx264 @ 0xa81fb00] ref P L0: 78.6% 15.8%  4.3%  1.2%  0.1%
[libx264 @ 0xa81fb00] ref B L0: 93.0%  6.4%  0.6%
[libx264 @ 0xa81fb00] ref B L1: 98.4%  1.6%
[libx264 @ 0xa81fb00] kb/s:79.65

ffprobe 输出:

ffprobe version 0.10.2.git Copyright (c) 2007-2012 the FFmpeg developers
  built on Jun 13 2012 05:18:13 with gcc 4.4.5
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-nonfree --enable-version3
  libavutil      51. 58.100 / 51. 58.100
  libavcodec     54. 25.100 / 54. 25.100
  libavformat    54.  6.101 / 54.  6.101
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 78.101 /  2. 78.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2006-02-03 22:54:07
    encoder         : Lavf54.6.101
  Duration: 00:00:15.16, start: 0.000000, bitrate: 176 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 176x144 [SAR 12:11 DAR 4:3], 80 kb/s, 15 fps, 15 tbr, 15 tbn, 30 tbc
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: ac3 (ac[45]3 / 0x332D6361), 8000 Hz, mono, s16, 96 kb/s
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : SoundHandler

psimon@zebra:~/tmp/convert_video$
ffprobe version 0.10.2.git Copyright (c) 2007-2012 the FFmpeg developers
  built on Jun 13 2012 05:18:13 with gcc 4.4.5
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-nonfree --enable-version3
  libavutil      51. 58.100 / 51. 58.100
  libavcodec     54. 25.100 / 54. 25.100
  libavformat    54.  6.101 / 54.  6.101
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 78.101 /  2. 78.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2006-02-03 22:54:07
    encoder         : Lavf54.6.101
  Duration: 00:00:15.16, start: 0.000000, bitrate: 176 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 176x144 [SAR 12:11 DAR 4:3], 80 kb/s, 15 fps, 15 tbr, 15 tbn, 30 tbc
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: ac3 (ac[45]3 / 0x332D6361), 8000 Hz, mono, s16, 96 kb/s
    Metadata:
      creation_time   : 2006-02-03 22:54:07
      handler_name    : SoundHandler

答案1

来自文档官方MP4注册机构,似乎不支持 QCELP。但是 AC-3 是支持的。[45]inac[45]3 是破折号的 ASCII 码,也就是ac-3,这是 MP4 的有效编解码器。因此,似乎文件本身是有效的,否则 FFmpeg 会抱怨。

我猜想是 QuickTime 本身无法将文件读取为 MP4。您可以尝试按照建议将扩展名更改为 M4V这里或者这里或者尝试编码为 MOV 容器,这对 QuickTime 来说更为原生。

再说一次,如果您编码为 h.264 / AAC 音频,您将获得与 MP4 的最佳兼容性,它将是这样的:

ffmpeg -i input.3g2 -c:v libx264 -c:a libfaac out.mp4

AAC 编码器采用各种参数,最值得注意的是:

  • -ar 44100作为采样率
  • -ac 2作为音频通道数(使用 1 表示单声道)
  • -b:a

相关内容