Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] avformat/mxfenc: fix stored/sampled/displayed width/height
@ 2023-01-14 15:48 Jerome Martinez
  2023-01-14 20:04 ` Michael Niedermayer
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Jerome Martinez @ 2023-01-14 15:48 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

Before the patch:
- stored values were rounded to upper 16 multiple also for formats not 
using macroblocks (should be st->codecpar->width and 
st->codecpar->height when not MPEG formats; note that I found no other 
muxer doing the rounding for AVC, only for MPEG-2 Video, but I find no 
reason in specs for doing the difference so I kept the rounding for AVC)
- sampled and displayed widths were stored width (should be 
st->codecpar->width like it is already done for height, with the 
DV50/100 exception)

Could be tested with e.g.
- fixed stored width (1912 instead of 1920) and height (1080 instead of 
1088) not multiple of 16 :
ffmpeg -f lavfi -i testsrc=duration=1:size=1912x1080 -c:v jpeg2000 
test_prores.mxf
- fixed sampled/displayed width (1912 instead of 1920):
ffmpeg -f lavfi -i testsrc=duration=1:size=1912x1080 -c:v mpeg2video 
test_mpeg2video.mxf

[-- Attachment #2: 0001-avformat-mxfenc-fix-stored-sampled-displayed-width-h.patch --]
[-- Type: text/plain, Size: 2925 bytes --]

From cda353059886182aab2e258023c4d027c448344b Mon Sep 17 00:00:00 2001
From: Jerome Martinez <jerome@mediaarea.net>
Date: Sat, 14 Jan 2023 13:32:36 +0100
Subject: [PATCH] avformat/mxfenc: fix stored/sampled/displayed width/height

Stored values are rounded to upper 16 multiple only for MPEG related formats
Sampled and displayed widths are codecpar ones (with DV exception)
---
 libavformat/mxfenc.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 58c551c83c..0b7e83ba4d 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -1109,8 +1109,9 @@ static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID
 {
     MXFStreamContext *sc = st->priv_data;
     AVIOContext *pb = s->pb;
-    int stored_width = 0;
-    int stored_height = (st->codecpar->height+15)/16*16;
+    int stored_width = st->codecpar->width;
+    int stored_height = st->codecpar->height;
+    int display_width;
     int display_height;
     int f1, f2;
     const MXFCodecUL *color_primaries_ul;
@@ -1129,12 +1130,25 @@ static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID
         else if (st->codecpar->height == 720)
             stored_width = 1280;
     }
-    if (!stored_width)
-        stored_width = (st->codecpar->width+15)/16*16;
+    display_width = stored_width;
 
+    switch (st->codecpar->codec_id) {
+    case AV_CODEC_ID_MPEG2VIDEO:
+    case AV_CODEC_ID_DVVIDEO:
+    case AV_CODEC_ID_H264:
+        //Based on 16x16 macroblocks
+        stored_width = (stored_width+15)/16*16;
+        stored_height = (stored_height+15)/16*16;
+        break;
+    default:
+        break;
+    }
+
+    //Stored width
     mxf_write_local_tag(s, 4, 0x3203);
     avio_wb32(pb, stored_width);
 
+    //Stored height
     mxf_write_local_tag(s, 4, 0x3202);
     avio_wb32(pb, stored_height>>sc->interlaced);
 
@@ -1154,7 +1168,7 @@ static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID
 
     //Sampled width
     mxf_write_local_tag(s, 4, 0x3205);
-    avio_wb32(pb, stored_width);
+    avio_wb32(pb, display_width);
 
     //Samples height
     mxf_write_local_tag(s, 4, 0x3204);
@@ -1168,8 +1182,9 @@ static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID
     mxf_write_local_tag(s, 4, 0x3207);
     avio_wb32(pb, 0);
 
+    //Display width
     mxf_write_local_tag(s, 4, 0x3209);
-    avio_wb32(pb, stored_width);
+    avio_wb32(pb, display_width);
 
     if (st->codecpar->height == 608) // PAL + VBI
         display_height = 576;
@@ -1178,6 +1193,7 @@ static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID
     else
         display_height = st->codecpar->height;
 
+    //Display height
     mxf_write_local_tag(s, 4, 0x3208);
     avio_wb32(pb, display_height>>sc->interlaced);
 
-- 
2.13.3.windows.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 16+ messages in thread

end of thread, other threads:[~2023-03-26 19:32 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-14 15:48 [FFmpeg-devel] avformat/mxfenc: fix stored/sampled/displayed width/height Jerome Martinez
2023-01-14 20:04 ` Michael Niedermayer
2023-01-15 14:24   ` Jerome Martinez
2023-01-15 16:55     ` Michael Niedermayer
2023-01-16 13:50 ` Tomas Härdin
2023-01-16 14:28   ` Jerome Martinez
2023-01-18 10:10     ` Tomas Härdin
2023-01-16 14:00 ` Nicolas Gaullier
2023-01-16 15:49   ` Jerome Martinez
2023-01-16 18:15     ` Nicolas Gaullier
2023-03-06 17:09       ` Nicolas Gaullier
2023-03-10 21:10         ` Marton Balint
2023-03-13 22:30           ` Marton Balint
2023-03-13 22:39             ` Pierre-Anthony Lemieux
2023-03-14  9:41           ` Jerome Martinez
2023-03-26 19:32             ` Marton Balint

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