Is it possible to stream MJPEG content over MPEG-DASH? - ffmpeg

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)

Related

Streaming RTMP to JANUS-Gateway only showing bitrate but no video

I'm currently using the streaming plugin as follows
Fancy artchitecture here
OBS--------RTMP--------->NGINX-Server------FFMPEG(input RTMP output RTP)--------->JANUS---------webrtc-------->Client
When using the ffmpeg command (bellow), on the Janus streaming interface, we only see the bitrate that corresponds to that of the ffmpeg output in the console but we don't see any video.
ffmpeg -i rtmp://localhost/live/test -an -c:v copy -flags global_header -bsf dump_extra -f rtp rtp://localhost:8004
(using "-c:v copy" so that no encoding is used and hence reducing the
latency)
The video shows fine if I use "-c:v libx264", the only issue is that it is CPU intensive and adds latency.
Previously I had tried using RTSP as input for FFMPEG and in this case the video show fine with almost no latency even though I use "-c:v copy".
So I don't realy get why for RTSP the copy works fine, but for RTMP I have to use the libx264 codec. If anyone has an idea about this I am all ears :)
I had similar issue and my problem was that the stream / video that I used has large GOP size.
For WebRTC, latency is sub-second, so the input source should have short interval I frames. Better to remove B frames since they referring backward and forward as well.
Here are commands that you could use for small GOP size (4) and remove B frames.
Using RTMP streaming src:
ffmpeg rtmp://<your_src> -c:v libx264 -g 4 -bf 0 -f rtp -an rtp://<your_dst>
Using a mp4 file:
ffmpeg -re -i test.mp4 -c:v libx264 -g 4 -bf 0 -f rtp -an rtp://<your_dst>
-c:v copy does not reduce latency. It merely tells ffmpeg not to transcode.

Sending BlackMagic DeckLink Studio 4K over RTMP streams with FFmpeg

I'm trying to send a stream of video that's coming into a BlackMagic DeckLink Studio 4K capture card over a few different RTMP streams at once with FFmpeg. The command that I am doing it with is this:
ffmpeg -re -format_code Hi59 -f decklink -i 'DeckLink Studio 4K' -map 0 -flags +global_header -vcodec libx264 -crf 25 -preset medium -pix_fmt yuv422p -acodec aac -f tee "[f=flv]rtmp://ip1/live/test|[f=flv]rtmp://ip2/live/test.
However, whenever I send this video out, I just get color bars when looking at the stream. I tried using a different video source (the testsrc supplied by FFmpeg), and that sends out fine over RTMP to multiple stream destinations.
Is there something weird with how tee and the decklink stuff work in FFmpeg? Or is there an issue with my command?
If you see colors bars, that means that ffmpeg is connecting to the card and streaming fine but the card is giving the bars. Your command says that ffmpeg is expecting 1920X1080#29.97 interlaced, make sure that is the format into the Decklink. You can also try explicitly setting the connection type, example:
ffmpeg -re -format_code Hi59 -video_input sdi -f decklink -i 'DeckLink Studio 4K' -map 0 -flags +global_header -vcodec libx264 -crf 25 -preset medium -pix_fmt yuv422p -acodec aac -f tee "[f=flv]rtmp://ip1/live/test|[f=flv]rtmp://ip2/live/test
If you are still running into issues, make sure that the BlackMagic software can see the video signal, and it's the format you expect.
One last thing to check, if its an HDMI input make sure it is not HDCP; it's not supported.

Stream RTSP from ONVIF general camera to Youtube

I have a wifi camera that uses RTSP/ONVIF protocol and after reading FFMPEG docs and some threads at Google I am trying to broadcast the stream to Youtube. So I started a broadcast at youtube and in my computer in ffmpeg I executed this command:
ffmpeg -f lavfi -i anullsrc -rtsp_transport udp -i rtsp://200.193.21.176:6002/onvif1 -tune zerolatency -vcodec libx264 -t 12:00:00 -pix_fmt + -c:v copy -c:a aac -strict experimental -f flv rtmp://x.rtmp.youtube.com/live2/private_key
The command above looks like it's correct cause it ouputs constantly something like this:
The problem is that at YOUTUBE it still says I am offline. Why?
Try replace first part to: ffmpeg -re -i somefile.mp4, so you will to know, if here any problems with your camera or not.
ffmpeg and VLC very similar and even uses same code for codecs. But RTSP it handles differently. But try just ffmpeg -i rtsp://200.193.21.176:6002/onvif1 and nothing more as source.

