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 A8BB849C45 for ; Wed, 3 Jul 2024 21:28:05 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA22268DA07; Thu, 4 Jul 2024 00:27:01 +0300 (EEST) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 912E568D9EE for ; Thu, 4 Jul 2024 00:26:51 +0300 (EEST) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7066f68e22cso14540b3a.2 for ; Wed, 03 Jul 2024 14:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042008; x=1720646808; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=M0VmP7zyEjRq7BIPibcoPG9PEpk9wNM6p6Kt2XRTXoI=; b=MnV67oWuirL3DuyE5wLrcvEXfHG7HAoElVVWv+BwBelmyM6qC+EF99arxnnwzlilfv l7WJQNWhfOXl6CrqV/4f5PhmvCUUUtONyUJ9AzARwD9QxuzucW7q58MJ8CW1k70V6IYw YXQRT4p7CuurROB20SGQPPSjXb4g4gdi4DnSfxp9qcjaFszANNHveP/83GPga7eZUB3i LXmpZvuuJxHytfAZwj1tXbXI5ehf6Wg2o4aGFWFSLRI/8InWSJjGskcQ0+lC7LicfuG+ uk5WD9LwFaaIeKVjOwmseflRslHLAmVgNCBwa1BU/nD7ZYLkuEFVWu+6OtRft2dCKCgT uTJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042008; x=1720646808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M0VmP7zyEjRq7BIPibcoPG9PEpk9wNM6p6Kt2XRTXoI=; b=sIh85r+LOXfpB25dkfdzalJWfMDdX+fJamWgr3Z0w/5L2O2kLTBXSrQLU2moIt7Gyi 0WB1hBLsNIp8DFFz+VO3omyBVO/x0DH2Y3ZcEOF2YsQ5frYHmyhNPMvKxZOt8HS2qh66 9kEA4YIJ7uDXePln3z5Rnd0hplmR/Ju6X33mXW095RtOGJbUCAkZBSpaz0wxzw4zT3Jo KQfXdWoCCRIFk+MWGOC4NXb00SXMhBvvutTGmmABF3ntivrsuXQ6YUxTjrzrBnl2pzA7 ODoycxcJp8guANQ4f4qwqk6elpBmTGwdJHw4bGPZD/P6M9VbEcNClr85WKuil5SMCtyp tJIw== X-Gm-Message-State: AOJu0YziECkGvtkppqBEZwuFDeZ2dV5Zu9lNWrohnOENkhXmOW+EDI/Z 9CIs2fZSuhUowzwk8b2b3qSZlCK0/QlmWPKiip5MKAORfW7zdbGZwR/TSw== X-Google-Smtp-Source: AGHT+IFnpsOqrDzMOwMGD831lqpMY+CLVTCT5o+PwbXMzbEhb0Bw9hbEzJNyN6+F2gGwNkGFSttYOg== X-Received: by 2002:a05:6a20:7489:b0:1bd:2aa5:f177 with SMTP id adf61e73a8af0-1bef611aa11mr14587480637.11.1720042007451; Wed, 03 Jul 2024 14:26:47 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm11370560a91.24.2024.07.03.14.26.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:26:47 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Jul 2024 18:26:45 -0300 Message-ID: <20240703212648.48483-10-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703212648.48483-1-jamrial@gmail.com> References: <20240703212648.48483-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/11] avformat/movenc: add support for writting vexu boxes 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: Signed-off-by: James Almer --- libavformat/movenc.c | 159 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 154 insertions(+), 5 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 26a67e6e47..500ea25731 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2190,6 +2190,138 @@ static int mov_write_sv3d_tag(AVFormatContext *s, AVIOContext *pb, AVSphericalMa return update_size(pb, sv3d_pos); } +static inline int64_t rescale_rational(AVRational q, int b) +{ + return av_rescale(q.num, b, q.den); +} + +static void mov_write_vexu_proj_tag(AVFormatContext *s, AVIOContext *pb, + const AVSphericalMapping *spherical_mapping) +{ + avio_wb32(pb, 24); /* size */ + ffio_wfourcc(pb, "proj"); + avio_wb32(pb, 16); /* size */ + ffio_wfourcc(pb, "prji"); + avio_wb32(pb, 0); /* version + flags */ + + switch (spherical_mapping->projection) { + case AV_SPHERICAL_RECTILINEAR: + ffio_wfourcc(pb, "rect"); + break; + case AV_SPHERICAL_EQUIRECTANGULAR: + ffio_wfourcc(pb, "equi"); + break; + case AV_SPHERICAL_HALF_EQUIRECTANGULAR: + ffio_wfourcc(pb, "hequ"); + break; + case AV_SPHERICAL_FISHEYE: + ffio_wfourcc(pb, "fish"); + break; + default: + av_assert0(0); + } +} + +static int mov_write_eyes_tag(AVFormatContext *s, AVIOContext *pb, + const AVStereo3D *stereo3d) +{ + int64_t pos = avio_tell(pb); + int view = 0; + + avio_wb32(pb, 0); /* size */ + ffio_wfourcc(pb, "eyes"); + + // stri is mandatory + avio_wb32(pb, 13); /* size */ + ffio_wfourcc(pb, "stri"); + avio_wb32(pb, 0); /* version + flags */ + switch (stereo3d->view) { + case AV_STEREO3D_VIEW_LEFT: + view |= 1 << 0; + break; + case AV_STEREO3D_VIEW_RIGHT: + view |= 1 << 1; + break; + case AV_STEREO3D_VIEW_PACKED: + view |= (1 << 0) | (1 << 1); + break; + } + view |= !!(stereo3d->flags & AV_STEREO3D_FLAG_INVERT) << 3; + avio_w8(pb, view); + + // hero is optional + if (stereo3d->primary_eye != AV_PRIMARY_EYE_NONE) { + avio_wb32(pb, 13); /* size */ + ffio_wfourcc(pb, "hero"); + avio_wb32(pb, 0); /* version + flags */ + avio_w8(pb, stereo3d->primary_eye); + } + + // it's not clear if cams is mandatory or optional + if (stereo3d->baseline) { + avio_wb32(pb, 24); /* size */ + ffio_wfourcc(pb, "cams"); + avio_wb32(pb, 16); /* size */ + ffio_wfourcc(pb, "blin"); + avio_wb32(pb, 0); /* version + flags */ + avio_wb32(pb, stereo3d->baseline); + } + + // it's not clear if cmfy is mandatory or optional + if (stereo3d->horizontal_disparity_adjustment.num) { + avio_wb32(pb, 24); /* size */ + ffio_wfourcc(pb, "cmfy"); + avio_wb32(pb, 16); /* size */ + ffio_wfourcc(pb, "dadj"); + avio_wb32(pb, 0); /* version + flags */ + avio_wb32(pb, rescale_rational(stereo3d->horizontal_disparity_adjustment, 10000)); + } + + return update_size(pb, pos); +} + +static int mov_write_vexu_tag(AVFormatContext *s, AVIOContext *pb, + const AVStereo3D *stereo3d, + const AVSphericalMapping *spherical_mapping) +{ + int64_t pos; + + if (spherical_mapping && + spherical_mapping->projection != AV_SPHERICAL_RECTILINEAR && + spherical_mapping->projection != AV_SPHERICAL_EQUIRECTANGULAR && + spherical_mapping->projection != AV_SPHERICAL_HALF_EQUIRECTANGULAR && + spherical_mapping->projection != AV_SPHERICAL_FISHEYE) { + av_log(s, AV_LOG_WARNING, "Unsupported projection %d. proj not written.\n", + spherical_mapping->projection); + spherical_mapping = NULL; + } + + if (stereo3d && (stereo3d->type == AV_STEREO3D_2D || + (!(stereo3d->flags & AV_STEREO3D_FLAG_INVERT) && + stereo3d->view == AV_STEREO3D_VIEW_UNSPEC && + stereo3d->primary_eye == AV_PRIMARY_EYE_NONE && + !stereo3d->baseline && + !stereo3d->horizontal_disparity_adjustment.num))) { + av_log(s, AV_LOG_WARNING, "Unsupported stereo 3d metadata. eyes not written.\n"); + stereo3d = NULL; + } + + if (!spherical_mapping && !stereo3d) + return 0; + + pos = avio_tell(pb); + avio_wb32(pb, 0); /* size */ + ffio_wfourcc(pb, "vexu"); + + if (spherical_mapping) + mov_write_vexu_proj_tag(s, pb, spherical_mapping); + + if (stereo3d) + mov_write_eyes_tag(s, pb, stereo3d); + + return update_size(pb, pos); +} + static int mov_write_dvcc_dvvc_tag(AVFormatContext *s, AVIOContext *pb, AVDOVIDecoderConfigurationRecord *dovi) { uint8_t buf[ISOM_DVCC_DVVC_SIZE]; @@ -2326,11 +2458,6 @@ static int mov_write_clli_tag(AVIOContext *pb, MOVTrack *track) return 12; } -static inline int64_t rescale_rational(AVRational q, int b) -{ - return av_rescale(q.num, b, q.den); -} - static int mov_write_mdcv_tag(AVIOContext *pb, MOVTrack *track) { const int chroma_den = 50000; @@ -2623,6 +2750,28 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex mov_write_sv3d_tag(mov->fc, pb, (AVSphericalMapping*)spherical_mapping->data); } + if (track->mode == MODE_MOV || (track->mode == MODE_MP4 && + mov->fc->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL)) { + const AVPacketSideData *sd; + const AVStereo3D *stereo3d = NULL; + const AVSphericalMapping *spherical_mapping = NULL; + + sd = av_packet_side_data_get(track->st->codecpar->coded_side_data, + track->st->codecpar->nb_coded_side_data, + AV_PKT_DATA_STEREO3D); + if (sd) + stereo3d = (AVStereo3D *)sd->data; + + sd = av_packet_side_data_get(track->st->codecpar->coded_side_data, + track->st->codecpar->nb_coded_side_data, + AV_PKT_DATA_SPHERICAL); + if (sd) + spherical_mapping = (AVSphericalMapping *)sd->data; + + if (stereo3d || spherical_mapping) + mov_write_vexu_tag(s, pb, stereo3d, spherical_mapping); + } + if (track->mode == MODE_MP4) { const AVPacketSideData *dovi = av_packet_side_data_get(track->st->codecpar->coded_side_data, track->st->codecpar->nb_coded_side_data, -- 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".