Skip to content

Instantly share code, notes, and snippets.

@lukebussey
Created January 3, 2017 21:43
Show Gist options
  • Save lukebussey/4d27678c72580aeb660c19a6fb73e9ee to your computer and use it in GitHub Desktop.
Save lukebussey/4d27678c72580aeb660c19a6fb73e9ee to your computer and use it in GitHub Desktop.

Direct copy of pre-encoded file:

$ ffmpeg -i filename.mp4 -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls filename.m3u8
@ciniexpress
Copy link

I was looking for a code to convert video files in a directory where it has multiple subfolder for each video file. I want to run a batch code so it can convert the video files and save them where the original file was there.

Example:

Main folder : Movies

---> Subfolder1 : movie1.mp4

---> subfolder2 : movie2.mp4

---> subfolder3 : movie3.mkv

And so on.

I want the output to be same as the my main structure but in . m3u8 format.

I have used a code where it can convert each movie manually but for some reason I can use the .m3u8 file or link only in that server i can't make it work all over the internet.

for i in .mp4; do ffmpeg -i "$i" -c copy -map 0 -hls_time 3 -hls_list_size 0 -f hls "${i%.}.hls"; done

Thanks

@SilipTv5
Copy link

SilipTv5 commented Mar 2, 2022

what is main benefit of to use m3u8 instead of mp4?

@MLutt
Copy link

MLutt commented May 16, 2022

what is main benefit of to use m3u8 instead of mp4?

In short: If you need to ask, there won't be any.

In long: m3u8 is a HLS Index and widely used for streaming. E.g. transfering the least data possible to provide what is necessary for playback. Though I really do not understand how you didn't get that as literally a first google result... - https://en.wikipedia.org/wiki/HTTP_Live_Streaming

@jacodhis
Copy link

jacodhis commented Jun 7, 2022

man ..this code is amaizing..i can do both hls to mp4 and reverse.Thanks much

@theonlyu
Copy link

theonlyu commented Jul 7, 2022

-codec: copy this is a very fast .but -hls_time not working. default every ts file time always it's 8s. how to do can change ts time, for example 4s or shorter time.

@MLutt
Copy link

MLutt commented Jul 7, 2022

-codec: copy this is a very fast .but -hls_time not working. default every ts file time always it's 8s. how to do can change ts time, for example 4s or shorter time.

... https://ffmpeg.org/ffmpeg-formats.html#hls-2

Please, just read the docs? It's not that hard.

@MLutt
Copy link

MLutt commented Jul 7, 2022 via email

@theonlyu
Copy link

theonlyu commented Jul 7, 2022

-codec: copy this is a very fast .but -hls_time not working. default every ts file time always it's 8s. how to do can change ts time, for example 4s or shorter time.

... https://ffmpeg.org/ffmpeg-formats.html#hls-2

Please, just read the docs? It's not that hard.

sorry.I read already.But still no answer why -hls_time 2 not work. this is my command.

ffmpeg -i file.mp4 -codec: copy -start_number 0 -hls_time 4 -hls_list_size 0 -f hls m3u8/file.m3u8.
but in the m3u8 file always is #EXTINF:8.341667. then I try
ffmpeg -i file.mp4 -force_key_frames "expr:gte(t,n_forced*4)" -codec: copy -start_number 0 -hls_time 4 -hls_list_size 0 -f hls m3u8/file.m3u8.
Same result.

then I use other command.
ffmpeg -i file.mp4 -codec: copy -map 0 -f segment -segment_list file.m3u8 -segment_time 00:00:04 file%03d.ts.
in the m3u8 file also is #EXTINF:8.341667. this -segment_time 00:00:04 also not work.

but when I not use -codec: copy this command can work normal.
ffmpeg -i file.mp4 -start_number 0 -hls_time 4 -hls_list_size 0 -f hls m3u8/file.m3u8. or
ffmpeg -i file.mp4 -map 0 -f segment -segment_list file.m3u8 -segment_time 00:00:04 file%03d.ts.
in the m3u8 file #EXTINF:4.004000. time change already. but it's very slow not with -codec: copy.

I don't why -codec: copy can't use -segment_time or -hls_time?
if anyone have answer plases tell me.

@MLutt
Copy link

MLutt commented Jul 7, 2022 via email

@magic-thomas
Copy link

Thanks for good experience.

After conversion, It works good in Safari , but not in Chrome.

Is this Chrome's bug ?

@MLutt
Copy link

MLutt commented Oct 11, 2022 via email

@sohag1192
Copy link

how to make any m3u8 source use to own m3u8 make

@alkozin
Copy link

alkozin commented Apr 19, 2023

Thanx!

@joshnissenbaum
Copy link

Doesn't work with a HEVC unfortunately - audio only, no video

@loopkinng
Copy link

Great for me

@codenoid
Copy link

codenoid commented Mar 5, 2024

I can't imagine developer burden without FFMPEG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment