【发布时间】:2015-09-02 18:55:46
【问题描述】:
我正在编写简单的 HLS(Http Live Streaming)java 服务器来直播(真正的直播,不是点播)屏幕显示 + 语音。我不断地获取大量图像帧和音频样本作为我的服务的输入,并生成 mpeg 2 ts 文件 + m3u8 播放列表网页作为输出。工作流程如下:
- 在一段时间内收集(缓冲)源视频帧和音频
- 将一系列视频帧转换为 h.264 编码的视频文件
- 将音频样本转换为 mp3 音频文件
-
使用 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 在 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 片段吗?你可以给我发链接。我会在我的播放列表中使用它们,看看会发生什么。
-
@Alam Here are examples
-
您的段 38.ts、39.ts、40.ts 和 41.ts 都是相同的文件。 (如果它们正在更新,请检查您的缓冲区)
标签: ffmpeg http-live-streaming mpeg2-ts ffprobe