Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting an HLS (m3u8) to MP4 [closed]

Can anyone advise on how to construct an MP4 file from an HLS stream (the reverse of what you usually want)? Say I have the m3u8 - is there a straightforward way of getting a single MP4 using FFMPEG or some other tool?

like image 217
orcaman Avatar asked Oct 13 '15 16:10

orcaman


People also ask

Can you convert M3U8 to MP4?

If you failed to open M3U8 files in a player, you can download or convert M3U8 to MP4, which is one of the best video formats compatible with all applications.

How do I open a M3U8 file?

If you're looking for a good program to open and use M3U8 files, try VLC, Apple's iTunes, or Songbird. Another way to open this file format on Linux is with XMMS, while Mac users should be able to use CocoModX (in addition to some of the those Windows-compatible programs).


2 Answers

ffmpeg -i in.m3u8 -acodec copy -vcodec copy out.mp4

For AAC audio you will also need to add the the bit ststream filter. (Thanks @aergistal for pointing that out)

ffmpeg -i in.m3u8 -acodec copy -bsf:a aac_adtstoasc -vcodec copy out.mp4

like image 54
szatmary Avatar answered Sep 22 '22 19:09

szatmary


An alternative way of converting an HLS to MP4 is using VLC Player. You can do the conversion through the interface as well as commandline. Simply you can run a .bat file which has following lines:

chcp 65001 "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" http://cdn.haramain.global/vods3/_definst_/mp4:amazons3/akra/programlar/yeni/335/c07f21e3-a313-4e8d-b594-403ddefbf11f.mp4/playlist.m3u8 --sout "#transcode{vcodec=none,acodec=mp3,ab=70,channels=2,samplerate=44100}:std{access=file{no-overwrite},mux=mp3,dst='C:\Users\aidata\Desktop\Akra FM\13.07.2013 - Karagöz - Bilmecesi.mp3'}" vlc://quit "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" http://cdn.haramain.global/vods3/_definst_/mp4:amazons3/akra/programlar/yeni/335/dcb6754a-49f1-4517-bfe4-3864942f63c8.mp4/playlist.m3u8 --sout "#transcode{vcodec=none,acodec=mp3,ab=70,channels=2,samplerate=44100}:std{access=file{no-overwrite},mux=mp3,dst='C:\Users\aidata\Desktop\Akra FM\12.07.2013 - Nasreddin Hoca - Köyün Eseği.mp3'}" vlc://quit 

This batch script converts two files one after another. If you had pasted these commands into cmd.exe, all conversions would start at the same time.


Now let me explain the codes. The chcp 65001 line allows you to use unicode characters in the destination file name. Following lines consist of four parts.

  1. "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"

This is the path of the VLC player. Verify this after installing VLC player.

  1. http://cdn.haramain.global/vods3/_definst_/mp4:amazons3/akra/programlar/yeni/335/c07f21e3-a313-4e8d-b594-403ddefbf11f.mp4/playlist.m3u8

This is a sample HLS file. I don't know what happens if you put this link in double quotes.

  1. --sout "#transcode{vcodec=none,acodec=mp3,ab=70,channels=2,samplerate=44100}:std{access=file{no-overwrite},mux=mp3,dst='C:\Users\aidata\Desktop\Akra FM\13.07.2013 - Karagöz - Bilmecesi.mp3'}"

This is the VLC command for conversion. You can find more options in VLC Documentation

  1. vlc://quit

This will close the VLC window. It is helpful if you don't want your taskbar to be filled with VLC windows. There is no way to stack conversion orders in playlist. You have to run VLC, do the conversion and close the window. You can also try running VLC in silent mode. Or you can drag a VLC window to right bottom of your screen so that subsquent flashing windows won't disturb you.

like image 34
sevenkul Avatar answered Sep 25 '22 19:09

sevenkul