Converting an HLS (m3u8) to MP4 [closed]
Asked Answered
H

2

32

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?

Hara answered 13/10, 2015 at 16:39 Comment(5)
ffmpeg -i in.m3u8 -acodec copy -vcodec copy out.mp4Numberless
@Numberless I think it also needs -bsf:a aac_adtstoascMaryellen
@Maryellen for aac audio yes, for mp3 audio no.Numberless
@Numberless of course, but I think AAC in HLS is pretty commonMaryellen
@Maryellen as is MP3. and DD+Numberless
N
63

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

Numberless answered 13/10, 2015 at 20:12 Comment(1)
Would this command generate an MP4 file with all the alternate audio tracks and side-car VTT captions from the HLS to burn in captions and audio tracks within the MP4?Zita
L
4

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.

Leatherjacket answered 14/7, 2017 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.