Rearranging the order of ts files in m3u8 causes them to get stuck during playback - linux

I have one m3u8 file and several TS files.
The following is the actual output of the m3u8 file.
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:5
#EXTINF:4.027222,
test0000.ts
#EXTINF:4.004000,
test0001.ts
#EXTINF:4.004000,
test0002.ts
#EXTINF:4.004000,
test0003.ts
#EXT-X-ENDLIST
I rewrote this m3u8 in the following format, saved it, and played it.
Then the playback order of the video was exactly as I changed the m3u8.
However, the video playback does not work as expected and gets stuck.
#extm3u.
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:5
#EXTINF:4.027222,
test0003.ts
#EXTINF:4.004000,
test0002.ts
#EXTINF:4.004000,
test0001.ts
#EXTINF:4.004000,
test0000.ts
#EXT-X-ENDLIST
If I want to change the order of the TS files like this, how do I edit the m3u8 file?
Or can I use the ffmpeg command to change the order of the ts files and then recreate the m3u8 file?

I'm afraid you're not allowed to manually edit the playlist (or re-generate it using ffmpeg command). Due to the restriction of HLS protocol (RFC8216) , media segments (the .ts files in your case) in the middle must NOT be removed when you set either value event or vod to -hls_playlist_type option in your ffmpeg command , even without -hls_playlist_type, it is still limited to change the playlist (and NOT including freely removing any media segment).
Quote from General Server Responsibilities in RFC8216
The server MUST NOT change the Media Playlist file, except to:
Append lines to it (Section 6.2.1).
Remove Media Segment URIs from the Playlist in the order that they
appear, along with any tags that apply only to those segments
(Section 6.2.2).
Increment the value of the EXT-X-MEDIA-SEQUENCE or EXT-X-
DISCONTINUITY-SEQUENCE tags (Section 6.2.2).
Add an EXT-X-ENDLIST tag to the Playlist (Section 6.2.1).
A Media Playlist has further constraints on its updates if it
contains an EXT-X-PLAYLIST-TYPE tag. An EXT-X-PLAYLIST-TYPE tag with
a value of VOD indicates that the Playlist file MUST NOT change. An
EXT-X-PLAYLIST-TYPE tag with a value of EVENT indicates that the
server MUST NOT change or delete any part of the Playlist file; it
MAY append lines to it.
Note that the EXT-X-PLAYLIST-TYPE in your playlist related to -hls_playlist_type in ffmpeg

Related

Remove subtitle/caption from hls and dash manifest file

I am currently using aws mediaconvert to encode videos to hls and dash format. I believe that in the m3u8 (for hls) and mpd (for dash) file which is generated, these can be parsed to remove required subtitles. I am looking to parse the m3u8 and mpd file, create an updated manifest without required subtitles and save it back to s3. Has someone previously done something similar?
This could be done with a Lambda Function triggered by the arrival of the source manifest in a specified S3 bucket. A Lambda script could remove the captions line(s) and post a revised manifest to the different S3 bucket. The script should then copy the segments over to the new bucket as well in order to maintain a playable HLS or DASH file group.
Alternatively you can ingest the asset as-is into MediaPackage as a VOD asset, and use the '?aws.manifestfilter=subtitle_language:xxx' filter when asking for the VOD manifest. This feature of MediaPackage returns a customized (filtered) version of the source manifest on demand without you having to permanently alter it. Specifying a filter of 'subtitle_language:zzz' will return a manifest with no subtitles in it. You could also ask for only specified subtitle renditions to be included.

How to include same segment into m3u8 playlist multiple times?

