How to create a new. M3U file correctly? (Since I already have streaming .TS)

Asked

Viewed 5,807 times

8

I’m starting to study to make an online teaching site (live video), but the examples I’m using from the internet are giving me the most varied errors, as the example I use...
In this example, he is carrying infinitely...

Today the file I am using to study comes from the following site and I need to touch it in the BROWSER: "http://dveo.com/downloads/TS-sample-files/San_Diego_Clip.ts"


I started out that way:

Here is the file "exemplo.m3u" that I created:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:11167259
#EXTINF:10.000,
http://dveo.com/downloads/TS-sample-files/San_Diego_Clip.ts?sd=10
#EXTINF:10.000,
http://dveo.com/downloads/TS-sample-files/San_Diego_Clip.ts?sd=10
#EXTINF:10.000,
http://dveo.com/downloads/TS-sample-files/San_Diego_Clip.ts?sd=10


To play I’m using jpayer:

jwplayer('my-video').setup({
  playlist: [
    {
      sources: [
        {
        default: 'false',
            file: 'exemplo.m3u',
            label: '0',
            type: 'hls',
            preload: 'none'
        }
      ]
    }
  ],
  primary: 'html5',
  hlshtml: true
});

Well he’s carrying it endlessly, I can’t see where I’m going wrong...

1 answer

12

TL;DR

Use the Ffmpeg.

To recreate m3u8 from only one file . ts:

ffmpeg -i arquivo_original.ts -codec copy -hls_flags single_file -hls_list_size 0 nova_playlist.m3u8

The command for multiple files is:

ffmpeg -i "concat:arquivo0.ts|arquivo1.ts|arquivo2.ts|arquivo3.ts" -c copy -hls_list_size 0 nova_playlist.m3u8

It will generate a new file . ts, which can be ignored as it is a copy of the original - that’s what the option -c copy does. Removing the option causes it to "reencode" the video.


Long answer - Why video doesn’t play?

The example used video: San_Diego_Clip.ts, is in MPEG1/2, format not supported in browsers. It was probably created this way to be consumed otherwise, i.e. using the VLC.

A second reason for him not to play is because his page is not being served from the domain where the video resides, by itself of the same origin policy.

For example - the same page, open locally, allows viewing only the video that is also local:

screenshot do navegador

Opened from the server, both videos play normally (note that the 'local' in this case is also the server):

screenshot do navegador

The code used for these two pages was exactly the same:

<!DOCTYPE html>
<html>
<head>
    <title>Precisa de um título, blogueira!</title>
</head>
<body>
    <div style="display:inline-block">
        <h3>Esse vídeo está no servidor:</h3>
        <video src="http://192.168.56.1/saida.m3u8" width="320" height="180" controls autoplay></video>
    </div>
    <div style="display:inline-block">
        <h3>Este vídeo está local:</h3>
        <video src="saida_2.m3u8" width="320" height="180" controls autoplay></video>
    </div>
</body>
</html>

Regarding the m3u:

m3u is a file of playlist, that has many features. Recreating it correctly is not exactly a trivial task.

That said, for the example shown above, I did a m3u extremely simple:

#EXTM3U
#EXT-X-VERSION:3
#EXTINF:0,
saida_2.ts
#EXT-X-ENDLIST

Behold:

  • Most of the information of an m3u has been removed;
  • The duration of the segment is zero;
  • I used a middle snippet of the video;

Which means that at worst it is possible to create an m3u "in hand". The problem should happen if the video files are really segmented, and divided every ten seconds as some examples that are out there. Anyway, in the specifications, it is said:

"Generally, durations SHOULD be decimal-floating-point, with enough Accuracy to avoid perceptible error when segment durations are accumulated."

That is, putting wrong durations can cause glitches, but it shouldn’t stop the video from playing.

Use the Ffmpeg!


Previous answer:

jwplayer seems to only play HLS using premium accounts:

Apple’s HLS Protocol, using M3U8 manifest files and TS media files. HLS builds upon standard HTTP, making it easy to deploy and firewall resilient. All JW Player Editions support HLS on mobile Devices, but only the Premium and Higher support HLS on desktop browsers. See Using Apple HLS Streaming for more info.

To test your . M3U8, create a page with the following code:

<!DOCTYPE html>
<html>
<head>
    <title>precisa de um titulo, blogueira</title>
</head>
<body>
    <video width="640" height="360" controls>
        <source src="saida.m3u8" type="application/x-mpegURL">
    </video>
</body>
</html>

Warning: Everything indicates that this code only works in Edge!


To generate an . M3U8, you can use the program Ffmpeg.

Download the file and extract somewhere easily accessible.
Access it by command prompt, and type the following:

ffmpeg -i meu_video.mp4 saida.m3u8

Ffmpeg accepts several video formats, but I suggest that for testing you use any mp4, recorded from a mobile phone, or downloaded from the internet.

The result of this command will be multiple files . ts, and a file . m3u8.

Test using the code shown above:

player de video em página html

Sources:
Media formats supported by the HTML audio and video Elements
How to create byte-range m3u8 playlist for HLS?
HLS - how to create a m3u8 manifest if I have ts files (Ubuntu)?
How to play Html5 video play m3U8 on mobile and desktop?
Ffmpeg - Concatenating media files

  • It seems to me that she does not need to create new Streaming, she already has the file . TS being generated... So need to display in browser... What an alias and my problem too.

  • @Robervalsena 山 本 You have the file . ts and do not have the file . m3u8 corresponding?

  • 1

    @Camilayamamoto edited my answer - please take a look! :)

  • @Robervalsena 山 本 edited reply - I don’t see many other options besides this... :( Good luck!

  • @Camilayamamoto I hope this solution helps you!

  • @Camilayamamoto do not know if it was discontinued - on their page doesn’t seem to say that - and the last update on the page was quite recent. Anyway, if you continue to have a problem with it, I suggest you open a new question, as it is falling outside the scope of this... =]

  • @BlogerVoce knows how to play streaming "dveo.com/downloads/TS-sample-files/San_diego_clip.ts"; ?? __1) Today I put this URL in the browser... it asks to save.. __2) I put myself in the "web player" (jwplayer for example) it does nothing....

  • @Camilayamamoto hi there! so - it’s in an unsupported format in the browsers right - I also couldn’t touch, I don’t know if it’s possible without converting it before

  • mmm understand, pity, I did several tests, creating the .M3U8 or *.M3U local and everything went well.. BUT as I need to play THAT, remote.. from the public example... will not.. because just lack the .M3U ... ___=> SO I POINT OUT THE LOCAL ARCHIVE .M3U to the .TS remote.. but ai.. it stops.. GOOD if you have tips .. on how to play the file , remote .TS Agradeco... posi looks like everything is wrapped up from creating to darn .M3U8

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.