Opened 4 years ago
Last modified 4 years ago
#8989 open defect
#EXT-X-PROGRAM-DATE-TIME value of existing segments gets over written with new value when appending new segments to an existing playlist file
Reported by: | VigneshRavichandran | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avformat |
Version: | git-master | Keywords: | hls |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | yes | |
Analyzed by developer: | yes |
Description
Summary of the bug:
#EXT-X-PROGRAM-DATE-TIME value of existing segments gets over written with new value when appending new segments to an existing playlist file.
Did some digging into the code base(hlsenc.c and hlsplaylist.c) and found the below behavior:
- The initial_prog_date_time gets set to the current local time
- The existing playlist (.m3u8) file gets parsed and the segments present are added to the variant stream
- The new segment is created and added
- The existing segments and the new segment are written to the playlist file. The initial_prog_date_time from point 1 is used for calculating "#EXT-X-PROGRAM-DATE-TIME" for the segments, which results in incorrect "#EXT-X-PROGRAM-DATE-TIME" values for existing segments
Contents of the existing playlist file (.m3u8) used for debugging:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:50.104+0530
20201112T193150+0530.ts
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:54.104+0530
20201112T193154+0530.ts
#EXTINF:0.900000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:58.104+0530
20201112T193158+0530.ts
#EXT-X-ENDLIST
Contents of the playlist file after command execution:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-13T11:40:48.848+0530
20201112T193150+0530.ts
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-13T11:40:52.848+0530
20201112T193154+0530.ts
#EXTINF:0.900000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-13T11:40:56.848+0530
20201112T193158+0530.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-13T11:40:57.748+0530
20201113T114057+0530.ts
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-13T11:41:01.748+0530
20201113T114101+0530.ts
#EXTINF:0.800000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-13T11:41:05.748+0530
20201113T114105+0530.ts
#EXT-X-ENDLIST
Logs (Added more logs to hlsenc.c and hlsplaylist.c to produce the below):
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_videotoolbox))
Press [q] to stop, ? for help
[hls muxer @ 0x7fd19e80b200] parse_playlist(): Parsing 20201112T193150+0530.ts
[hls muxer @ 0x7fd19e80b200] parse_playlist(): Parsing 20201112T193154+0530.ts
[hls muxer @ 0x7fd19e80b200] parse_playlist(): Parsing 20201112T193158+0530.ts
[hls muxer @ 0x7fd19e80b200] parse_playlist(): Initial program date time: 1605247848.848017 This Epoch second is equal to 2020-11-13T11:40:48.848+0530
[hls muxer @ 0x7fd19e80b200] parse_playlist(): Parsing complete. 3 segments added to vs->segments
Output #0, hls, to 'playlist.m3u8':
Metadata:
encoder : Lavf58.64.100
Stream #0:0: Video: h264 (h264_videotoolbox), yuv420p(tv, progressive), 1280x720, q=2-31, 200 kb/s, 30 fps, 90k tbn, 30 tbc
Metadata:
encoder : Lavc58.112.102 h264_videotoolbox
[hls @ 0x7fd19e81c000] Opening '20201113T114057+0530.ts' for writing=72 drop=0 speed=0.974x
[hls @ 0x7fd19e81c000] Opening 'playlist.m3u8.tmp' for writing
ff_hls_write_file_entry(): Writing 20201112T193150+0530.ts with program_datetime 2020-11-13T11:40:48.848+0530
ff_hls_write_file_entry(): Writing 20201112T193154+0530.ts with program_datetime 2020-11-13T11:40:52.848+0530
ff_hls_write_file_entry(): Writing 20201112T193158+0530.ts with program_datetime 2020-11-13T11:40:56.848+0530
ff_hls_write_file_entry(): Writing 20201113T114057+0530.ts with program_datetime 2020-11-13T11:40:57.748+0530
[hls @ 0x7fd19e81c000] Opening '20201113T114101+0530.ts' for writing=146 drop=0 speed=0.984x
[hls @ 0x7fd19e81c000] Opening 'playlist.m3u8.tmp' for writing
ff_hls_write_file_entry(): Writing 20201112T193150+0530.ts with program_datetime 2020-11-13T11:40:48.848+0530
ff_hls_write_file_entry(): Writing 20201112T193154+0530.ts with program_datetime 2020-11-13T11:40:52.848+0530
ff_hls_write_file_entry(): Writing 20201112T193158+0530.ts with program_datetime 2020-11-13T11:40:56.848+0530
ff_hls_write_file_entry(): Writing 20201113T114057+0530.ts with program_datetime 2020-11-13T11:40:57.748+0530
ff_hls_write_file_entry(): Writing 20201113T114101+0530.ts with program_datetime 2020-11-13T11:41:01.748+0530
[hls @ 0x7fd19e81c000] Opening '20201113T114105+0530.ts' for writing=155 drop=0 speed=0.984x
[hls @ 0x7fd19e81c000] Opening 'playlist.m3u8.tmp' for writing
ff_hls_write_file_entry(): Writing 20201112T193150+0530.ts with program_datetime 2020-11-13T11:40:48.848+0530
ff_hls_write_file_entry(): Writing 20201112T193154+0530.ts with program_datetime 2020-11-13T11:40:52.848+0530
ff_hls_write_file_entry(): Writing 20201112T193158+0530.ts with program_datetime 2020-11-13T11:40:56.848+0530
ff_hls_write_file_entry(): Writing 20201113T114057+0530.ts with program_datetime 2020-11-13T11:40:57.748+0530
ff_hls_write_file_entry(): Writing 20201113T114101+0530.ts with program_datetime 2020-11-13T11:41:01.748+0530
ff_hls_write_file_entry(): Writing 20201113T114105+0530.ts with program_datetime 2020-11-13T11:41:05.748+0530
frame= 264 fps= 30 q=-0.0 Lsize=N/A time=00:00:08.80 bitrate=N/A dup=159 drop=0 speed=1.01x
video:222kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
How to reproduce:
% ffmpeg -re \ -f avfoundation \ -framerate 30 -i 0 \ -codec:v h264_videotoolbox \ -an \ -f hls -hls_list_size 600 -hls_time 4 -hls_flags program_date_time+append_list -strftime 1 -hls_segment_filename '%Y%m%dT%H%M%S%z.ts' \ playlist.m3u8 ffmpeg version: git-master built on: Mac OSX Catalina (Version 10.15.5)
Attachments (3)
Change History (9)
comment:1 by , 4 years ago
Component: | ffmpeg → avformat |
---|---|
Keywords: | playlist ffmpeg m3u8 EXT-X-PROGRAM-DATE-TIME append_list program_date_time removed |
by , 4 years ago
Attachment: | ffmpeg_defect_ticket_8989_wip_fix_vignesh_ravichandran.patch added |
---|
comment:2 by , 4 years ago
I have a WIP fix for this bug. The high level approach is below:
- Add a new variable "discont_program_date_time" of type double to HLSSegment struct
- Store the "EXT-X-PROGRAM-DATE-TIME" value from the existing segments in this variable
- When writing to playlist file if "discont_program_date_time" is set then use that value for "EXT-X-PROGRAM-DATE-TIME" else use the value present in vs->initial_prog_date_time
I have attached a patch containing the code changes for the approach described above. Would appreciate any suggestions/comments on this.
comment:4 by , 4 years ago
Done. I have attached the new version of the patch below. Also, the changes in the patch seems to fix the issue. Below are the test results:
Existing playlist file used for testing:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:50.104+0530
20201112T193150+0530.ts
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:54.104+0530
20201112T193154+0530.ts
#EXTINF:0.900000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:58.104+0530
20201112T193158+0530.ts
Playlist file after command execution:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:50.104+0530
20201112T193150+0530.ts
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:54.104+0530
20201112T193154+0530.ts
#EXTINF:0.900000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-12T19:31:58.104+0530
20201112T193158+0530.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-16T22:00:09.087+0530
20201116T220009+0530.ts
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-16T22:00:13.087+0530
20201116T220013+0530.ts
#EXTINF:4.000000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-16T22:00:17.087+0530
20201116T220017+0530.ts
#EXTINF:1.300000,
#EXT-X-PROGRAM-DATE-TIME:2020-11-16T22:00:21.087+0530
20201116T220021+0530.ts
#EXT-X-ENDLIST
by , 4 years ago
Attachment: | ffmpeg_defect_ticket_8989_wip_fix_vignesh_ravichandran_2.patch added |
---|
Fix for defect 8989
comment:5 by , 4 years ago
Fixed a bug introduced in the playlist sliding window logic, due to the new changes. The below version of the patch contains the fix and also the previous changes.
by , 4 years ago
Attachment: | ffmpeg_defect_ticket_8989_wip_fix_vignesh_ravichandran_3.patch added |
---|
WIP fix for defect 8989