I have several .ts files, generated by ffmpeg from live stream. All of them have the same length (well, approximately). Ideally, they are being generated constantly, with names representing the datetime when they have been recorded (for example, "2019-04-11_10-51-40.ts"). But it may happen so, that for any technical reasons recording was being stopped for a while and files have not been generated.
Now, I have a task to create a playlist of these files for a certain datetime range - and if there are no files for part of this range, I need to show just a black screen. I have a black video for this purpose with the same length as other files. So, I'm trying to manually create an .m3u8 file and insert this black video in all gaps between normal videos that I have. For example:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:34
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:30.07,
http://example.com/black_video.ts
#EXTINF:30.07,
http://example.com/black_video.ts
#EXTINF:33.33,
http://example.com/2019-04-11_10-51-40.ts
#EXTINF:33.33,
http://example.com/2019-04-11_10-52-15.ts
#EXTINF:25.00,
http://example.com/2019-04-11_10-52-48.ts
#EXT-X-ENDLIST
The problem is that when I'm trying to play this playlist, it does not play correctly: depending on player either only one black part is being played no matter how much of them there are in a sequence (VLC), or player is getting stuck after first black video ("Play HLS M3u8" extension for Chrome or player on our own service, based on hls.js).
I also tried to use #EXT-X-DISCONTINUITY; in this case all videos are being played, but progress bar drops to the very beginning after each #EXT-X-DISCONTINUITY appearance, which is also an undesired behaviour. Example:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:34
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:30.07,
http://example.com/black_video.ts
#EXT-X-DISCONTINUITY
#EXTINF:30.07,
http://example.com/black_video.ts
#EXTINF:33.33,
http://example.com/2019-04-11_10-51-40.ts
#EXTINF:33.33,
http://example.com/2019-04-11_10-52-15.ts
#EXTINF:25.00,
http://example.com/2019-04-11_10-52-48.ts
#EXT-X-ENDLIST
As for black videos themselves, I tried several options: each link was to the same file; each link was to a different symlink to the same file; each link was to a separately generated black video - none of them worked.
As of now the only way I found is to collect all normal videos for the time range, fill the gaps with black video files and then combine them into one file with ffmpeg -f concat and split the concatenated file back to parts. But this approach works way longer than manual m3u8 file creation, so I would like to avoid it.
So, what could be the reason of manually formed playlist not working correctly and how could I fix that? May it be the problem with playlist itself, or playlist is technically fine but players I used possibly don't fully implement the specification?
TLDR: I am creating m3u8 playlist manually and I want to insert the same video multiple times into this playlist. Unfortunately, such playlist is not being played correctly: depending on player either this inserted video is being played only once no matter how many times has it been included, or playing is getting stuck after the first inserted video part. May it be that there is something wrong with playlist and how can this be fixed?
Add a #EXT-X-DISCONTINUITY tag before and after black_video.ts file and change the #EXT-X-VERSION tag to 5. That should fix the issue. This solution worked for me on VLC player.

For an HLS VOD Stream, Is it possible to only play specific Media Sequences in a Media Playlist File?

I'd like to play specific time-segments from an HLS Stream, without needing to re-edit the original MP4 file. Is it possible to alter the Media Playlist File to play specific TS Media Sequences that are out of order?
For instance, in the below M3U list, is it possible to only play fileSequence0-fileSequence2, then skip over fileSequence3 and go right to fileSequence4?
Example M3U List:
#EXTM3U
#EXT-X-PLAYLIST-TYPE:EVENT
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
fileSequence0.ts
#EXTINF:10.0,
fileSequence1.ts
#EXTINF:10.0,
fileSequence2.ts
#EXTINF:10.0,
fileSequence3.ts
#EXTINF:10.0,
fileSequence4.ts
According to HLS Documentation, I would need to change or omit the Media Sequence Number for fileSequence3.ts in order to skip it, but I'm unsure if this is possible.
6.3.5. Determining the Next Segment to Load
...
The first segment to load is generally the segment that the client has chosen to play first (see Section 6.3.3).
In order to play the presentation normally, the next Media Segment to load is the one with the lowest Media Sequence Number that is greater than the Media Sequence Number of the last Media Segment loaded.
Yes, you can play them in any order, Just put a #EXT-X-DISCONTINUITY tag before any 'splice'. You also need #EXT-X-ENDLIST at the end, or the player will assume this is a live manifest and only play the most recent segments.
If the segments do not begin with keyframes however, you may not get the result you want.

how to play mpd file

