使用 ffmpeg 转换带有延迟音频流的流

使用 ffmpeg 转换带有延迟音频流的流

我正在尝试使用 ffmpeg 进行转换TS 流文件转换为 MP4。请注意,直到 10 秒左右才有音频。每当我尝试转换(或复制)此 TS 文件时,我都听不到音频。我怀疑这是因为 ffmpeg 无法在文件开头找到音频流,但我如何让它找到稍后开始的音频?

例如,这是我运行此行时的输出ffmpeg -i beinold.ts -vf scale=1280:720 bein.mp4。我添加了比例,因为否则,ffmpeg 会将整个 MP4 返回为 270p,这是前几秒的分辨率。请注意没有错误。即使运行也-analyzeduration 15000000不起作用。

ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[mpegts @ 0x7fe58e801200] PES packet size mismatch
    Last message repeated 1 times
[mpegts @ 0x7fe58e801200] Could not find codec parameters for stream 1 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels): unspecified sample format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts @ 0x7fe58e801200] Could not find codec parameters for stream 2 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels): unspecified sample format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'beinold.ts':
  Duration: 00:00:50.05, start: 0.466722, bitrate: 3065 kb/s
  Program 1 
    Metadata:
      service_name    : 
      service_provider: 
    Stream #0:0[0x64]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 480x270 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
    Stream #0:1[0xc8](eng): Audio: aac ([15][0][0][0] / 0x000F), 0 channels
    Stream #0:2[0xc9](spa): Audio: aac ([15][0][0][0] / 0x000F), 0 channels
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x7fe58f000c00] using SAR=1/1
[libx264 @ 0x7fe58f000c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fe58f000c00] profile High, level 3.1
[libx264 @ 0x7fe58f000c00] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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 lookahead_threads=1 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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'bein.mp4':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc57.107.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[h264 @ 0x7fe58e07c600] Increasing reorder buffer to 107.87 bitrate=3195.9kbits/s speed=1.34x     
[h264 @ 0x7fe58f800000] Increasing reorder buffer to 2
frame= 1500 fps= 31 q=-1.0 Lsize=   25728kB time=00:00:49.94 bitrate=4219.6kbits/s dup=7 drop=0 speed=1.04x    
video:25708kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.078066%
[libx264 @ 0x7fe58f000c00] frame I:7     Avg QP:22.72  size: 96187
[libx264 @ 0x7fe58f000c00] frame P:398   Avg QP:25.43  size: 37357
[libx264 @ 0x7fe58f000c00] frame B:1095  Avg QP:29.51  size:  9848
[libx264 @ 0x7fe58f000c00] consecutive B-frames:  0.7%  4.3%  5.2% 89.9%
[libx264 @ 0x7fe58f000c00] mb I  I16..4:  8.9% 54.3% 36.8%
[libx264 @ 0x7fe58f000c00] mb P  I16..4:  3.1% 10.7%  4.1%  P16..4: 35.4% 23.6% 12.2%  0.0%  0.0%    skip:11.0%
[libx264 @ 0x7fe58f000c00] mb B  I16..4:  0.2%  0.5%  0.2%  B16..8: 39.2% 10.9%  2.9%  direct: 4.9%  skip:41.1%  L0:40.6% L1:49.6% BI: 9.8%
[libx264 @ 0x7fe58f000c00] 8x8 transform intra:58.3% inter:57.1%
[libx264 @ 0x7fe58f000c00] coded y,uvDC,uvAC intra: 71.3% 67.7% 37.4% inter: 21.0% 18.7% 1.9%
[libx264 @ 0x7fe58f000c00] i16 v,h,dc,p: 13% 51% 10% 26%
[libx264 @ 0x7fe58f000c00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 28% 17%  5%  6%  6%  8%  6%  8%
[libx264 @ 0x7fe58f000c00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 28% 17%  5%  7%  7%  7%  5%  6%
[libx264 @ 0x7fe58f000c00] i8c dc,h,v,p: 46% 27% 18%  9%
[libx264 @ 0x7fe58f000c00] Weighted P-Frames: Y:0.3% UV:0.3%
[libx264 @ 0x7fe58f000c00] ref P L0: 61.9% 14.4% 17.9%  5.8%  0.0%
[libx264 @ 0x7fe58f000c00] ref B L0: 93.8%  5.2%  1.0%
[libx264 @ 0x7fe58f000c00] ref B L1: 97.5%  2.5%
[libx264 @ 0x7fe58f000c00] kb/s:4207.72

答案1

这在这里有效:

ffmpeg -analyzeduration 15M -i beinold.ts -c copy bein.mp4

音频开始于 9 秒左右。分辨率得以保留,即如果播放器支持解码器重新初始化,那么当流中发生这种情况时,您应该会看到分辨率切换。VLC 和 Potplayer (Windows) 都支持。

答案2

尝试一下这个工具,可以使这个过程更容易。

温控器是命令行视频转换器 FFMPEG 的 GUI。它可以转换 FFmpeg 可以转换的大多数视频文件。WinFF 可以同时处理多种格式的多个文件。例如,您可以同时将 mpeg、flv 和 mov 全部转换为 avi。

相关内容