Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: support for interlace format
@ 2022-01-02  0:43 lance.lmwang
  2022-01-02  0:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/rtpenc_rfc4175: " lance.lmwang
  2022-01-09  2:33 ` [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: " lance.lmwang
  0 siblings, 2 replies; 3+ messages in thread
From: lance.lmwang @ 2022-01-02  0:43 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Limin Wang

From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
FYI, other patches have submit to support for the interface format few years ago:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/1531259521-19421-2-git-send-email-patrick.keroulas@savoirfairelinux.com/

I proposal to process the interlace format from packet level.

 libavformat/rtpdec_rfc4175.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
index a66e00d..e0a708e 100644
--- a/libavformat/rtpdec_rfc4175.c
+++ b/libavformat/rtpdec_rfc4175.c
@@ -33,6 +33,8 @@ struct PayloadContext {
     int depth;
     int width;
     int height;
+    int interlaced;
+    int field;
 
     uint8_t *frame;
     unsigned int frame_size;
@@ -104,6 +106,11 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
     stream->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
     data->frame_size = data->width * data->height * data->pgroup / data->xinc;
 
+    if (data->interlaced)
+        stream->codecpar->field_order = AV_FIELD_TT;
+    else
+        stream->codecpar->field_order = AV_FIELD_PROGRESSIVE;
+
     if (data->framerate.den > 0) {
         stream->avg_frame_rate = data->framerate;
         stream->codecpar->bit_rate = data->frame_size * av_q2d(data->framerate) * 8;
@@ -124,6 +131,8 @@ static int rfc4175_parse_fmtp(AVFormatContext *s, AVStream *stream,
         data->sampling = av_strdup(value);
     else if (!strncmp(attr, "depth", 5))
         data->depth = atoi(value);
+    else if (!strncmp(attr, "interlace", 9))
+        data->interlaced = 1;
     else if (!strncmp(attr, "exactframerate", 14)) {
         if (av_parse_video_rate(&data->framerate, value) < 0)
             return AVERROR(EINVAL);
@@ -195,15 +204,18 @@ static int rfc4175_parse_sdp_line(AVFormatContext *s, int st_index,
 static int rfc4175_finalize_packet(PayloadContext *data, AVPacket *pkt,
                                    int stream_index)
 {
-    int ret;
+    int ret = 0;
 
     pkt->stream_index = stream_index;
+    if (!data->interlaced || data->field) {
     ret = av_packet_from_data(pkt, data->frame, data->frame_size);
     if (ret < 0) {
         av_freep(&data->frame);
     }
-
     data->frame = NULL;
+    }
+
+    data->field = 0;
 
     return ret;
 }
@@ -213,7 +225,7 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                                  const uint8_t * buf, int len,
                                  uint16_t seq, int flags)
 {
-    int length, line, offset, cont;
+    int length, line, offset, cont, field;
     const uint8_t *headers = buf + 2; /* skip extended seqnum */
     const uint8_t *payload = buf + 2;
     int payload_len = len - 2;
@@ -266,10 +278,12 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             return AVERROR_INVALIDDATA;
 
         length = (headers[0] << 8) | headers[1];
+        field = (headers[2] & 0x80) >> 7;
         line = ((headers[2] & 0x7f) << 8) | headers[3];
         offset = ((headers[4] & 0x7f) << 8) | headers[5];
         cont = headers[4] & 0x80;
         headers += 6;
+        data->field = field;
 
         if (!data->pgroup || length % data->pgroup)
             return AVERROR_INVALIDDATA;
@@ -277,9 +291,12 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data,
         if (length > payload_len)
             length = payload_len;
 
+        if (data->interlaced)
+            line = 2 * line + field;
+
         /* prevent ill-formed packets to write after buffer's end */
         copy_offset = (line * data->width + offset) * data->pgroup / data->xinc;
-        if (copy_offset + length > data->frame_size)
+        if (copy_offset + length > data->frame_size || !data->frame)
             return AVERROR_INVALIDDATA;
 
         dest = data->frame + copy_offset;
-- 
1.8.3.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avformat/rtpenc_rfc4175: support for interlace format
  2022-01-02  0:43 [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: support for interlace format lance.lmwang
@ 2022-01-02  0:43 ` lance.lmwang
  2022-01-09  2:33 ` [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: " lance.lmwang
  1 sibling, 0 replies; 3+ messages in thread
From: lance.lmwang @ 2022-01-02  0:43 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Limin Wang

From: Limin Wang <lance.lmwang@gmail.com>

Below is step for how to test in your local machine:
wget --no-check-certificate https://samples.ffmpeg.org/MPEG2/interlaced/burosch1.mpg
1. test interlace:
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,http,https,rtp,udp,tcp,tls"  test.sdp

2. test progressive:
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,http,https,rtp,udp,tcp,tls"  test.sdp


Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
If someone have other interface source from hardware, please help to test.

 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 17f5d9d..6be67b5 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 70ea85b..9c8ad14 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 ea4c370..257d072 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 111a25b..ec05d4b 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;
     }
 
-- 
1.8.3.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: support for interlace format
  2022-01-02  0:43 [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: support for interlace format lance.lmwang
  2022-01-02  0:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/rtpenc_rfc4175: " lance.lmwang
@ 2022-01-09  2:33 ` lance.lmwang
  1 sibling, 0 replies; 3+ messages in thread
