From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH] avformat/matroskadec: Export rectangular projection as displaymatrix Date: Fri, 21 Jan 2022 20:01:24 +0100 Message-ID: <AM7PR03MB6660484F8EA7F73BAD638C568F5B9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw) This is the officially supported way to express rotations and flips in Matroska. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- No muxing support and tests for now; for the former, I first have to write a proper function that actually checks for whether a given display matrix is a rotation (even if not a proper rotation). The latter will be added together with muxing support. libavformat/matroskadec.c | 44 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 594543748d..d165f6ab90 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -37,6 +37,7 @@ #include "libavutil/base64.h" #include "libavutil/bprint.h" #include "libavutil/dict.h" +#include "libavutil/display.h" #include "libavutil/intfloat.h" #include "libavutil/intreadwrite.h" #include "libavutil/lzo.h" @@ -2231,6 +2232,44 @@ static int mkv_parse_video_color(AVStream *st, const MatroskaTrack *track) { return 0; } +static int mkv_create_display_matrix(AVStream *st, + const MatroskaTrackVideoProjection *proj, + void *logctx) +{ + double pitch = proj->pitch, yaw = proj->yaw, roll = proj->roll; + int32_t *matrix; + int hflip; + + if (pitch == 0.0 && yaw == 0.0 && roll == 0.0) + return 0; + + /* Note: The following constants are exactly representable + * as floating-point numbers. */ + if (pitch != 0.0 || (yaw != 0.0 && yaw != 180.0 && yaw != -180.0) || + isnan(roll)) { + av_log(logctx, AV_LOG_WARNING, "Ignoring non-2D rectangular " + "projection in stream %u (yaw %f, pitch %f, roll %f)\n", + st->index, yaw, pitch, roll); + return 0; + } + matrix = (int32_t*)av_stream_new_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, + 9 * sizeof(*matrix)); + if (!matrix) + return AVERROR(ENOMEM); + + hflip = yaw != 0.0; + /* ProjectionPoseRoll is in the counter-clockwise direction + * whereas av_display_rotation_set() expects its argument + * to be oriented clockwise, so we need to negate roll. + * Furthermore, if hflip is set, we need to negate it again + * to account for the fact that the Matroska specifications + * require the yaw rotation to be applied first. */ + av_display_rotation_set(matrix, roll * (2 * hflip - 1)); + av_display_matrix_flip(matrix, hflip, 0); + + return 0; +} + static int mkv_parse_video_projection(AVStream *st, const MatroskaTrack *track, void *logctx) { @@ -2249,6 +2288,8 @@ static int mkv_parse_video_projection(AVStream *st, const MatroskaTrack *track, } switch (track->video.projection.type) { + case MATROSKA_VIDEO_PROJECTION_TYPE_RECTANGULAR: + return mkv_create_display_matrix(st, mkv_projection, logctx); case MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR: if (track->video.projection.private.size == 20) { t = AV_RB32(priv_data + 4); @@ -2291,9 +2332,6 @@ static int mkv_parse_video_projection(AVStream *st, const MatroskaTrack *track, return AVERROR_INVALIDDATA; } break; - case MATROSKA_VIDEO_PROJECTION_TYPE_RECTANGULAR: - /* No Spherical metadata */ - return 0; default: av_log(logctx, AV_LOG_WARNING, "Unknown spherical metadata type %"PRIu64"\n", -- 2.32.0 _______________________________________________ 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".
reply other threads:[~2022-01-21 19:01 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=AM7PR03MB6660484F8EA7F73BAD638C568F5B9@AM7PR03MB6660.eurprd03.prod.outlook.com \ --to=andreas.rheinhardt@outlook.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