How to include same segment into m3u8 playlist multiple times? - http-live-streaming

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.

Related

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

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

Play MultipleAudioTrack in Roku

I know about Roku doesn't support multiple videos at a time. But, Some Developers are mix up two things multiple playbacks and multiple audio tracks. Roku Does Support Multiple Audio Track?
I tried to Play MultipleAudioTrack in Roku. I used the below code to find a multiple audio track Here ?"m.video.availableAudioTracks :"m.video.availableAudioTracks but here not available any track. my stream check-in VLC MediaPlayer. Here two-track available. But, I not found in Roku. My Audio Format is AAC. I also Set Here m.video.audioFormat = "aac". Any other Configuration required to Playing a multiple Audio.
My m3u8 file is below.
#EXTM3U
#EXT-X-TARGETDURATION:9
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-VERSION:3
#EXTINF:8,
RokuMedia00000001.ts
#EXTINF:8,
RokuMedia00000002.ts
#EXTINF:8,
RokuMedia00000003.ts
Is there any configuration required for the m3u8 file.
I read the HLS Documentation which is provided by Roku. But, I have still some doubts regarding HLS Stream. I used the Roku Premiere plus device. 
For CC, I enable Closed Captions options using coding it's below.
m.videoContent.streamformat = "hls"
m.videoContent.subtitleTracks = [{ language: "EN", description: "EN", trackName: "eia608/1" }]
m.videoContent.subtitleConfig = { trackName: "eia608/1" }
It's not available in M3u8 file content. It's available on my ts File. I mention my M3u8 Content in the above.
Same way, I tried to enable Multiple Audio Track using Coding.
I used Following Field For fetching a multiple Audio Track.
?"m.video.availableAudioTracks :"m.video.availableAudioTracks
m.video.audioFormat = "aac"
I refer to this example of playing a Multiple Audio Track.
I used the aac audio format for playing audio in the Roku video player.
I check the same M3u8 File in other Video Player(VLC, IOS inbuilt player, EXO Player) It takes automatically shows two audio track. 
I'm not sure. But, I think Roku Video player Compalsary required multiple Audio tracks in M3u8 File. Like below. Is it Correct?
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="English",LANGUAGE="en",AUTOSELECT=YES,\
DEFAULT=YES,URI="RokuMedia00000001.ts"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Spanish",LANGUAGE="es-ES",AUTOSELECT=NO,\
DEFAULT=NO,URI="RokuMedia00000001.ts"
But, Here It possible to Put the EXT-X-MEDIA tag in Two Times?
or I don't know which specific field will add I required.
I found one article in the Roku  Knowledge Center article Does Roku support multiple audio tracks?
But, I'm not required to enable multiple audio tracks at the same time. or also not required to playing simultaneously. I required to at a time only a single audio track. Because, I know any media player not support multiple audio track and video track the same time.
I required to change the audio track at run time. If my default track in English and using this option, I  change to It Spanish or any else.
My Actual question is a how-to enable audio track option which provide by Roku and which fields are required in m3u8 files. To enable these options. or Roku has stopped supporting audiotrack options?
I'm not certain about Audio files, but I know that Rokus don't allow you to buffer more than one Video at a time. This effectively means that a Roku cannot play more than one Video at a time.
The same could be true for audio files but I am not certain.
Roku does not support 2 or more parallel audios.
You have to stop one audio to play some another audio.
you can do it like
m.firstAudio.contorl = "stop"
m.secondAudio.contorl = "play"
note that you have to stop it not mute.

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

How to extract the data frame in mp3 stream using gstreamer?

I am now trying to write a music player using Gstreamer.I know that mp3 files are made up with frames (data frame and tag frame).what i want to do is extract the data frame and calculate its hash to identify a file. what should i do?
thinks in advince!
this all is done by gstremer mad element. So if you are writing application then use this element.
NOTE: mad element is comes inside gst-plugin-bad package which you can download from gstremer site

Resources