From: lance.lmwang @ 2022-01-09  2:33 UTC (permalink / raw)
  To: ffmpeg-devel

On Sun, Jan 02, 2022 at 08:43:30AM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> FYI, other patches have submit to support for the interface format few years ago:
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/1531259521-19421-2-git-send-email-patrick.keroulas@savoirfairelinux.com/
> 
> I proposal to process the interlace format from packet level.
> 
>  libavformat/rtpdec_rfc4175.c | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
> index a66e00d..e0a708e 100644
> --- a/libavformat/rtpdec_rfc4175.c
> +++ b/libavformat/rtpdec_rfc4175.c
> @@ -33,6 +33,8 @@ struct PayloadContext {
>      int depth;
>      int width;
>      int height;
> +    int interlaced;
> +    int field;
>  
>      uint8_t *frame;
>      unsigned int frame_size;
> @@ -104,6 +106,11 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
>      stream->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
>      data->frame_size = data->width * data->height * data->pgroup / data->xinc;
>  
> +    if (data->interlaced)
> +        stream->codecpar->field_order = AV_FIELD_TT;
> +    else
> +        stream->codecpar->field_order = AV_FIELD_PROGRESSIVE;
> +
>      if (data->framerate.den > 0) {
>          stream->avg_frame_rate = data->framerate;
>          stream->codecpar->bit_rate = data->frame_size * av_q2d(data->framerate) * 8;
> @@ -124,6 +131,8 @@ static int rfc4175_parse_fmtp(AVFormatContext *s, AVStream *stream,
>          data->sampling = av_strdup(value);
>      else if (!strncmp(attr, "depth", 5))
>          data->depth = atoi(value);
> +    else if (!strncmp(attr, "interlace", 9))
> +        data->interlaced = 1;
>      else if (!strncmp(attr, "exactframerate", 14)) {
>          if (av_parse_video_rate(&data->framerate, value) < 0)
>              return AVERROR(EINVAL);
> @@ -195,15 +204,18 @@ static int rfc4175_parse_sdp_line(AVFormatContext *s, int st_index,
>  static int rfc4175_finalize_packet(PayloadContext *data, AVPacket *pkt,
>                                     int stream_index)
>  {
> -    int ret;
> +    int ret = 0;
>  
>      pkt->stream_index = stream_index;
> +    if (!data->interlaced || data->field) {
>      ret = av_packet_from_data(pkt, data->frame, data->frame_size);
>      if (ret < 0) {
>          av_freep(&data->frame);
>      }
> -
>      data->frame = NULL;
> +    }
> +
> +    data->field = 0;
>  
>      return ret;
>  }
> @@ -213,7 +225,7 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data,
>                                   const uint8_t * buf, int len,
>                                   uint16_t seq, int flags)
>  {
> -    int length, line, offset, cont;
> +    int length, line, offset, cont, field;
>      const uint8_t *headers = buf + 2; /* skip extended seqnum */
>      const uint8_t *payload = buf + 2;
>      int payload_len = len - 2;
> @@ -266,10 +278,12 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data,
>              return AVERROR_INVALIDDATA;
>  
>          length = (headers[0] << 8) | headers[1];
> +        field = (headers[2] & 0x80) >> 7;
>          line = ((headers[2] & 0x7f) << 8) | headers[3];
>          offset = ((headers[4] & 0x7f) << 8) | headers[5];
>          cont = headers[4] & 0x80;
>          headers += 6;
> +        data->field = field;
>  
>          if (!data->pgroup || length % data->pgroup)
>              return AVERROR_INVALIDDATA;
> @@ -277,9 +291,12 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data,
>          if (length > payload_len)
>              length = payload_len;
>  
> +        if (data->interlaced)
> +            line = 2 * line + field;
> +
>          /* prevent ill-formed packets to write after buffer's end */
>          copy_offset = (line * data->width + offset) * data->pgroup / data->xinc;
> -        if (copy_offset + length > data->frame_size)
> +        if (copy_offset + length > data->frame_size || !data->frame)
>              return AVERROR_INVALIDDATA;
>  
>          dest = data->frame + copy_offset;
> -- 
> 1.8.3.1
> 
ping, please help to test if have other sources from hardware. Now only line number from 0 is supported. 

-- 
Thanks,
Limin Wang
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-09  2:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-02  0:43 [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: support for interlace format lance.lmwang
2022-01-02  0:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/rtpenc_rfc4175: " lance.lmwang
2022-01-09  2:33 ` [FFmpeg-devel] [PATCH 1/2] avformat/rtpdec_rfc4175: " lance.lmwang

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git