I am trying to create a hls stream out of an .mp4 file. So far I can create a manifest + .ts files, but I don't have a playlist.m3u8 to deside which manfest I should give the users based on their bandwith. How do I do that?
Here is my current command which creates HLS streams (no playlist):
ffmpeg -i test.mp4 -codec copy -vbsf h264_mp4toannexb -map 0 -f segment -segment_list out.m3u8 -segment_time 10 out%03d.ts
What this creates is out.m3u8:
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10,
out.ts
#EXTINF:10,
out.ts
What I want to create:
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=860000
low.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=512000
medium.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=160000
high.m3u8
To do adaptive streaming with HLS first of all you need to encode your video at the bitrates you want to support. Take a look at Apple's encoding recommendations for some examples.
Once you've done that, you then need to segment each video and generate a playlist for it. The final step is to create a master playlist where you add the URLs of the variant playlists and information about each stream, such as the bandwidth, resolution, and so on - this is the playlist you will use as the video source for the player.
For example, let's assume that your source video was shot in 1080p and you want to generate a 360p variant with a video bitrate of 1200k. You could something like that with the following ffmpeg command:
ffmpeg -i 1080p.mov -c:v libx264 -vprofile baseline -vlevel 3.1 -s 640x360 -b:v 1200k -strict -2 -c:a aac -ar 44100 -ac 2 -b:a 96k 360p.mov
Note that the (source) video you generate the variants from needs to be high quality - you can't encode a 1080p video from a 720p one (without upscaling).
Next, run the command similar to the one in your question to generate the playlist and the segments for this video:
ffmpeg -i 360p.mov -codec copy -vbsf h264_mp4toannexb -map 0 -f segment -segment_time 10 -segment_format mpegts -segment_list 360p/playlist.m3u8 -segment_list_type m3u8 360p/fileSequence%d.ts
Now create a master playlist and add the (relative) URL of the playlist you just created. So something like this:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=1228800,CODECS="mp4a.40.2,avc1.4d401e",RESOLUTION=640x360
360p/playlist.m3u8
(The bandwidth attribute should also take into account the bitrate of the audio, which I haven't done here.)
Repeat the process for the other variants.
The player will use the information about the available streams in the playlist, and the available bandwidth at the time, to determine which stream is the most appropriate to play.
Related
I need to fit audio with video, but sync option is negative (audio is -350 ms) How to fit it with video? I see only examples when audio is +, but not -
ffmpeg -i "sample.mp4" -itsoffset 13.84 -i "sample.mp4" -map 1:v -map 0:a -c copy "movie-video-delayed.mp4"
I use nginx and ffmpeg to restream video from my provider. Previously I use ffmpeg with arguments where I reencoding video and reencoding audio, because my server is to slow I resigned from reencoding.
So now, I use that command :
ffmpeg -re -i http://link.somelink.com:6565/21d12d1/17233 -map 0 -c copy -bsf:a aac_adtstoasc -f flv -flvflags no_duration_filesize rtmp://test_ip/canal/stream
This works only when my provider streaming with aac audio codec, but sometimes my provider change audio codec to ac3. And then this doesn't work. I try something like this :
ffmpeg -thread_queue_size 32768 -re -i http://link.somelink.com:6565/21d12d1/17233 -c:v copy -c:a aac -f flv -flvflags no_duration_filesize rtmp://test_ip/canal/stream
And it all looks like it's all right in console with ffmpeg, but my restreaming video doesn't work. Ngnix throws 304 exception sometime.
Any suggestions?
Please help,
It's very important for me...
Ac3 is not in supported codecs list. You should encode your stream accordingly.
RTMP supports only a limited number of codecs. The most popular RTMP video codecs are H264, Sorenson-H263 (aka flv) and audio codecs AAC, MP3, Nellymoser, Speex. If your video is encoded with these codecs (the most common pair is H264/AAC) then you do not need any conversion. Otherwise you need to convert video to one of supported codecs.
https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp
In almost all the online references related to FFMPEG and RTMP, I am getting -f as flv. Is there any other formats.
(I have tried avi, mpeg and h264, but no success.)
Currently, I am running following command -
ffmpeg -re -i video.mp4 -f s16le -ar 48000 -ac 2 -i audio.wav -c copy -f flv rtmp://192.168.0.1:1935/myapp/stream
The issues with -f flv in my case are -
It doesn't support 48k sample rate.
None of my input videos are in flv format (I have to convert it to flv externally).
P.S. - I am using VLC as RTMP player.
EDIT -
I am getting following error with 48k audio file -
[flv # 0x5650ba7afb80] FLV does not support sample rate 48000, choose from (44100, 22050, 11025)
So, I've read all the articles here and unfortunately I can't seem to find the answers I'm looking for. I've gotten close, but the certain magic strings allude me.
I'm running hls live streaming (nginx) on ubuntu 17.10 server. In short, I can get the server running one video at a time fine with ffmpeg (with subtitles) using the following:
ffmpeg -re -i "1.mkv" -vcodec libx264 -vprofile baseline -g 30 -b:v 1000k -s 852x480 -acodec aac -strict -2 -b:a 192k -ac 2 -vf subtitles=1.srt -f flv rtmp://localhost:1935/show/stream
Though, I cannot find a solution to run a playlist using this method. It seems impossible, and when I try vlc via sout (internally, or externally) I reveive either buffer problems, or the aac experimental codec error:
[aac # 0xb162e900] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.
Example string that spits that error:
vlc "1.mkv" --sout '#transcode{soverlay,vb=1000,vcodec=h264,width=853,height=480,acodec=mp4a,ab=128,channels=2,samplerate=44100}:std{access=rtmp,mux=ffmpeg{mux=flv},dst=rtmp://localhost:1935/show/stream}'
Every other audio codec doesn't work with flv. I'm at a loss, I've tried almost every combination I could think of and digout just to get to this point. The best functioning out of them has been ffmpeg: it doesn't buffer video at all, plays smoothly, but just can't play a playlist. Whereas vlc can play a playlist but buffers, and has no sound (internally). I've tried aenc=ffmpeg{strict=-2}, batch pipes, etc, etc. I need help. Nothing works. Is there any solution? All I want is to run a playlist of 25 videos, all different variations, on a loop to the m3u8 for embedding.
A friend of mine mentioned he used bash scripts to have a seamless playlist like viewing feature. Hopefully that points you in the direction you need. I can try digging them up if you want to work together on this, coz I too am interested in finding out more about it.
I want to take an HLS stream and transcode it to RTMP and simulcast it with the nginx RTMP module.
It's not working, however (I have it placed in the application section of the RTMP module).
exec ffmpeg -i -re http://<HLS>.m3u8 -acodec aac -vcodec libx264 -f flv rtmp://localhost/live/test;
When I try to view my RTMP stream in VLC, it is not loading. I have tried several variations of that ffmpeg directive, none have worked. Any advice? If you need to see more of my config file, I can provide that, but this server has been working previously perfectly when sending video over via a Teradek encoder. This new wrinkle is just not working.
EDIT: Just had a thought. It’d probably help to have the codec information of the incoming HLS stream. Here it is:
Video Codec: H264 - MPEG-4 AVC
Resolution: 640x360
Frame rate: 24
Decoded format: Planar 4:2:0 YUV
Audio Codec: MPEG AAC Audio (mp4a)
Channels: Stereo
Sample rate:48000Hz
If you run in terminal
ffmpeg -i -re http://<HLS>.m3u8 -acodec aac -vcodec libx264 -f flv rtmp://localhost/live/test;
are you able to play the stream in VLC?