From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: export cropping values from clap boxes Date: Mon, 8 Jul 2024 22:55:19 -0300 Message-ID: <20240709015521.10083-1-jamrial@gmail.com> (raw) Addresses part of ticket #7437. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/mov.c | 78 +++++++++++++++++++++++++ tests/ref/fate/aic | 32 +++++----- tests/ref/fate/prores-transparency | 4 +- tests/ref/fate/prores-transparency_skip | 4 +- 4 files changed, 98 insertions(+), 20 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index d862434d25..0e290617ed 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1208,6 +1208,83 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) return ret; } +static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + AVPacketSideData *sd; + AVRational aperture_width, aperture_height, horiz_off, vert_off; + AVRational pc_x, pc_y; + int top, bottom, left, right; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + aperture_width.num = avio_rb32(pb); + aperture_width.den = avio_rb32(pb); + aperture_height.num = avio_rb32(pb); + aperture_height.den = avio_rb32(pb); + + horiz_off.num = avio_rb32(pb); + horiz_off.den = avio_rb32(pb); + vert_off.num = avio_rb32(pb); + vert_off.den = avio_rb32(pb); + + if (aperture_width.num < 0 || aperture_width.den < 0 || + aperture_height.num < 0 || aperture_height.den < 0 || + horiz_off.den < 0 || vert_off.den < 0 || + av_q2d(aperture_width) > st->codecpar->width || + av_q2d(aperture_height) > st->codecpar->height) + return AVERROR_INVALIDDATA; + + av_log(c->fc, AV_LOG_TRACE, "clap: apertureWidth %d/%d, apertureHeight %d/%d " + "horizOff %d/%d vertOff %d/%d\n", + aperture_width.num, aperture_width.den, aperture_height.num, aperture_height.den, + horiz_off.num, horiz_off.den, vert_off.num, vert_off.den); + + pc_x = av_mul_q((AVRational) { st->codecpar->width - 1, 1 }, (AVRational) { 1, 2 }); + pc_x = av_add_q(pc_x, horiz_off); + pc_y = av_mul_q((AVRational) { st->codecpar->height - 1, 1 }, (AVRational) { 1, 2 }); + pc_y = av_add_q(pc_y, vert_off); + + aperture_width = av_sub_q(aperture_width, (AVRational) { 1, 1 }); + aperture_width = av_mul_q(aperture_width, (AVRational) { 1, 2 }); + aperture_height = av_sub_q(aperture_height, (AVRational) { 1, 1 }); + aperture_height = av_mul_q(aperture_height, (AVRational) { 1, 2 }); + + left = av_q2d(av_sub_q(pc_x, aperture_width)); + right = av_q2d(av_add_q(pc_x, aperture_width)); + top = av_q2d(av_sub_q(pc_y, aperture_height)); + bottom = av_q2d(av_add_q(pc_y, aperture_height)); + + if (top < 0 || bottom < 0 || + left < 0 || right < 0 || + bottom > (st->codecpar->height - 1) || + right > (st->codecpar->width - 1)) + return AVERROR_INVALIDDATA; + + bottom = st->codecpar->height - 1 - bottom; + right = st->codecpar->width - 1 - right; + + if ((left + right) >= st->codecpar->width || + (top + bottom) >= st->codecpar->height) + return AVERROR_INVALIDDATA; + + sd = av_packet_side_data_new(&st->codecpar->coded_side_data, + &st->codecpar->nb_coded_side_data, + AV_PKT_DATA_FRAME_CROPPING, + sizeof(uint32_t) * 4, 0); + if (!sd) + return AVERROR(ENOMEM); + + AV_WL32(sd->data, top); + AV_WL32(sd->data + 4, bottom); + AV_WL32(sd->data + 8, left); + AV_WL32(sd->data + 12, right); + + return 0; +} + /* This atom overrides any previously set aspect ratio */ static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom) { @@ -8922,6 +8999,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('a','l','a','c'), mov_read_alac }, /* alac specific atom */ { MKTAG('a','v','c','C'), mov_read_glbl }, { MKTAG('p','a','s','p'), mov_read_pasp }, +{ MKTAG('c','l','a','p'), mov_read_clap }, { MKTAG('s','i','d','x'), mov_read_sidx }, { MKTAG('s','t','b','l'), mov_read_default }, { MKTAG('s','t','c','o'), mov_read_stco }, diff --git a/tests/ref/fate/aic b/tests/ref/fate/aic index 244ea25967..30197129f7 100644 --- a/tests/ref/fate/aic +++ b/tests/ref/fate/aic @@ -1,20 +1,20 @@ #tb 0: 100/2997 #media_type 0: video #codec_id 0: rawvideo -#dimensions 0: 1440x1080 +#dimensions 0: 1416x1062 #sar 0: 4/3 -0, 0, 0, 1, 2332800, 0xc22b8485 -0, 1, 1, 1, 2332800, 0xc22b8485 -0, 2, 2, 1, 2332800, 0xe0c21bd8 -0, 3, 3, 1, 2332800, 0x3e1a8fa0 -0, 4, 4, 1, 2332800, 0xbcb3f235 -0, 5, 5, 1, 2332800, 0x1a7cabd6 -0, 6, 6, 1, 2332800, 0xc0136ba8 -0, 7, 7, 1, 2332800, 0x295e59a6 -0, 8, 8, 1, 2332800, 0xf9c09288 -0, 9, 9, 1, 2332800, 0x0518cc8f -0, 10, 10, 1, 2332800, 0x9ad3068e -0, 11, 11, 1, 2332800, 0x5a8b7af1 -0, 12, 12, 1, 2332800, 0x7b35a8fa -0, 13, 13, 1, 2332800, 0xbe5801eb -0, 14, 14, 1, 2332800, 0x31ca019f +0, 0, 0, 1, 2255688, 0x48f3973d +0, 1, 1, 1, 2255688, 0x48f3973d +0, 2, 2, 1, 2255688, 0x8c9f3c83 +0, 3, 3, 1, 2255688, 0xb89c02e3 +0, 4, 4, 1, 2255688, 0x185b1a84 +0, 5, 5, 1, 2255688, 0x82167715 +0, 6, 6, 1, 2255688, 0xe675971e +0, 7, 7, 1, 2255688, 0x623759db +0, 8, 8, 1, 2255688, 0x910274ad +0, 9, 9, 1, 2255688, 0x0eafce15 +0, 10, 10, 1, 2255688, 0x4457b006 +0, 11, 11, 1, 2255688, 0x48f70e0b +0, 12, 12, 1, 2255688, 0xfd269c3d +0, 13, 13, 1, 2255688, 0x4c6258ad +0, 14, 14, 1, 2255688, 0xb131c4af diff --git a/tests/ref/fate/prores-transparency b/tests/ref/fate/prores-transparency index 246e0b26aa..a4452e7333 100644 --- a/tests/ref/fate/prores-transparency +++ b/tests/ref/fate/prores-transparency @@ -1,13 +1,13 @@ #tb 0: 1/25 #media_type 0: video #codec_id 0: rawvideo -#dimensions 0: 1920x1080 +#dimensions 0: 1888x1062 #sar 0: 1/1 #tb 1: 1/48000 #media_type 1: audio #codec_id 1: pcm_s16le #sample_rate 1: 48000 #channel_layout_name 1: stereo -0, 0, 0, 1, 16588800, 0xcfb3d806 +0, 0, 0, 1, 16040448, 0x74480f47 1, 0, 0, 1024, 4096, 0x00000000 1, 1024, 1024, 896, 3584, 0x00000000 diff --git a/tests/ref/fate/prores-transparency_skip b/tests/ref/fate/prores-transparency_skip index 3f5fa0a13f..3e99a3de94 100644 --- a/tests/ref/fate/prores-transparency_skip +++ b/tests/ref/fate/prores-transparency_skip @@ -1,13 +1,13 @@ #tb 0: 1/25 #media_type 0: video #codec_id 0: rawvideo -#dimensions 0: 1920x1080 +#dimensions 0: 1888x1062 #sar 0: 1/1 #tb 1: 1/48000 #media_type 1: audio #codec_id 1: pcm_s16le #sample_rate 1: 48000 #channel_layout_name 1: stereo -0, 0, 0, 1, 12441600, 0x74f53304 +0, 0, 0, 1, 12030336, 0x088e6a36 1, 0, 0, 1024, 4096, 0x00000000 1, 1024, 1024, 896, 3584, 0x00000000 -- 2.45.2 _______________________________________________ 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".
next reply other threads:[~2024-07-09 1:57 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-07-09 1:55 James Almer [this message] 2024-07-09 1:55 ` [FFmpeg-devel] [PATCH 2/2] avformat/movenc: support writing cropping values James Almer 2024-07-11 12:43 ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: export cropping values from clap boxes James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240709015521.10083-1-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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