I am using the following ffmpeg command to inject an rtmp stream to mediasoup.
ffmpeg \
-re \
-v info \
-stream_loop -1 \
-i rtmp://3.126.121.45:1935/live/stream \
-map 0:a:0 \
-acodec libopus -ab 128k -ac 2 -ar 48000 \
-map 0:v:0 \
-c:v libvpx -minrate 2500k -maxrate 2500k -b:v 2500k -r 30 -g 60 -max_delay 0 -bf 0 -deadline realtime -cpu-used 1 \
-f tee \
"[select=a:f=rtp:ssrc=11111111:payload_type=101]rtp://52.29.30.225:41299?rtcpport=40612&pkt_size=1300|[select=v:f=rtp:ssrc=22222222:payload_type=102]rtp://52.29.30.225:44083?rtcpport=48791&pkt_size=1300"
But the video seems to freeze randomly and plays again. Any idea how I can fix this? Tried the solution given here and here with no luck.
Update: Seems like it is the problem of RTP retransmission when some packets are lost. Unfortunately, ffmpeg doesn't fare well with RTP streaming as mentioned here. Meaning ffmpeg doesn't support retransmission mechanism like nack, pli etc. So considering gstreamer instead as suggested in the mediasoup discourse discussion.
Related
Stream a video file or m3u8 file from the internet via udp or rtsp with ffmpeg. I can watch from players like VLC player. As in the examples below. Can I do the same with gstreamer?
Ubuntu: 22.04.1 LTS
gstream: GStreamer 1.20.4
ffmpeg -re -fflags +discardcorrupt -fflags +genpts -i "https://www.blabla.net/tv/tv_360p.m3u8" -max_muxing_queue_size 9999 -fps_mode cfr -c:v copy -b:v 1050k -maxrate 1300K -bufsize 2500K -strict experimental -tune zerolatency -f "rtsp" "rtsp://192.168.1.111:8554/rtsp_stream?pkt_size=1316"
ffmpeg -re -fflags +discardcorrupt -fflags +genpts -i "https://www.blabla.net/tv/tv_360p.m3u8" -max_muxing_queue_size 9999 -fps_mode cfr -c:v copy -b:v 1050k -maxrate 1300K -bufsize 2500K -strict experimental -tune zerolatency -f "mpegts" "udp://225.100.5.1:5000?pkt_size=1316"
ffmpeg -re -fflags +discardcorrupt -fflags +genpts -i "video.mp4" -max_muxing_queue_size 9999 -fps_mode cfr -c:v copy -b:v 1050k -maxrate 1300K -bufsize 2500K -strict experimental -tune zerolatency -f "mpegts" "udp://225.100.5.1:5000?pkt_size=1316"
If you just want to play you can use playbin and play the stream. The bin will take care of demuxing and sending it to your sinks.
Here is an example.
gst-launch-1.0 playbin uri="http://amssamples.streaming.mediaservices.windows.net/634cd01c-6822-4630-8444-8dd6279f94c6/CaminandesLlamaDrama4K.ism/manifest\(format\=m3u8-aapl\)"
Hej!
I'm trying to set up the following:
I have a GoPro Session 5 which streams from udp://10.5.5.9:8554
I have a raspberry pi 3 that is connected to the GoPro's wifi hotspot
I'd like to stream from the GoPro via the rpi over 4g to a Gstreamer viewer (in this case QGroundControl) on another computer with a static ip.
I can get this working by means of this tool:
https://github.com/KonradIT/gopro-py-api
and this command:
ffmpeg -f mpegts -i udp://10.5.5.9:8554 -map 0:0 -c copy -f rtp
udp://94.234.203.109:5000
Now I'd like to see if I can get better performance using Gstreamer.
I'm trying the following:
#!/bin/bash
gst-launch-1.0 -v \
rtpbin name=rtpbin \
udpsrc uri=udp://10.5.5.9:8554 \
! queue \
! avenc_h264_omx bitrate=500000 \
! "video/x-h264,profile=high" \
! h264parse \
! queue max-size-bytes=10000000 \
! rtph264pay pt=96 config-interval=1 \
! rtpbin.send_rtp_sink_0 rtpbin.send_rtp_src_0 \
! udpsink port=5000 host=94.234.203.109 ts-offset=0 name=vrtpsink
rtpbin.send_rtcp_src_0 \
! rtpbin.recv_rtcp_sink_0
And get this error:
Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstUDPSrc:udpsrc0: Could not get/set settings from/on resource.
Additional debug info:
gstudpsrc.c(1548): gst_udpsrc_open (): /GstPipeline:pipeline0/GstUDPSrc:udpsrc0: bind failed: Error binding to address: Cannot assign requested address
Setting pipeline to NULL ...
Freeing pipeline ...
Can someone spare me some knowledge? Thanks!
I use avconv on ubuntu,I found this command
avconv -f alsa -i pulse -f x11grab -r 25 -s 1280x720 -i :0.0+0,0 -acodec libfaac -vcodec libx264 -pre:0 lossless_ultrafast -threads 0 video.mkv
to save as a file, and this command
avconv -i ./test.m4v -re -c copy -f flv "rtmp://localhost/livestream"
to push live stream.
How can I combine them together?
Firstly, you should ask such questions on video.stackexchange.com and not here.
Secondly, let's take apart the two commands that you have found:
-f alsa - format for the input is alsa
-i pulse - you are reading pulse (the pulseaudio driver)
-f x11grab - planning to read from the screen on x11
-r 25 -s 1280x720 - rate and size of the incoming video stream
-i :0.0+0,0 - this selects where the incoming video comes from
-acodec libfaac - here the output options start, you're setting audio code to libfaac, or at least trying to... since this option has been deprecated long time ago, currently -c:a would be used
-vcodec libx264 - setting video code, except that you should be using -c:v
-pre:0 lossless_ultrafast -threads 0 - some sort of parameters about how encoding should be done
video.mkv - this is the output file
And the second one
-i ./test.m4v - the file you're reading
-re - "Read input at native frame rate"
-c copy - do not reencode, but simply pipe as is
-f flv - the container format
"rtmp://localhost/livestream" - where you're planning to write all that.
When you understand that, it should be clear that what you are planning to do is to use the input and encoding part from the first command, and the format and output from the second one.
Here i didn't have time to check that everything that you found is working, you should do that yourself.
I'm trying to save the live feed from an IP camera to a file but the resulting file always plays much faster than the original speed.
I have tried with the following commands:
ffmpeg -i http://171.22.3.47/image -vcodec copy -an -t 900 c:\output.mp4
ffmpeg -i http://171.22.3.47/image -c:v libx264 -an c:\output.mp4
Does anybody know what I'm missing? Both commands create the file and I can use Windows Media Player to play them, but they run much faster.
Try forcing output framerate by adding -r key
ffmpeg -i http://171.22.3.47/image -c:v libx264 -an -r 30 c:\output.mp4
You can also try to slow down the resulting video as an option. This will make output.mp4 2 times slower:
ffmpeg -i output.mp4 -filter:v "setpts=2.0*PTS" -c:v libx264 -an output-slow.mp4
I am trying to get the following screencast command to work:
avconv -f alsa -ar 44100 -ac 2 -i default -acodec aac -strict experimental -ab 320k -f x11grab -s 1024x600 -r 24 -i :0.0 -vcodec rawvideo screencast.mp4
But I still get the following error:
encoder 'aac' is experimental and might produce bad results.
Add '-strict experimental' if you want to use it
Other sites suggest making sure that the -strict experimental appears immediately after the aac parameter, which I have done, to no effect.
Move both the -acodec aac and -strict experimental to somewhere after the last -i parameter in the command line, before the output file name.
Parameters to avconv are parsed as "avconv [input1 options] -i input1 [input2 options] -i input2 [output options] outputfile", so when you added these parameters before the second -i they were interpreted as options to the second input, not to the output.