I am trying to use ffmpeg to create a live stream from a video file, encoded on the fly, that can be paused and resumed (like what Plex does). Suspending the ffmpeg process pauses the encoding, but resuming it causes ffmpeg to try to catch up to where it would have been in the stream. I assume there is some kind of internal timestamp that ffmpeg is looking at to keep track of timing. I would like ffmpeg to continue encoding from where it left off.
I am using the "-re" switch to read the file at it's native framerate. I have tried hls and dash formats; as far as I can tell, they both behave the same. Segmenting the entire file beforehand is not an option, I would like to be able to stream using only temporary files created on the fly.
Here are simplified commands I've been using.
HLS:
ffmpeg -y -re -i "input.mkv" -movflags +frag_keyframe+empty_moov+faststart -f hls -hls_time 2 -hls_list_size 10 -hls_delete_threshold 1 -hls_flags split_by_time+delete_segments+second_level_segment_index -strftime playlist.m3u8
DASH:
ffmpeg -re -i input.mkv" -f dash -seg_duration 2 -window_size 5 -extra_window_size 0 -remove_at_exit 1 playlist.m3u8
Related
I am trying to re-stream an MJPEG stream over dash using ffmpeg.
I have an ESP32 camera module that outputs an MJPEG livestream at 192.168.2.128:81/stream (Arduino code here).
I can open this stream directly in the browser and see the video in realtime, but the camera will only allow for a single client at a time while I am in need of a multi client solution.
What doesn't work
A solution I am currently trying to implement is to use a seperate server (Raspberry Pi) running apache and ffmpeg to re-stream the MJPEG content using DASH:
ffmpeg -re -i http://192.168.2.128:81/stream -strict -2 -an -c:v copy -b:v 2000k -f dash -window_size 4 -extra_window_size 0 -min_seg_duration 2000000 -remove_at_exit 1 /var/www/html/out.mpd
I get no errors when executing this command on the server.
I then use this ffmpeg-dash.html to display the video in the browser.
This code unfortunately fails, in Firefox the console reports the error:
[72][Stream] No streams to play.
followed by:
Cannot play media. No decoders for requested formats: video/mp4;codecs="mp4v.6c";width="640";height="480"
What does work
What is puzzling me is that the above code works fine if I replace the MJPEG livestream url with a sample .mkv file, so if I use
ffmpeg -re -i /var/www/html/video.mkv -strict -2 -an -c:v copy -b:v 2000k -f dash -window_size 4 -extra_window_size 0 -min_seg_duration 2000000 -remove_at_exit 1 /var/www/html/out.mpd
I can view the livestreamed sample video (video.mkv) without problems using the previously mentioned ffmpeg-dash.html file.
Furthermore, it seems that ffmpeg can read the MJPEG livestream without problems, since
ffmpeg -t 10 -i http://192.168.2.128:81/stream -filter:v fps=15 -c:v flv test.flv
returns a 10 second clip of the livestream succesfully.
So to me it seems that the problem lies in how I combine the two. What am I missing? Is it even possible to stream MJPEG content over MPEG-DASH?
(I am new to this, sorry in advance for my ignorance)
I am rebroadcasting a live mp3 stream (probably it is using icecast - the admin requested me to re-broadcast it on another server). I am using ffmpeg for this task, using HLS playlist, to a public URL location.
It works! But sometimes (I mean once per day, mostly in the night), the m3u8 playlist file disappears or the re-broadcast is not working and I need to kill the ffmpeg process on the server and start it again.
ffmpeg -y -i "THE URL OF LIVE MP3" -f hls -hls_time 10 -hls_list_size 4 playlist.m3u8
I think there could be a problem with the original stream. But even if that happens, I need ffmpeg to "reload" the url of the stream. Is there any method to check and reset ffmpeg automatically?
Thank you so much!
Try to add reconnection flags. If issue is with input it can help:
ffmpeg \
-reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 \
-y -i "THE URL OF LIVE MP3" -f hls -hls_time 10 -hls_list_size 4 playlist.m3u8
I can't find any answer to this scenarios:
Produce a continuous ts file that initially contains silence (or blank video), and as I add files to a text file I wish them to be queued in the output ts stream.
Think of it as a radio or tv station.
I found everything on how to stream anything to anything,
but not a tv/radio broadcast like stream.
A good start seems to be this:
ffmpeg -re -y -nostats -nostdin -hide_banner -loglevel quiet -fflags +genpts -f concat -i list.txt -map 0:a? -map 0:v? -map 0:s? -strict -2 -dn -c copy -hls_flags delete_segments -hls_time 10 -hls_list_size 6 /var/www/html/showname_.m3u8
list.txt example
file '/mnt/vusolo-tv/show/Season 1/S01E01.mp4'
file '/mnt/vusolo-tv/show/Season 1/S01E02.mp4'
But i think there can be better ways...
This is not a good answer either: From multiple video files to single output
because "All files must have streams with identical encoding. Timebase for streams should be the same. Duration of all streams within a file should be the same, in order to maintain sync."
And I want to be able to add arbitrary files and produce a TS stream playable by any TV (once broadcasted in dvb).
I am trying to record rtsp stream in HLS format using openRTSP and ffmpeg. openRTSP receives rtsp and pipe to ffmpeg to record,
Here is the command I used and which works fine
openRTSP -D 10 -v -t -c -b 800000 rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov | .././ffmpeg -r 15 -i - -codec copy -hls_list_size 65535 -hls_time 2 "./live.m3u8"
Note in above commnad -v is for video only.
But now I need to record audio also so I removed -v option, but the video is not getting recorded. It's just creating two files named
audio-MPEG4-GENERIC-1 and video-H264-2 no HLS video file. I think some problem with piping. Can anyone help me to solve it.
I know this is an old question, but it came up in a Google search for me today. Since I can answer this I will, for any future Googlers out there.
You don't need to use openRTSP at all. ffmpeg can handle RTSP streams just fine. I recently coded up a livecam streaming site for my security cameras. The command I'm using to generate the HLS stream is this:
ffmpeg -v quiet -i 'rtsp://user:pass#192.168.1.110:554' -c:v copy -c:a copy \
-bufsize 50k -pix_fmt yuv420p -flags -global_header -hls_time 5 -hls_list_size 3 \
-hls_flags delete_segments hls.m3u8
This will output hls.m3u8 and all of the hls.ts files. You might have to play with some of those parameters for your specific needs. Here is some good documentation for the flags: FFmpeg Formats Documentation
Hello i Have a Live HTTP stream input for ffmpeg
i want to create HLS streaming im using ffmpeg to do this
ffmpeg -i http://127.0.0.1:4242/bysid/7275 -map 0 -codec:v libx264 -codec:a copy -f ssegment -segment_list playlist.m3u8 -segment_list_type hls -segment_list_size 10 -segment_list_flags +live -segment_time 10 out%03d.ts
i works fine i just want to delete the old segmens that are not shown in playlist.m3u8
segment_list_size 10
this will keep the last 10 in the playlist file i want to keep only these files on hard disk
You can use the recently added option to the HLS segmenter:
-hls_flags delete_segments
You will need to change your command to use the HLS segmenter rather than the stream segmenter by using -f hls instead of -f ssegment.
I've been using this option and it doesn't do exactly what you request, but rather it's implemented to be compliant with the HLS spec. See the ffmpeg documentation for more information: https://www.ffmpeg.org/ffmpeg-formats.html
USE
-segment_wrap 10
for wrap and rewrite segment files