FFmpeg recording audio from several sources

everyone.
I'm trying to use FFmpeg to record video and 3 audio sources and use it to generate 3 different video files - each file should contain the same video stream but the different audio stream. The problem is that I got audio sync issues. The first audio stream is synced perfectly, but the second one has 1 sec lag, and the third one has like 2 sec lag.
I've made a few tests so far and it seems that root cause of the issue is initialization time of video/audio devices. So, one device is already recording something but the second is still being opened and so on. I've tried to change input devices order and after that audio streams still have the same issue BUT if before 2nd and 3rd audio streams were some time ahead of video, after reordering they became to lag after the audio (audio for the same event appears with some delay). So this test confirms my version about device initialization times.
But the question still, why the first audio stream is synchronized properly, while other 2 are not. and also, how could I overcome this issues? Any workarounds and ideas are highly appreciated.
Here is FFmpeg command I'm using and it's output.
ffmpeg.exe -f dshow -video_size 1920x1080 -i video="Logitech HD Webcam
C615" -f dshow -i audio="Microphone (HD Webcam C615)" -f dshow -i
audio="Microphone Array (Realtek High Definition Audio)"
-filter_complex "[1:a]volume=1[a1];[2:a]volume=1[a2]" -vf scale=h=1080:force_original_aspect_ratio=decrease -vcodec libx264
-pix_fmt yuv420p -crf 23 -preset ultrafast -acodec aac -vbr 5 -threads 0 -map v:0 -map [a1] -map [a2] -f tee
"[select=\'v,a:0\']C:/Users/vshevchu/Desktop/123/111/111_jjj1.avi|
[select=\'v,a:1\']C:/Users/vshevchu/Desktop/123/111/111_jjj2.avi"
OUTPUT
PS. Actually, the issue is exactly the same when I'm not using "tee" muxer but writing all the audio streams to one container. So, "tee" isn't a suspect.

Simple RTMP webcam script?

Okay I have a rtmp server is there a simple webcam script which I can use to broadcast a webcam to this server I have tried numerous scripts found online however these don't work. I have also asked questions on these scripts I have found online through this forum however haven't had any luck resolving the issues I had with them. Basically I'm after a script which allows a user to broadcast their webcam to an RTMP server. I can provide a rtmp address to test out the script if you can provide one.
Thankyou for any help
If you have FFMPEG installed on your computer...
Here is a quick Windows guide (VFW capture method) :
http://ffmpeg.gusari.org/viewtopic.php?f=25&t=13
If you get a list (first code) with device availble and then it also makes an MP4 test file (second code) then you are ready.
However they recommend using DShow instead of VFW:
see: https://trac.ffmpeg.org/wiki/DirectShow
If you run ffmpeg -list_devices true -f dshow -i dummy in the command prompt you will get a list of devices. One those listed should say "something camera". example output looks like: [dshow # 03ACF580] "Integrated Camera"
Test that "Integrated Camera" with this command:
ffmpeg -f dshow -i video="Integrated Camera" out.mp4
Use a command like this below to send to RTMP server (you must be logged in there too)
ffmpeg -f dshow -i video="Integrated Camera" -acodec aac -ac 2 -strict experimental -ab
160k -vcodec libx264 -preset slow -profile:v baseline -level 30
-maxrate 10000000 -bufsize 10000000 -b 1000k -f flv rtmp://yourRTMPServer/Type/yourStreamName
replace Type in the link with your stream type (eg: live or VOD or Play or whatever your full RTMP link is written. You did not say so I can only guess its one of these three types).

Resources