How to use ffmpeg to record video from SDP? - ffmpeg

I'm running Ubuntu 18.04 and I have the following SDP Offer from Kurento Media Server. The offer is saved to the file a.sdp :
v=0
o=- 3831476180 3831476180 IN IP4 172.31.46.122
s=Kurento Media Server
c=IN IP4 172.31.46.122
t=0 0
m=audio 28460 RTP/AVPF 96 0 97
a=setup:actpass
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=rtpmap:96 opus/48000/2
a=rtpmap:97 AMR/8000
a=rtcp:28461
a=sendrecv
a=mid:audio0
a=ssrc:1797155263 cname:user1913428254#host-e7ab0454
m=video 18122 RTP/AVPF 102 103
a=setup:actpass
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=rtpmap:102 VP8/90000
a=rtpmap:103 H264/90000
a=fmtp:103 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtcp:18123
a=sendrecv
a=mid:video0
a=rtcp-fb:102 nack
a=rtcp-fb:102 nack pli
a=rtcp-fb:102 goog-remb
a=rtcp-fb:102 ccm fir
a=rtcp-fb:103 nack
a=rtcp-fb:103 nack pli
a=rtcp-fb:103 ccm fir
a=ssrc:2822275190 cname:user1913428254#host-e7ab0454
Then, I'm calling ffmpeg to record this flow to a file :
ffmpeg -max_delay 5000 -reorder_queue_size 16384 -protocol_whitelist file,crypto,udp,rtp -re -i a.sdp -vcodec copy -acodec aac -y output.mp4
172.31.46.122 is the local ip adress and I'm running ffmpeg from the same machine as SDP offer. So ffmpeg has access to this ip adress.
I'm getting the error :
bind failed: Address already in use.
a.sdp: Invalid data found when processing input
Does anyone know how to solve that please ?
Thanks.
Cheers,

Try one of these or both:
ffplay a.sdp -protocol_whitelist "file,udp,rtp"
ffmpeg -i a.sdp -protocol_whitelist "file,udp,rtp" -vcodec copy -acodec aac -y output.mp4
Does it work if you reorder the parameters so that the input file is first?

Related

FFMPEG : Microphone capturing too much noise while using ffmpeg command

I am listening audio from source IP address and trying to encode it into speex format and again sending it to the destination IP address using ffmpeg.
My ffmpeg command is:
ffmpeg -protocol_whitelist file,rtp,udp -i temp.sdp -c:a libspeex -f rtp rtp://<dest_ip>:<port>
SDP file content is(temp.sdp):
v=0
c=IN IP4 <source_IP>
t=0 0
m=audio <port> RTP/AVP 98
a=rtpmap:98 L16/8000
Issue: Whenever I am trying to run this command, I am getting too much background noise on speaker.
I could hear music(not clearly), but not human voice.
Also, I have tried with highpass and lowpass filters are as follows:
ffmpeg -protocol_whitelist file,rtp,udp -i temp.sdp -af "highpass=f=200, lowpass=f=3000" -c:a
libspeex -f rtp rtp://<dest_ip>:<port>

Convert MJPEG RTP stream to MP4 RTP stream with FFMPEG - how?

