From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2529E4813B for ; Tue, 9 Jul 2024 17:22:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 75A3668DA9B; Tue, 9 Jul 2024 20:21:59 +0300 (EEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 89FF368DA9B for ; Tue, 9 Jul 2024 20:21:52 +0300 (EEST) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-70af8062039so3313857b3a.0 for ; Tue, 09 Jul 2024 10:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720545710; x=1721150510; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=tlwdzRZsQ9vn9hW+c0sPCSzH5hR4JBnztYwMNDBLl+w=; b=APQQEJLoGBJvlJqZgXXwySPP9Oqx0i50LyVRE/lPwIcYkjoJKT/KKs4OVwuz/M51ym w4+RVoDQ928sZDjmWyQJpXXc6C0YlhEo7mX+Teb7xfjVPRlicZba3aa4UNddi1b3Q/69 HZuV/aJLl2NoNt09vFwiu6hY2XOwr/oYIsudqDW/NG7yi9bfp1ZfqIkSPckyhGBukER7 e76yyQd0agOcSjtp10ORQCPZWbGQjz/85O4XVGEr5a/gIY9Qo6eNhBOoBBH86nTcwqO2 RUZkyvyXjDe0AUmKHcBPr+xvyAuh2/LXVmrStikchFCx8N6XYh98llFBf/nGgrcEALiJ vDXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720545710; x=1721150510; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tlwdzRZsQ9vn9hW+c0sPCSzH5hR4JBnztYwMNDBLl+w=; b=cqOrW/5Q/DtvBuROwHeP4hz7jQiNPvSvNqMzdNMg9jyBtenzgH/ufysJRwvnKAbvgZ OZtuW2mBOA9K+4w6eqO+/NK7vFm+EG2H3YyZpTFJGvJHFfIbWZzPIlvCBq98kAJqSDly Y6E3SbmMnr3NDlVveTCFOAZKj7YKMv0w6XOGUs026FDljLnu7Xg79AyS78aEqQ5/ye3H xd5OZn2csy/SyQN95nCQ9t8PNo3SQDKadx/Wvum2RIIzG02Rb3VZiTlmdywFHwWcLmY8 M6dmGgv2ekA9RZ79v648oTNK7WualxRAlm283txQ/G9uxfCJSRFhxDCW/+YU3MVn+LLY 4yfA== X-Gm-Message-State: AOJu0Ywky4E+7jD1WW8pDtsxdGN5Fs4RXgEwtdSv90ebv38GEsCcpej0 eHraQ8aPVKauEHulG7F9i1DGbVim9EK5b2nKZAi1rsrborP3rQZ7HPuw6w== X-Google-Smtp-Source: AGHT+IH5ttSD9QKUXUNaY7bpWcz/0R4y15zNNePLiojIf48kRBUgnwzs3/LxSDlOK8nZzpvhjILAoA== X-Received: by 2002:a05:6a21:1690:b0:1c0:e322:e8c5 with SMTP id adf61e73a8af0-1c29821b544mr3021043637.26.1720545709825; Tue, 09 Jul 2024 10:21:49 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6a0fc62sm18715725ad.40.2024.07.09.10.21.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jul 2024 10:21:49 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jul 2024 14:21:40 -0300 Message-ID: <20240709172140.48976-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: ensure pasp box derived SAR is used if present X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: It's meant to override any codec specific (but container level) information, but its position is not guaranteed, so apply the values after the entire trak structure has been parsed. Also, replace the ugly roundabout int -> double -> int method to set SAR from existing dimensions while at it. Signed-off-by: James Almer --- libavformat/isom.h | 2 ++ libavformat/mov.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index a0498f45e5..5b6125a908 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -215,6 +215,8 @@ typedef struct MOVStreamContext { int timecode_track; int width; ///< tkhd width int height; ///< tkhd height + int h_spacing; ///< pasp hSpacing + int v_spacing; ///< pasp vSpacing int dts_shift; ///< dts shift when ctts is negative uint32_t palette[256]; int has_palette; diff --git a/libavformat/mov.c b/libavformat/mov.c index ced4b2e6b3..ce95842ce5 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1287,14 +1287,18 @@ static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom) const int num = avio_rb32(pb); const int den = avio_rb32(pb); AVStream *st; + MOVStreamContext *sc; if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + + av_log(c->fc, AV_LOG_TRACE, "pasp: hSpacing %d, vSpacing %d\n", num, den); if (den != 0) { - av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, - num, den, 32767); + sc->h_spacing = num; + sc->v_spacing = den; } return 0; } @@ -5031,11 +5035,15 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (sc->h_spacing && sc->v_spacing) + av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, + sc->h_spacing, sc->v_spacing, INT_MAX); if (!st->sample_aspect_ratio.num && st->codecpar->width && st->codecpar->height && sc->height && sc->width && (st->codecpar->width != sc->width || st->codecpar->height != sc->height)) { - st->sample_aspect_ratio = av_d2q(((double)st->codecpar->height * sc->width) / - ((double)st->codecpar->width * sc->height), INT_MAX); + av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, + (int64_t)st->codecpar->height * sc->width, + (int64_t)st->codecpar->width * sc->height, INT_MAX); } #if FF_API_R_FRAME_RATE -- 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".