kaltura / nginx-vod-module

NGINX-based MP4 Repackager
GNU Affero General Public License v3.0
1.96k stars 433 forks source link

hls segment 376 bytes length #288

Closed GoodGame closed 8 years ago

GoodGame commented 8 years ago

Hello!

I have problem with hls fragments.

$cat master.m3u8

EXTM3U

EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1131572,RESOLUTION=640x360,CODECS="avc1.42c01e,mp4a.40.2"

http://domain.tld/upload/gallery/video/10684/tr360.mp4/index-v1-a1.m3u8

$cat index-v1-a1.m3u8

EXTM3U

EXT-X-TARGETDURATION:4

EXT-X-ALLOW-CACHE:YES

EXT-X-PLAYLIST-TYPE:VOD

EXT-X-VERSION:3

EXT-X-MEDIA-SEQUENCE:1

EXTINF:1.000,

http://domain.tld/upload/gallery/video/10684/tr480.mp4/seg-1-v1-a1.ts

EXTINF:4.000,

http://domain.tld/upload/gallery/video/10684/tr480.mp4/seg-2-v1-a1.ts

EXTINF:4.000,

http://domain.tld/upload/gallery/video/10684/tr480.mp4/seg-3-v1-a1.ts ...

Some segments (starts with 3 serment in my case) have Content-Length:376 and contains mp3 (?) structure.

Content in hex: 4740 0015 0000 b00d 0001 c100 0000 01ef ff36 90e2 3dff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff 474f ff15 0002 b03c 0001 c100 00e1 00f0 1125 0fff ff49 4433 20ff 4944 3320 001f 0001 1be1 00f0 000f e101 f000 15e1 02f0 0f26 0dff ff49 4433 20ff 4944 3320 000f 22bb 5b1a ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff

At the same time dash works fine.

vod_align_segments_to_keyframes on; location ~* /./video/..mp4./(..m3u8|..ts) { proxy_hide_header Access-Control-Allow-Origin; addheader Access-Control-Allow-Origin ""; vod hls; vod_mode remote; vod_segment_duration 4000; vod_upstream_location /vod_upstream; vod_bootstrap_segment_durations 1000; }

location ~* /./video/..mp4./(..mpd|..m4s|init..mp4) { proxy_hide_header Access-Control-Allow-Origin; add_header Access-Control-Allow-Origin "*"; vod dash; vod_mode remote; vod_segment_duration 4000; vod_upstream_location /vod_upstream; vod_bootstrap_segment_durations 1000; vod_dash_absolute_manifest_urls off; }

locations contains star & dash, parser eats it.

I tried last released versions of module and nginx 1.9.14

Whats wrong?

p.s. problem disappears when I set: vod_align_segments_to_key_frames off;

erankor commented 8 years ago

This means your GOP size does not match the segment duration, in this case you configured a segment duration of 4 seconds, if you have a GOP size of 6 seconds, with vod_align_segments_to_key_frames enabled, the first segment should have been 0-4 sec, but it stretches up to 0-6. The second segment that was supposed to be 4-8 sec becomes 6-12 sec. The third segment was supposed to be 8-12 sec, but all these frames were already returned in segment 2, so it returns empty. A segment of size 376 is a segment that has no frames. In our platform, we use a GOP size of 2 seconds, which enables us to choose any even segment duration we want (we use 4/6/10 depending on the protocol) I didn't understand you comment about mp3 structure, the hex dump you pasted is clearly MPEG2 TS. Btw, it is also possible to get an empty segment with vod_align_segments_to_key_frames disabled, in case the last segment contains half a frame. E.g. if you have 120 video frames at a frame rate of 29.97 the total duration is 4.004 sec, so you will get a segment of duration 4 sec with all frames, an a segment of duration 0.004 sec with no frames.

GoodGame commented 8 years ago

If we can't change input mp4 files, solution is enable vod_align_segments_to_key_frames for dash (for #246) and disable for hls?

erankor commented 8 years ago

Either that, or increase the segment duration in HLS to match the GOP, it's not really helpful to have small segments with a large GOP

GoodGame commented 8 years ago

Is there a way to calculate vod_segment_duration based on GOP?

erankor commented 8 years ago

If you mean that the module will automatically determine the segment duration according to GOP, then no, there is no such feature. But anyway, it can be problematic, since:

  1. The GOP size may not be consistent throughout the whole file
  2. In our case, we force a key frame every 2 seconds, but the encoder can output additional key frames as it sees fit (e.g. after a scene cut) and the module can mistakenly use one of those frames to calculate the GOP size
GoodGame commented 8 years ago

It may be better to describe all of this documentation? Without your comments on this issue it would have been impossible to find out what is wrong.

erankor commented 8 years ago

I will add some comment in readme