Mp4 to dynamic adaptive hls with multiple bitrates using ffmpeg - ffmpeg

I tried converting mp4 video to HLS for online streaming which I have successfully done using FFmpeg.
Command:
ffmpeg -i /var/www/html/file_conversion/heli.mp4 -map 0 -profile:v baseline -level 3.0 -s 640x360 -c:v libx264 -b:v 500k -c:a libfdk_aac -b:a 320k -hls_list_size 0 -start_number 0 -hls_init_time 0 -hls_time 2 -f hls /var/www/html/file_conversion/hlstest2/heli.m3u8
But now I am trying to convert the same video with multiple bitrates for dynamic adaptive streaming.
Any idea how can I achieve this?

I was having the same doubt, and found this article:
https://dev.to/nodir_dev/transcode-video-source-to-hls-playlist-format-for-video-on-demand-vod-streaming-3h99
After making transcoding files, just create a *.m3u8 file, with the following content:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=375000,RESOLUTION=640x360
360_out.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=750000,RESOLUTION=854x480
480_out.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2000000,RESOLUTION=1280x720
720_out.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=3500000,RESOLUTION=1920x1080
1080_out.m3u8
now just send this file to the streams.
My HLS folder:
image_folder
content_of_master_file
I made the transcoding two resolutions: 1280x720 and 640x480
- Author of the article: Nodirbek Sharipov

Related

Video size streaming to YouTube with FFMPEG on Raspberry Pi 4

I'm using FFMPEG to stream video to YouTube with my Raspberry Pi 4. It used to work well, but just recently YouTube has started displaying the video smaller than it should be with a black surround as pictured.
preview in YouTube studio
The command I am using is:
ffmpeg -re -i $path -r 24 -g 48 -pix_fmt yuv420p -x264-params kiyint=48:min-keyint=48:scenecut=-1 -video_size 1280x720 -b:v 2000k -b:a 128k -ar 44100 -acodec aac -vcodec h264_v4l2m2m -preset superfast -bufsize 960k -crf 28 -threads 4 -f flv rtmp://a.rtmp.youtube.com/live2/$key
I thought -video_size 1280x720 should set the resolution that FFMPEG is outputting, but it's still displaying as in the picture. The videos themselves are 720p.
I can't work out how to get YouTube and FFMPEG to understand the resolution of the video from one another and have it fill the frame.

Creating live hls playlist with FFmpeg using chunk size mp4 files

I have a program coded in python that will downloads and output h264 video and audio files every 6 seconds.
Each h264 video audio is a 10 second segment.
so basically, every 6 seconds new video.h264 and auio.h264 file replaces with video.h264 and auio.h264 file
My goal here is to create a hls playlist with these downloaded h264 files
I am using ffmpeg to transcode these h264 files and convert them into hls playlist but there is a problem here.
The playlist stops once after the first h264 video finishes. m3u8 is not fetching the next .ts which is created by ffmpeg. How do i make the hls playlist keeps on playing the .ts files and works like a live streaming ?
ffmpeg -i video.h264 -i audio.h264 -loglevel info -c:v libx264 -c:a aac -ac 1 -strict -2 -r 25 -crf 23 -profile:v baseline -preset:v ultrafast -maxrate 2048k -bufsize 2048k -pix_fmt yuv420p -s 720x576 -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 test.m3u8

ffmpeg forward hls stream

I am trying to forward HLS stream to server via RTSP. On the server, it will be transcoded to the multiple bitrate streams so a wide range of users can watch stream.
To achieve this, I am using ffmpeg.
Should I stream to my server in best quality because my server will do transcoding to lower bitrate streams?
I am using this command:
ffmpeg -i http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch1/appleman.m3u8 -c:v libx264 -preset veryfast -maxrate 2000k -bufsize 2000k -g 60 -c:a aac -b:a 96k -ac 2 -ar 44100 -f rtsp -muxdelay 0.1 rtsp://username:password#95.138.139.123:1935/live/myStream
But my stream is pixelated on some moments like on the picture:
How can I fix that?
Is there some better method to achieve this?
Here is log file from ffmpeg.
Log file

Audio is lost in some portions of a HLS stream

I have setup a HLS live stream on AWS. Significant part of the video plays as expected but in some portions audio is lost while the video continues to play. Please share you thoughts/insights if you have faced such an issue.
I transcode video to h264, baseline3.1 and audio to aac stereo 2 channels before segmenting to 10s files. Following commands are being used:
Transcoding:
ffmpeg -y -i ${file_path} -b:v ${vBitrate} -minrate ${vBitrate} -maxrate ${vBitrate} -c:v libx264 -b:a ${aBitrate} -c:a libfaac -ac 2 -r 25 -s ${resolution} -profile:v baseline -level 3.1 ${output_dir}/${file_name}.ts
Ex: vBitrate: 1m, aBirate: 128k, resolution: 960x540
Splittting:
ffmpeg -i ${file_path} -c:v copy -c:a copy -flags -global_header -map 0 -f segment -segment_time ${segment} -segment_list ${output_dir}/playlist.m3u8 -segment_format mpegts tmp0/${file_name}_%02d.ts
Ex: segment: 10
Setup: segments are being served from Nginx and playlist is managed by a Python/Flask app.

Getting the original video quality while converting in ffmpeg

In my site, having upload video(only mp4 videos) functionality and then to combine. For the combining i used Mp4Box, If we want combine all the mp4 video, those videos have to same dimesions,bitrate,codecs,samplerate,etc, So while uploading the mp4 videos itself we set the constant dimension and other details like
ffmpeg -i test.mp4 -r 25 -s 640x360 -ar 48000 -acodec copy -f mp4 -vcodec libx264 -vpre default -async 1 -strict -2 -qscale 10 test.mp4
After using this command the video quality will loss fro the original video, Kindly suggest any solution?
Add
-qp 0
ยง Lossless H.264

Resources