FFMPEG skipping x segments ahead, expired from playlists - ffmpeg

I'm trying to re-stream an M3U8 stream to an rtmp server but I'm often seeing this:
Skipping 1 segments ahead, expired from playlists
This causes the output stream playback to pause and lag after a while.
I'm using the following ffmpeg command:
ffmpeg -stream_loop -1 -thread_queue_size 8192 -i http://demo.m3u8 -c:a aac -c:v h264 -ar 44100 -vf scale=640:-1 -hide_banner -bf 0 -pix_fmt yuv420p -vprofile baseline -preset superfast -segment_list_flags live -segment_list_size 300 -segment_time 300 -hls_list_size 300 -hls_time 300 -flvflags no_duration_filesize -f flv rtmp://myserver
Is there a way to prevent this issue to ensure a smooth playback?

Related

How to reduce audio delay in FFmpeg using HTTP FLV stream?

I have problem with live http flv stream. I'm using the following command and it works great except for the audio. Audio has delay that increasing over time. I can fix the this by removing refresh rate option on the output (-r 30) but then stream latency goes higher for about half second.
ffmpeg -f v4l2 -threads 0 -video_size 672X420 -i /dev/video1 -f alsa -thread_queue_size 512 -i hw:1,0 -c:a aac -ar 44100 -b:a 128k -c:v libx264 -s 672x420 -r 30 -g 60 -preset superfast -tune zerolatency -strict -2 -f flv rtmp://localhost/live/primary
Can someone explain why this happening and what possible fixes are?
On the client I'm using Chrome with flv.js library.
On the server Node-Media-Server.

Synchronization and concurrency for creating hls resolutions for Live Streaming

Is there a single command to transcode mp4 video + aac into HLS at multiple resolutions ?
I have a convert server, and I think to live stream multiple resolutions, I must create all resolutions at the same time and this process must be concurrent.
I raised this issue,because I do this process wtih running these below codes at 4 cmd seperately for creating 4 resolutions of a video examply at the same time:
1- 720p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s hd720 -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 720p/out.m3u8
2- 480p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s hd480 -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 480p/out.m3u8
3- 360p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s nhd -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 360p/out.m3u8
4- 200p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s cga -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 200p/out.m3u8
but doing in this way have some problems.
1- the .TS parts of each resolutions doesn't create with another resolutions part at the same time(this issue makes that in switching resolutions, player cannot seek to the continue of selected resolution,because that part doesn't create yet).
2- You have run some threads for each live streaming.
Here is the answer of mine,Note that you must be set -hls_time If you want the number part of each resolutions be same.
ffmpeg -re -i 123.mp4
-c:a aac -c:v libx264 -s hd480 -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 480p/out.m3u8
-c:a aac -c:v libx264 -s nhd -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 360p/out.m3u8
-c:a aac -c:v libx264 -s cga -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 200p/out.m3u8

Creating a simulated HLS live stream from multiple MP4 sources with ffmpeg

I've already tried to create HLS stream from a UDP continuous input stream, it was fairly easy, now I want to create a simulated live HLS stream from multiple MP4 sources with ffmpeg, the idea behind it is to be able to create a TV channel with non-live data, so the input must be a loop of non-live data to simulate live stream continuity. I tried to do it with the below command but after the first round, ffmpeg exits with this error:
concat:1.mp4|2.mp4|3.mp4" Resource temporarily unavailable.
ffmpeg command:
ffmpeg -i "concat:1.mp4|2.mp4|3.mp4" -strict experimental -sn -ac 2 -map_metadata -1 -s 720x576 -g 250 -c:v libx264 -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 5 -hls_wrap 12 -hls_flags delete_segments -f hls -strftime 1 -segment_time 10 -segment_format mpegts -segment_list_flags +live -hls_allow_cache 0 -segment_wrap 12 -segment_list_size 5 -hls_base_url http://192.168.1.100/0/ -hls_segment_filename /data/0/live_0_%02d.ts /data/0/live_0.m3u8
If anyone has a nice solution to this issue, I would appreciate any input.
Cheers,
Navid

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.

How to record UDP stream with FFMPEG in chunks?

I'm looking for a way to record a video UDP stream using ffmpeg but in 10mn chunks.
I currently use the following to get 10mn of video (with h264 transcoding).
"ffmpeg -i udp://239.0.77.15:5000 -map 0:0 -map 0:1 -s 640x360 -vcodec libx264 -g 100 -vb 500000 -r 25 -strict experimental -vf yadif -acodec aac -ab 96000 -ac 2 -t 600 -y /media/test.m4 "
My problem is that using command line ffmpeg needs time to resync with the udp stream loosing 2 seconds of video each time. Is it normal ?
Any idea if there is a way to do it in command line or should I tried to use the ffmpeg API ?
Thanks in advance
Ok found it.
Recently ffmpeg add a segmenter, here is the syntax:
-f segment: tell ffmpeg to use the segmenter
-segment_time: chunk size in second
You can use autoincrement file name with something like %03d (000,001,002,003...).
Here is my line to transcode a UDP MPEGTS stream, into H264+AAC and save it to file chunk (60 seconds):
ffmpeg -i udp://239.0.77.15:5000 -map 0:0 -map 0:1 -s 640x360 -vcodec libx264 -g 60 -vb 500000 -strict experimental -vf yadif -acodec aac -ab 96000 -ac 2 -y -f segment -segment_time 60 "xxx-%03d.ts"
This is a better way:
ffmpeg -re -i udp://10.1.1.238:1234?fifo_size=1000000 -vcodec libx264 -vb 500000 -g 60 -vprofile main -acodec aac -ab 128000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -b 1000k -minrate 1000k -maxrate 1000k -strict experimental -f stream_segment -segment_format mpegts -segment_time 5 -segment_atclocktime 1 -reset_timestamps 1 -strftime 1 d:/%H%M%S.mp4
By this code ffmpeg makes series of output files using current system time.

Resources