.
I am trying to understand how mpd file plays and i am referring to the following data set:
http://www-itec.uni-klu.ac.at/ftp/datasets/mmsys12/Valkaama/MPDs/Valkaama_1s_act_isoffmain_DIS_23009_1_v_2_1c2_2011_08_30.mpd
In mpd file format there is segment base consists of mp4 chunk and within it has chunk list with extension .m4s.I downloaded mpd file using :
http://www-itec.uni-klu.ac.at/ftp/datasets/mmsys12/Valkaama/valkaama_1s/valkaama_1s_50kbit/valkaama_50kbit_dash.mp4
and m4s chunk by following link:
http://www-itec.uni-klu.ac.at/ftp/datasets/mmsys12/Valkaama/valkaama_1s/valkaama_1s_50kbit/valkaama_1s1.m4s
I tried to play both mp4 and m4s in vlc player but not able to play any of these two so i want to ask which of the chunk links in the mpd file forma i can be able to play standalone in vlc player.
Please correct me if any of my observations is wrong:
Regards
Mayank
MPD file is just a index of streams with various formats in order to adapt to your bandwidth, to get more information follow the links of the other answers here.
It's possible to download all streams and merge them into a single file, you could achieve this by using youtube-dl:
youtube-dl http://URL/TO/manifest.mpd
You can get more information in https://stackoverflow.com/a/39931712/1522342.
Also, VLC 3.0.0+ can play that kind of file from a url, just open VLC, use the shortcut CTRL+N, paste the url and enjoy.
A DASH player plays an MPD by selecting a Period, and in the Period one or more AdaptationSet, and then one Representation per AdaptationSet. For the chosen Representation, it downloads and passes the intialization segment and some media segments to the media engine. As indicated by others you can simulate that by concatenating (simply using caton Linux).
The MPEG-DASH standard requires that initialization segments (in your case the mp4 file) contain no data. This is because when switching the player might use several times the initialization segment. You can open it in a player but it does not contain any media.
For m4s files, they contain media data but they cannot be interpreted without the associated initialization segment.
you can download init segment (SegmentBase/Initialization#sourceURL) and all media segments (SegmentList/SegmentURL#media) and concatenate everything (e.g. with the copy command on windows). The result should be playable on VLC. This has to be done for audio and video separately. In the next step you can then use MP4Box or similar tools to mux audio and video.
Alternatively you can use www.dash-downloader.com to download everything in one step. The page will display some log explaining what it's doing. That might be helpfull.
(full disclosure: that's my website).
I dont think it is possible to play any of the files in a standalone player. The mp4 is the init segment which is required to decode the .m4s media segments. I dont think there is an option in the vlc player to map an init segment to multiple media segments. Nevertheless you can try a Dash player to play the manifest file. For instance dash.js
Initialization segment: A sequence of bytes that contain all of the initialization information required to decode a sequence of media segments. This includes codec initialization data, Track ID mappings for multiplexed segments, and timestamp offsets (e.g. edit lists).
Media segment: A sequence of bytes that contain packetized & timestamped media data for a portion of the media timeline. Media segments are always associated with the most recently appended initialization segment.
Source: http://www.w3.org/TR/media-source/#init-segment

Can .m3u8 playlist files reference OTHER .m3u8 playlist files?

I know that the EXT-X-STREAM-INF tag provides a mechanism for linking to another playlist file, but this appears to be to support variant encoding's (at lower or higher bandwidth) of the same stream. What I would like to do is return a playlist that references actual .ts files but the last reference in the playlist is to the "next" .m3u8.
The reason I want this is that I can use this mechanism to build a stateless HLS server that is not necessarily serving a "live" stream (because the playlist URL can encode information about WHERE in the stream you are). Any idea what players support this (does iOS?)?
It is not supported in the draft specification (as of draft 10).
Yes They can. The main m3u8 that holds other m3u8 is called variant playlist m3u8.
But why we need a variant playlist? - for storing various bit rates of the same stream
I used "One Click m3u8" app from the mac app store - that created the variant playlist as well the children m3u8. No need of ffmpeg or mediafilesegmenter.
How to video here from youtube
Website

Resources