-1

By using ffmpeg or ffplay you may specify "-rtsp_transport tcp" switch to force the rtsp stream be opened via tcp. In programming, I'm using libav to open the rtsp stream with the following code:

AVDictionary *options = NULL;
av_dict_set(&options, "rtsp_transport", "tcp", 0);
int status = avformat_open_input(&mFormatContext, path.c_str(), inputFormat, &options);

and I expect the same behavior. But the url 'path' is opened via udp. I may figure this out this way:

I create an SDP file with libav and write the received packets to it. Then I use ffplay to process and play the sdp file. I get errors like:

RTP: missed 1 packets

error while decoding MB 75 38, bytestream -48

If the rtsp stream has been opened via TCP, I should not miss any packets, and the second type of error, I think, is caused by losing packets too. So, it seems that the rtsp_transport option is not working.

Any idea?

Update

I found that av_dict_set works as expected, but the SDP file is made incorrectly (maybe). Its content is like:

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 226.1.1.15/0
t=0 0
a=tool:libavformat 56.40.101
m=video 43908 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z00AKpY1QPAET8s3AQEBAgA=,aO48gAA=; profile-level-id=4D002A

I researched about it and found that the line beginning with 'm' should contain TCP instead of RTP/AVP, although all of this is my guess. The ffplay is reading the sdp file in the same system, so no socket or network connection exists between ffplay and the sdp file. So my guess may be incorrect. What do you think about the sdp file? May it be incorrect? I make it by av_sdp_create function and don't change it. I write it directly to the file.

hamidi
  • 1,611
  • 1
  • 15
  • 28
  • in the RTSP exchange, SETUP should specify transport of unicast and specify the port ranges. e.g. google around for strings like "Transport: RTP/AVP/TCP;unicast;interleaved=0-1;mode=RECORD" (note setup is the step after ANNOUNCE/DESCRIBE - i.e. the step the follows definition of the SDP) – gfunk Aug 24 '23 at 14:31
  • hmm, could you give me a sample code? I couldn't figure out how. – hamidi Aug 25 '23 at 19:11
  • These work: `ffplay -rtsp_transport tcp -i rtsp://127.0.0.1:8554/test` or `gst-launch-1.0 rtspsrc location=rtspt://127.0.0.1:8554/test protocols=tcp ! rtph264depay ! queue ! avdec_h264 ! videoconvert ! autovideosink`. SDP is not your problem. Heres RTSP SETUP: `RTSP request method: 'SETUP' uri: 'rtsp://127.0.0.1:8554/test/stream=0' version: '1.0' headers: Transport: 'RTP/AVP/TCP;unicast;interleaved=0-1' RTSP response status line: code: '200' reason: 'OK' headers: CSeq: '3' Transport: 'RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=BA5FE478;mode="PLAY"' ...` – gfunk Aug 28 '23 at 15:06
  • I would use a legitimate RTSP server - might be easier than trying to mimic network with a file, especially since timing/packet cadence often affects processing of 'live stream' – gfunk Aug 28 '23 at 15:09

0 Answers0