[FFmpeg-devel] [PATCH v2 2/3] avformat/rtsp: add satip_raw flag to receive raw mpegts stream
Aman Karmani
ffmpeg at tmm1.net
Wed Dec 23 00:47:46 EET 2020
From: Aman Karmani <aman at tmm1.net>
This can be used to receive the raw mpegts stream from a SAT>IP
server, by letting avformat handle the RTSP/RTP/UDP negotiation
and setup, but then simply passing the MP2T stream through
instead of demuxing it further.
For example, this command would demux/remux the mpegts stream:
SATIP_URL='satip://192.168.1.99:554/?src=1&freq=12188&pol=h&ro=0.35&msys=dvbs&mtype=qpsk&plts=off&sr=27500&fec=34&pids=0,17,18,167,136,47,71'
ffmpeg -i $SATIP_URL -map 0 -c copy -f mpegts -y remux.ts
Whereas this command will simply write out the raw stream, with
the original PAT/PMT/PIDs intact:
ffmpeg -rtsp_flags satip_raw -i $SATIP_URL -map 0 -c copy -f data -y raw.ts
Signed-off-by: Aman Karmani <aman at tmm1.net>
---
libavformat/rtsp.c | 17 ++++++++++++++---
libavformat/rtsp.h | 1 +
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index ba21b50b76..450ad3a4b8 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -89,6 +89,7 @@ const AVOption ff_rtsp_options[] = {
RTSP_FLAG_OPTS("rtsp_flags", "set RTSP flags"),
{ "listen", "wait for incoming connections", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_LISTEN}, 0, 0, DEC, "rtsp_flags" },
{ "prefer_tcp", "try RTP via TCP first, if available", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_PREFER_TCP}, 0, 0, DEC|ENC, "rtsp_flags" },
+ { "satip_raw", "export raw MPEG-TS stream instead of demuxing", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_SATIP_RAW}, 0, 0, DEC, "rtsp_flags" },
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
{ "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
{ "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
@@ -265,9 +266,19 @@ static int init_satip_stream(AVFormatContext *s)
av_strlcpy(rtsp_st->control_url,
rt->control_uri, sizeof(rtsp_st->control_url));
- rtsp_st->stream_index = -1;
- init_rtp_handler(&ff_mpegts_dynamic_handler, rtsp_st, NULL);
- finalize_rtp_handler_init(s, rtsp_st, NULL);
+ if (rt->rtsp_flags & RTSP_FLAG_SATIP_RAW) {
+ AVStream *st = avformat_new_stream(s, NULL);
+ if (!st)
+ return AVERROR(ENOMEM);
+ st->id = rt->nb_rtsp_streams - 1;
+ rtsp_st->stream_index = st->index;
+ st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+ st->codecpar->codec_id = AV_CODEC_ID_MPEG2TS;
+ } else {
+ rtsp_st->stream_index = -1;
+ init_rtp_handler(&ff_mpegts_dynamic_handler, rtsp_st, NULL);
+ finalize_rtp_handler_init(s, rtsp_st, NULL);
+ }
return 0;
}
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 239ea8a0eb..1310dd9c08 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -429,6 +429,7 @@ typedef struct RTSPState {
#define RTSP_FLAG_RTCP_TO_SOURCE 0x8 /**< Send RTCP packets to the source
address of received packets. */
#define RTSP_FLAG_PREFER_TCP 0x10 /**< Try RTP via TCP first if possible. */
+#define RTSP_FLAG_SATIP_RAW 0x20 /**< Export SAT>IP stream as raw MPEG-TS */
typedef struct RTSPSource {
char addr[128]; /**< Source-specific multicast include source IP address (from SDP content) */
--
2.29.2
More information about the ffmpeg-devel
mailing list