I'm already searching for a solution for several days how to convert an MJPEG rtp stream to MP4 rtp stream.
Already tried something like this:
ffmpeg -i rtsp://192.168.10.8:554/stream1/mobotix.mjpeg -rtsp_transport tcp -f H264 udp://192.168.10.5:8554
ffmpeg then shows me like it's doing something...
frame= 612 fps= 11 q=25.0 size= 3243kB time=00:00:56.00 bitrate= 474.4kbits/s dup=275 drop=0 speed=0.981x
Then I tried with VLC to open udp://192.168.10.5:8554
but it opens nothing simply the bar is running left/right forever.
Do I need something like Simple RTP-Server (https://github.com/ossrs/srs) and then stream to that?
Best would be, when ffmpeg could host rtp itself...
Here is what I used to stream a local mkv to RTP
ffmpeg -re -thread_queue_size 4 -i input.mkv -strict -2 -vcodec copy -an -f rtp rtp://127.0.0.1:6005 -acodec copy -vn -sdp_file my_sdp_file -f rtp rtp://127.0.0.1:7005
I then had to copy the generated sdp file to the client and used ffmpeg to save the stream to disk
ffmpeg -protocol_whitelist "file,rtp,udp" -i my_sdp_file -strict -2 saved_rtp_stream.mp4
For completeness, here are the contents of the sdp file
$ cat my_sdp_file
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
t=0 0
a=tool:libavformat 57.83.100
m=video 6005 RTP/AVP 96
c=IN IP4 127.0.0.1
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z01AHuiAWh7f+AEAANiAAAH0gABdwHAwABAFgABVc0lGAPFi0SA=,aOvssg==; profile-level-id=4D401E
m=audio 7005 RTP/AVP 97
c=IN IP4 127.0.0.1
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190

RTP streaming with FFmpeg audio and video out of sync

I am streaming a webcam/audio with the command:
ffmpeg.exe -f dshow -framerate 30 -i video="xxx" -c:v libx264 -an -f rtp rtp://localhost:50041 -f dshow -i audio="xxx" -c:a aac -vn -f rtp rtp://localhost:50043
This outputs the following sdp info:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
t=0 0
a=tool:libavformat 57.65.100
m=video 50041 RTP/AVP 96
c=IN IP6 ::1
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1
m=audio 50043 RTP/AVP 97
c=IN IP6 ::1
b=AS:128
a=rtpmap:97 MPEG4-GENERIC/44100/2
a=fmtp:97 profile-level-id=1;mode=AAC-
hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=121056E500
And I read the stream with the command:
ffmpeg.exe -protocol_whitelist file,udp,rtp -i D:\test.sdp -c:v libx264 -c:a aac d:\out.mp4
In the resulting file, the audio is slightly ahead of the video. I have read that RTCP runs on the RTP port + 1, and contains synchronization information. I don't see any RTCP information in the SDP file though.
Do I need to specify something to include RTCP?
If that's not the issue, what else can I do to sync the audio and video?
Not sure if RTCP is your issue, but I would start by trying to use one directshow input and splitting it to two outputs like this:
ffmpeg.exe -f dshow -framerate 30 -i video="XX":audio="YY" -an -vcodec libx264 -f rtp rtp://localhost:50041 -acodec aac -vn -f rtp rtp://localhost:50043
The ffmpeg DirectShow documentation mentions synchronization issues when multiple inputs are used. It also mentions trying the "-copy_ts" flag to resolve sync issues if you want to keep the inputs separate.

streaming webcam via rtp protocol

i am trying to stream and receive my webcam feed on two terminal on same laptop.For this purpose I am using the following commands:-
foo.sdp:
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 55.2.100
m=video 1235 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1
Transmitting:
ffmpeg -re -i /dev/video0 -r 24 -b 50k -s 858x500 -f mulaw -f rtp rtp://127.0.0.1:3000> foo.sdp
Receiving:
ffplay -i foo.sdp
While transmission seems to be working fine , but when i am using receiving command I am getting en error :
Protocol not on whitelist 'file,crypto'!/0
foo.sdp: Invalid data found when processing input
try add
-protocol_whitelist file,udp,rtp
https://www.ffmpeg.org/ffmpeg-protocols.html#Protocol-Options
https://lists.ffmpeg.org/pipermail/ffmpeg-user/2016-February/030853.html

FFmpeg (avconv) rtp stream, how to attach sdp file?

I have a rtp live stream whit h.254 video, I want to copy it to file I use:
avconv -i rtp://#192.168.0.34:60005 -an -acodec copy -vcodec copy abc.mp4
But I have an error:
[rtp # 0x1f6cfe0] Unable to receive RTP payload type 96 without an SDP file describing it
That's ok, because avconv don't know what is inside.
My sdp file:
v=0
o=- 20966096445 1 IN IP4 0.0.0.0
t=0 0
a=type:broadcast
a=control:*
a=x-qt-text-nam:brovotech
a=x-qt-text-inf:live/sub
a=range:npt=0-
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:8
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=4d001e;sprop-parameter-sets=Z00AHpWoLASZ,aO48gA==
How can I attach sdp file for FFmpeg? Or set some arguments that will describe the stream?
Just use avconv -i camera.sdp
camera.sdp:
...
o=- 20966096445 1 IN IP4 my_ip
...
m=video my_port RTP/AVP 96

Resources