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
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 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
I am trying to implement HLS using FFmpeg for transcoding + segmenting but have been facing a couple of issues that have been bugging me for the past week.
Issue
Webserver currently receives live MP4 fragments being recorded on-the-go and needs to take care of transcoding and segmentation.
As mp4 fragments are being received, they need to be encoded. Then segmented. If i run a segmenter (be it ffmpeg or apple mediastreamsegmenter), every mp4 fragment is being treated as a VOD by itself and I'm not being able to integrate them as part of a larger live event implementation.
I thought of a solution where every time I receive an mp4 fragment, I first use fmpeg to concatenate it with previous ones to form the larger mp4 that I then pass to be segmented for HLS. That did not work either because the entire stream has to be re-segmented each and every time and existing TS fragments replaced by new ones that are similar yet shifted in time.
Implementation 1
ffmpeg -re -i fragmentX.mp4 -b:v 118k -b:a 32k -vcodec copy -preset:v veryfast -acodec aac -strict -2 -ac 2 -f mpegts -y fragmentX.ts
I manage the m3u8 manifest on my own, deleting old fragments and appending new ones.
When validating the stream, I find it stacked with EXT-X-DISCONTINUITY tags making the stream unwatchable.
Implementation 2
First combine latest fragment with overall.mp4
ffmpeg -i "concat:newfragment.mp4|existing.mp4" -c copy overall.mp4
Then pass the combination to ffmpeg for HLS segmentation
ffmpeg -re -i overall.mp4 -ac 2 -r 20 -vcodec libx264 -b:v 318k -preset:v veryfast -acodec aac -strict -2 -b:a 32k -hls_time 2 -hls_list_size 3 -hls_allow_cache 0 -hls_base_url /Users/JosephKalash/Desktop/test/350/ -hls_segment_filename '350/fragment%03d.ts' -hls_flags delete_segments 350/index.m3u8
Concatenation is not perfect and there are noticeable glitches where the fragments are supposed to be stitched. Segmentation replaces older fragments and the manifest is rewritten as if it's a new HLS stream every time ffmpeg is called.
I cannot figure out how to get this to work properly.
Any ideas?
Solved by relying on nginx rtmp module which turned out to be suited for the above implementation.
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
I am using FFMPEG to convert uploaded videos to .flv, after conversion the flv video doesn't have information about it's duration. So the user cannot rewind/forward, replay or see a specific part of it. The code is as follows:
"ffmpeg -i $srcfile_path -s 320x240 -ar 44100 -b 2048k -r 12 $desfilepath";
Please help. Thanks in advance.
I ran the following command and it worked.
"ffmpeg -i $srcfile_path -f flv - | flvtool2 -U stdin $desfilepath"
This requires flvtool installed on your system. I am using an FFMPEG and FLVTOOL2 enabled server, so it worked.
That's very strange, I have been using ffmpeg to convert videos from one format to another without any issues. See example below:
ffmpeg -i input.avi -b:a 192K -b:v 2400 -s hd720 -c:v mpeg2video output.mpg
I am sure you know the syntax.