[FFmpeg-cvslog] avformat/rtpenc_rfc4175: support for interlace format

Limin Wang git at videolan.org
Wed Jan 12 03:27:43 EET 2022


ffmpeg | branch: master | Limin Wang <lance.lmwang at gmail.com> | Sat Jan  1 20:19:50 2022 +0800| [b697326a68372bec6dc3adece9afaaaebae5028d] | committer: Limin Wang

avformat/rtpenc_rfc4175: support for interlace format

Below are steps how to test on your local host:
wget --no-check-certificate https://samples.ffmpeg.org/MPEG2/interlaced/burosch1.mpg

1. interlace format:
ffmpeg  -re -i ./burosch1.mpg  -c:v bitpacked  -pix_fmt yuv422p10  -f rtp  rtp://239.255.0.1:6000
copy and create sdp file test.sdp
ffplay -buffer_size 671088640 -protocol_whitelist "file,rtp,udp"  test.sdp

2. progressive format:
ffmpeg  -re -i ./burosch1.mpg  -vf yadif -c:v bitpacked  -pix_fmt yuv422p10  -f rtp  rtp://239.255.0.1:6000
copy and create sdp file test.sdp
ffplay -buffer_size 671088640 -protocol_whitelist "file,rtp,udp"  test.sdp

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b697326a68372bec6dc3adece9afaaaebae5028d
---

 libavformat/rtpenc.c         |  9 +++++++--
 libavformat/rtpenc.h         |  2 +-
 libavformat/rtpenc_rfc4175.c | 31 +++++++++++++++++++++----------
 libavformat/sdp.c            |  5 ++++-
 4 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 17f5d9d308..6be67b5885 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -622,9 +622,14 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
         ff_rtp_send_jpeg(s1, pkt->data, size);
         break;
     case AV_CODEC_ID_BITPACKED:
-    case AV_CODEC_ID_RAWVIDEO:
-        ff_rtp_send_raw_rfc4175 (s1, pkt->data, size);
+    case AV_CODEC_ID_RAWVIDEO: {
+        int interlaced = st->codecpar->field_order != AV_FIELD_PROGRESSIVE;
+
+        ff_rtp_send_raw_rfc4175(s1, pkt->data, size, interlaced, 0);
+        if (interlaced)
+            ff_rtp_send_raw_rfc4175(s1, pkt->data, size, interlaced, 1);
         break;
+        }
     case AV_CODEC_ID_OPUS:
         if (size > s->max_payload_size) {
             av_log(s1, AV_LOG_ERROR,
diff --git a/libavformat/rtpenc.h b/libavformat/rtpenc.h
index 70ea85bf3f..9c8ad14a53 100644
--- a/libavformat/rtpenc.h
+++ b/libavformat/rtpenc.h
@@ -95,7 +95,7 @@ void ff_rtp_send_vc2hq(AVFormatContext *s1, const uint8_t *buf, int size, int in
 void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size);
 void ff_rtp_send_vp9(AVFormatContext *s1, const uint8_t *buff, int size);
 void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size);
-void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size);
+void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size, int interlaced, int field);
 
 const uint8_t *ff_h263_find_resync_marker_reverse(const uint8_t *av_restrict start,
                                                   const uint8_t *av_restrict end);
diff --git a/libavformat/rtpenc_rfc4175.c b/libavformat/rtpenc_rfc4175.c
index ea4c3705f3..257d072cd3 100644
--- a/libavformat/rtpenc_rfc4175.c
+++ b/libavformat/rtpenc_rfc4175.c
@@ -21,36 +21,40 @@
 #include "avformat.h"
 #include "rtpenc.h"
 
-void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size)
+void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size, int interlaced, int field)
 {
     RTPMuxContext *s = s1->priv_data;
     int width = s1->streams[0]->codecpar->width;
     int height = s1->streams[0]->codecpar->height;
     int xinc, yinc, pgroup;
-    int field = 0;
     int i = 0;
     int offset = 0;
 
     s->timestamp = s->cur_timestamp;
     switch (s1->streams[0]->codecpar->format) {
         case AV_PIX_FMT_UYVY422:
-            xinc = yinc = 2;
+            xinc = 2;
+            yinc = 1 << interlaced;
             pgroup = 4;
             break;
         case AV_PIX_FMT_YUV422P10:
-            xinc = yinc = 2;
+            xinc = 2;
+            yinc = 1 << interlaced;
             pgroup = 5;
             break;
         case AV_PIX_FMT_YUV420P:
-            xinc = yinc = 4;
+            xinc = 4;
+            yinc = 1 << interlaced;
             pgroup = 6;
             break;
         case AV_PIX_FMT_RGB24:
-            xinc = yinc = 1;
+            xinc = 1;
+            yinc = 1 << interlaced;
             pgroup = 3;
             break;
         case AV_PIX_FMT_BGR24:
-            xinc = yinc = 1;
+            xinc = 1;
+            yinc = 1 << interlaced;
             pgroup = 3;
             break;
         default:
@@ -72,7 +76,9 @@ void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size)
 
         headers = dest;
         do {
-            pixels = width * xinc - offset;
+            int l_line;
+
+            pixels = width - offset;
             length = (pixels * pgroup) / xinc;
 
             left -= head_size;
@@ -90,8 +96,9 @@ void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size)
             *dest++ = length & 0xff;
 
             /* Line No */
-            *dest++ = ((i >> 8) & 0x7f) | ((field << 7) & 0x80);
-            *dest++ = i & 0xff;
+            l_line = i >> interlaced;
+            *dest++ = ((l_line >> 8) & 0x7f) | ((field << 7) & 0x80);
+            *dest++ = l_line & 0xff;
             if (next_line) i += yinc;
 
             cont = (left > (head_size + pgroup) && i < height) ? 0x80 : 0x00;
@@ -106,16 +113,20 @@ void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size)
         } while (cont);
 
         do {
+            int l_field;
             int l_line;
             int l_off;
             int copy_offset;
 
             length    = (headers[0] << 8) | headers[1];
+            l_field   = (headers[2] & 0x80) >> 7;
             l_line    = ((headers[2] & 0x7f) << 8) | headers[3];
             l_off     = ((headers[4] & 0x7f) << 8) | headers[5];
             cont      = headers[4] & 0x80;
             headers  += head_size;
 
+            if (interlaced)
+                l_line = 2 * l_line + l_field;
             copy_offset = (l_line * width + l_off) * pgroup / xinc;
             if (copy_offset + length > size)
                 break;
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index 2230d74742..d63a0b34c4 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -728,9 +728,12 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
         av_strlcatf(buff, size, "a=rtpmap:%d raw/90000\r\n"
                                 "a=fmtp:%d sampling=%s; "
                                 "width=%d; height=%d; "
-                                "depth=%d\r\n",
+                                "depth=%d",
                                 payload_type, payload_type,
                                 pix_fmt, p->width, p->height, bit_depth);
+        if (p->field_order != AV_FIELD_PROGRESSIVE)
+            av_strlcatf(buff, size, "; interlace");
+        av_strlcatf(buff, size, "\r\n");
         break;
     }
 



More information about the ffmpeg-cvslog mailing list