How can I convert an mp4 video file having inside 3 audio tracks (english, german and french) to an HLS playlist having :
one videofile.m3u8 and its corresponding segmentsfile.ts
one audiofile-english.m3u8 and its corresponding segmentsfile.aac
one audiofile-german.m3u8 and its corresponding segmentsfile.aac
one audiofile-french.m3u8 and its corresponding segmentsfile.aac
one masterfile.m3u8 like that :
#EXTM3U
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="medium",NAME="#1 Fre",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="fre",URI="medium/planete_interdite_500_h264_240p_audio1_fre.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="medium",NAME="#2 Eng",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="eng",URI="medium/planete_interdite_500_h264_240p_audio2_eng.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="medium",NAME="#3 Fre",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="de",URI="medium/planete_interdite_500_h264_240p_audio1_de.m3u8"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=3274000, CODECS="avc1.66.30,mp4a.40.2",RESOLUTION=854x480,AUDIO="medium"
medium/planete_interdite_2080_q264_480p.m3u8
You can use ffmpeg for firstly convert only hls video with flags -an -sn, than converts hls audio streams with flags -vn -sn, and finally make playlist with some scripts
Related
Update:
I have a video player in browser which plays mp4 videos though websocket. The player only supports mp4 file. When i checked normal mp4 fiels does not play in the player, a mp4 file with a "moovflags faststart " will only play on that player. For a allready stored file , this will work properly.
But In case of an livestream(RTSP), using ffmpeg will only work once the RTSP connection has terminated since the "moovflags faststart " flags will work once a connection has terminated properly.
Hope the above statements makes more sense.
Due to this behavior, am checking if there is any way to get the moovflasg at first or something
I am having RTSP live source and i need it to convert the RTSP to a mp4 file which has moov flags in the begining of the file.
I have checked with openrtsp to take a mp4 dump of the rtsp, but it only adds moov flags and other info on the footer of the mp4(onlky when openrtsp has closes the rtsp stream).
Ffmpeg has " -movflags faststart" to move the footer info to the header of the mp4 container.
Since i am having a RTSP live source, the video data will be comming back to back and there wont be any termination. The above ffmpeg command only works once the rtsp stream has terminated.
Is there any way we can make a mp4 container which contains the mp4 footer info present in the header itself so that i can use it for a live source?
EDIT #1
I have video player which plays mp4 video files , it only support playback of a recorded mp4 file which is createtd using "-movflags faststart" , normal mp4 files does not play in that.
This is the player
https://github.com/sonysuqin/WasmVideoPlayer.
Since i am tryng to stream live video to the player, its not possible to use movflags faststart.
The mp4 header can not be added to the file before it is complete. It’s not possible because of how mp4 files are structured. The header needs to know the frame type, timestamp, size, and file offset of every frame in the file. That can’t be known until the file is complete. You can not stream an mp4 while it is being created. You need to use a protocol such as HLS or DASH to accomplish this.
I'm trying to convert DVD iso files to mp4 using HandbrakeCLI. I use the following line in a batch file:
D:\HandBrakeCLI.exe -i "D:\input.iso" -o "D:\output.mp4" --no-markers --width "720" --height "480" --preset "HQ 480p30 Surround" --encoder "mpeg2" --audio-lang-list "eng"
When I do this, I must then extract the audio from the file, using the following line:
D:\eac3to\eac3to.exe "D:\output.mp4" "D:\output.wavs" -down16
However, when I attempt to extract the audio, I get the error message
The format of the source file could not be detected.
Is there anything wrong with my former line of code that's causing the mp4 to get screwed up?
Minor side question: I'm also trying to get handbrake to remove subtitles and also only keep English audio, do you know what code could be used for that? I started a bit there with the --audio-lang-list "eng" but I'm now sure what to do from there.
Thanks a lot in advance!
You need to use a valid audio format. .wavs is not valid. You have to use an available audio codec to output to the below for --aencoder. The default output audio for MP4 is .aac
av_aac
copy:aac
ac3
copy:ac3
eac3
copy:eac3
copy:truehd
copy:dts
copy:dtshd
mp3
copy:mp3
vorbis
flac16
flac24
copy:flac
opus
copy
Defaults for audio
av_mp4 = av_aac
av_mkv = mp3
You need to pass none for no subtitles
-s none
And define only eng track like you were doing
--audio-lang-list eng
Check out the Handbrake CLI Documentation for the command line code:
https://handbrake.fr/docs/en/latest/cli/cli-guide.html
You can also try using a different program once you extract the audio. A program like XMediaRecode. It can also remux audio and video and convert other audio formats to wav
https://www.videohelp.com/software/XMedia-Recode
Here is the input manifest:
$ curl 'https://example.net/ipadlive/index_new.m3u8?sessionid=81893121496608402793&ipaddress=x.x.x.x&callsign=YYYY&hubid=51&zipcode='
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group",NAME="eng",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="en",URI="https://example.net/ipadlive/06_new.m3u8?cdnHost=da148.cdn.iptv.example.net&sessionid=81893121496608402793&ipaddress=x.x.x.x&callsign=CHAN&hubid=51&zipcode=&countycode=null&fta=null&optimumid=null&devicename=&devicetype=0&osver=&res=&fps="
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group",NAME="spa",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="en",URI="https://example.net/ipadlive/07_new.m3u8?cdnHost=da148.cdn.iptv.example.net&sessionid=81893121496608402793&ipaddress=x.x.x.x&callsign=CHAN&hubid=51&zipcode=&countycode=null&fta=null&optimumid=null&devicename=&devicetype=0&osver=&res=&fps="
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=479776,RESOLUTION=240x180,CODECS="avc1.42c00c,mp4a.40.2",AUDIO="group"
https://example.net/ipadlive/01_new.m3u8?cdnHost=da148.cdn.iptv.example.net&sessionid=81893121496608402793&ipaddress=x.x.x.x&callsign=CHAN&hubid=51&zipcode=&countycode=null&fta=null&optimumid=null&devicename=&devicetype=0&osver=&res=&fps=
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=780576,RESOLUTION=320x240,CODECS="avc1.42c00d,mp4a.40.2",AUDIO="group"
https://example.net/ipadlive/02_new.m3u8?cdnHost=da148.cdn.iptv.example.net&sessionid=81893121496608402793&ipaddress=x.x.x.x&callsign=CHAN&hubid=51&zipcode=&countycode=null&fta=null&optimumid=null&devicename=&devicetype=0&osver=&res=&fps=
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1079872,RESOLUTION=480x360,CODECS="avc1.42c01e,mp4a.40.2",AUDIO="group"
https://example.net/ipadlive/03_new.m3u8?cdnHost=da148.cdn.iptv.example.net&sessionid=81893121496608402793&ipaddress=x.x.x.x&callsign=CHAN&hubid=51&zipcode=&countycode=null&fta=null&optimumid=null&devicename=&devicetype=0&osver=&res=&fps=
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1682976,RESOLUTION=640x480,CODECS="avc1.42c01e,mp4a.40.2",AUDIO="group"
https://example.net/ipadlive/04_new.m3u8?cdnHost=da148.cdn.iptv.example.net&sessionid=81893121496608402793&ipaddress=x.x.x.x&callsign=CHAN&hubid=51&zipcode=&countycode=null&fta=null&optimumid=null&devicename=&devicetype=0&osver=&res=&fps=
I've never seen this before where the audio stream is a separate url than a video stream listed in the manifest.
Is there a way I can combine an audio stream and a specific video stream to produce a new stream that has both audio and video in it?
I was doing something like this:
ffmpeg -i <manifest> -c copy test.m3u8 and I don't get any audio.
I've tried changing <manifest> to an individual video stream, but then no audio. If I change it to an AUDIO stream I get no video.
I recently had the problem of combining an audio .ts file with its accompanying video .ts file. I was able to solve it using the following method for Windows users. [see - Video resource ]
1) You will need to download the ffmpeg library that will allow Windows to combine both files together. In my case I was running Windows 8 (32 bit OS) and chose a static build:
2) I then opened notepad and wrote the following code once ffmpeg was installed:
ffmpeg -i VIDEO.ts -i AUDIO.ts -c:v copy -c:a copy OUTPUT.mp4
I saved the notepad file as "joiner.bat"
NB: this bat file must present in the same folder as your separate audio and video ts files in order to combine them!!!
3) Once the bat file is in the same folder as your audio and video ts files you can double click on the joiner.bat file to combine the audio and video ts files into a single mp4 (OUTPUT.mp4) file.
I hope this helps the more novice types among us. Yes I'm still a n00b after many years - don't worry! ;)
i want to try to experiment on jwplayer with video files which have 2 or more audio tracks. Can anyone provide me with a sample video or point to resource to download it?
Thank you in advance!
You can use MP4Box to construct such file as follows:
MP4Box -add file1.mp3 -add file2.mp3 output.mp4
You can use any format that MP4Box supports MP3, AAC, MP4, AVI, ...
I've created a simple example for GPAC's test files, available here.
I have an album stored as a list of gapless m4a files, ripped from CD. I need to stream the album gaplessly over HTTP Live Streaming, and the user must be able to "jump in" at the start of any track. For now, my only client is AVPlayer on iOS.
I can segment the tracks individually using Apple's mediafilesegmenter tool. For each track, this produces one .m3u8 playlist file and several .aac segment files, each ~10 seconds in duration except for the last.
The m3u8 playlist for Track 1 looks like this:
#EXTM3U
#EXT-X-TARGETDURATION:11
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:10.001,
segment0.aac
#EXTINF:9.983,
segment1.aac
...
#EXTINF:3.231,
segment23.aac
#EXT-X-ENDLIST
I can combine these m3u8 playlist files into one master m3u8 file for the album:
#EXTM3U
#EXT-X-TARGETDURATION:11
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:10.001, // begin track 1
segment0.aac
#EXTINF:9.983,
segment1.aac
...
#EXTINF:3.231,
segment23.aac
#EXT-X-DISCONTINUITY
#EXTINF:10.001, // begin track 2
segment24.aac
#EXTINF:9.983,
segment25.aac
...
#EXTINF:6.845,
segment46.aac
#EXT-X-DISCONTINUITY
#EXTINF:10.001, // begin track 3
segment47.aac
#EXTINF:9.983,
segment48.aac
...
#EXTINF:8.012,
segment80.aac
#EXT-X-ENDLIST
It will play through the whole album, but it isn't gapless. Notice the DISCONTINUITY tag between each track (without it, the player hangs forever). This introduces a small gap between tracks, maybe 300 milliseconds.
How can I create segments that flow into each other with no discontinuity?
You can concatenate the AAC files before using the mediafilesegmenter tool on the combined AAC file.
The following ffmpeg command might generate the output file.
ffmpeg -i "concat:input1.aac|input2.aac|input3.aac" -c copy output.aac
It's possible you'll need to remux the aac files to mpeg2ts files before concatenation, and then remux the mpeg2ts file to AAC.