【问题标题】:How to adjust mpeg 2 ts start time with ffmpeg?如何使用 ffmpeg 调整 mpeg 2 ts 开始时间?
【发布时间】:2015-09-02 18:55:46
【问题描述】:

我正在编写简单的 HLS(Http Live Streaming)java 服务器来直播(真正的直播,不是点播)屏幕显示 + 语音。我不断地获取大量图像帧和音频样本作为我的服务的输入,并生成 mpeg 2 ts 文件 + m3u8 播放列表网页作为输出。工作流程如下:

  1. 在一段时间内收集(缓冲)源视频帧和音频
  2. 将一系列视频帧转换为 h.264 编码的视频文件
  3. 将音频样本转换为 mp3 音频文件
  4. 使用 ffmpeg 命令将它们合并到.ts 文件

    ffmpeg -i audio.mp3 -i video.mp4 -f mpegts -c:a copy -c:v copy -vprofile main -level:v 4.0 -vbsf h264_mp4toannexb -flags -global_header segment.ts
    
  5. 在 m3u8 播放列表上发布多个 .ts 文件。

问题是在播放第一段后导致播放列表中断。 VLC 记录以下错误:

freetype error: Breaking unbreakable line
ts error: libdvbpsi (PSI decoder): TS discontinuity (received 0, expected 4) for PID 17
ts error: libdvbpsi (PSI decoder): TS duplicate (received 0, expected 1) for PID 0
ts error: libdvbpsi (PSI decoder): TS duplicate (received 0, expected 1) for PID 4096
core error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 1000 ms)
core error: ES_OUT_RESET_PCR called
core error: Could not convert timestamp 185529572000
ts error: libdvbpsi (PSI decoder): TS discontinuity (received 0, expected 4) for PID 17
ts error: libdvbpsi (PSI decoder): TS duplicate (received 0, expected 1) for PID 0
ts error: libdvbpsi (PSI decoder): TS duplicate (received 0, expected 1) for PID 4096
core error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 8653 ms ignored)
core error: Could not get display date for timestamp 0
core error: Could not convert timestamp 185538017000
core error: Could not convert timestamp 185538267000
core error: Could not convert timestamp 185539295977
...

我猜原因是分段的开始时间不属于一个流,但是一旦添加了新块,就不可能连接和重新分段(使用ffmepg -f segment)整个流。尝试将#EXT-X-DISCONTINUITY 标记添加到播放列表中作为suggested here,但它没有帮助。当我ffprobe他们时,我得到:

Input #0, mpegts, from '26.ts':
Duration: 00:00:10.02, start: 1.876978, bitrate: 105 kb/s
Program 1
Metadata:
  service_name    : Service01
  service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 640x640, 4 fps, 4 tbr, 90k tbn, 8 tbc
Stream #0:1[0x101]: Audio: mp3 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 64 kb/s   

Duration: 00:00:10.02, start: 1.876978, bitrate: 105 kb/s 行中的起始值对于所有段都或多或少相等。 当我从可用的经过验证的播放列表(如http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch1/appleman.m3u8)中检查片段时,它们对于每个片段都有不同的起始值,例如:

Input #0, mpegts, from 'segm150518140104572-424570.ts':
Duration: 00:00:06.17, start: 65884.808689, bitrate: 479 kb/s
Program 257
Stream #0:0[0x20]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 320x180 [SAR 1:1 DAR 16:9], 30 fps, 29.97 tbr, 90k tbn, 60 tbc
Stream #0:1[0x21]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 115 kb/s
Stream #0:2[0x22]: Data: timed_id3 (ID3  / 0x20334449)

以及它之后的下一个

Input #0, mpegts, from 'segm150518140104572-424571.ts':
Duration: 00:00:06.22, start: 65890.814689, bitrate: 468 kb/s
Program 257
Stream #0:0[0x20]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 320x180 [SAR 1:1 DAR 16:9], 30 fps, 29.97 tbr, 90k tbn, 60 tbc
Stream #0:1[0x21]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 124 kb/s
Stream #0:2[0x22]: Data: timed_id3 (ID3  / 0x20334449)

区别在于segm150518140104572-424571.ts的开始时间等于segm150518140104572-424570.ts的开始时间+持续时间。

如何使用ffmpeg 调整此起始值?或者也许我的整个方法是错误的?不幸的是,我在互联网上找不到使用 ffmepg 实现的实时(非点播)视频服务的工作示例。

【问题讨论】:

  • 你能分享你的 4 ts 片段吗?你可以给我发链接。我会在我的播放列表中使用它们,看看会发生什么。
  • 您的段 38.ts、39.ts、40.ts 和 41.ts 都是相同的文件。 (如果它们正在更新,请检查您的缓冲区)

标签: ffmpeg http-live-streaming mpeg2-ts ffprobe


【解决方案1】:

我已经用here 描述的方法回答了我自己的问题。 时间戳可以用-f segment格式的-initial_offset参数调整:

ffmpeg -i in.ts -vcodec copy -acodec copy -f segment -initial_offset 10 -segment_format mpegts out%d.ts

对于每个新段,我计算必要的-initial_offset 作为所有先前段长度的总和。

【讨论】:

  • 您是否使用了 2 个ffmpeg 命令来访问 ts 文件?此外,当我使用-initial_offset 10 尝试您的第二个命令时,现在我最终的开始时间为 11.4 秒。你遇到过同样的事情吗?
【解决方案2】:

它不仅仅是时间戳,它也是连续性指标。因此,设置开始时间并不能解决您的问题。您必须编码为单个流。

【讨论】:

    【解决方案3】:

    你可以设置“-segment_time 20”只输出一个ts文件

    fmpeg.exe -i 0.mp3 -c copy -bsf:v aac_adtstoasc -f segment -segment_time 20 -initial_offset 10 -segment_format mpegts out%d.ts
    

    【讨论】:

      猜你喜欢
      • 2012-03-06
      • 2014-02-12
      • 2016-01-14
      • 2013-02-24
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 2023-03-30
      • 2017-11-07
      相关资源
      最近更新 更多