[PATCH 1/2] avutil/stereo3d add Monoscopic View enum value
We need a way to signal the frame has a single view that doesn't map to any particular eye, and it should be the default one. Signed-off-by: James Almer <jamrial@gmail.com> --- The Stereo spec from Apple, which was used to design this API, states "both has_left_eye_view and has_right_eye_view can be set to 0 to indicate that the frame is monoscopic". Since this API is barely two days old, we can change the enum maped to value 0 as an exception. libavutil/stereo3d.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h index 00a5c3900e..77340f72b2 100644 --- a/libavutil/stereo3d.h +++ b/libavutil/stereo3d.h @@ -143,9 +143,9 @@ enum AVStereo3DType { */ enum AVStereo3DView { /** - * Frame contains two packed views. + * Frame is monoscopic. */ - AV_STEREO3D_VIEW_PACKED, + AV_STEREO3D_VIEW_MONO, /** * Frame contains only the left view. @@ -156,6 +156,11 @@ enum AVStereo3DView { * Frame contains only the right view. */ AV_STEREO3D_VIEW_RIGHT, + + /** + * Frame contains two packed views. + */ + AV_STEREO3D_VIEW_PACKED, }; /** -- 2.45.2
Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/mov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 50e171c960..4fa39cf4fd 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -6546,7 +6546,7 @@ static int mov_read_eyes(MOVContext *c, AVIOContext *pb, MOVAtom atom) int size, flags = 0; int64_t remaining; uint32_t tag, baseline = 0; - enum AVStereo3DView view = AV_STEREO3D_VIEW_PACKED; + enum AVStereo3DView view = AV_STEREO3D_VIEW_MONO; enum AVStereo3DPrimaryEye primary_eye = AV_PRIMARY_EYE_NONE; AVRational horizontal_disparity_adjustment = { 0, 1 }; -- 2.45.2
On Fri, Jun 21, 2024 at 10:25:31PM -0300, James Almer wrote:
Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/mov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
doesnt apply automatically with "git am" with the v2 Applying: avformat/mov: default to Monoscopic view when parsing eyes box error: sha1 information is lacking or useless (libavformat/mov.c). error: could not build fake ancestor Patch failed at 0001 avformat/mov: default to Monoscopic view when parsing eyes box it applies with patch but inability to automatically apply patches could affect tools which try to test patches posted git am --show-current-patch=diff | patch -p1 patching file libavformat/mov.c Hunk #1 succeeded at 6546 with fuzz 2. thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB It is a danger to trust the dream we wish for rather than the science we have, -- Dr. Kenneth Brown
On 6/22/2024 6:25 PM, Michael Niedermayer wrote:
On Fri, Jun 21, 2024 at 10:25:31PM -0300, James Almer wrote:
Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/mov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
doesnt apply automatically with "git am" with the v2
Applying: avformat/mov: default to Monoscopic view when parsing eyes box error: sha1 information is lacking or useless (libavformat/mov.c). error: could not build fake ancestor Patch failed at 0001 avformat/mov: default to Monoscopic view when parsing eyes box
it applies with patch but inability to automatically apply patches could affect tools which try to test patches posted
git am --show-current-patch=diff | patch -p1 patching file libavformat/mov.c Hunk #1 succeeded at 6546 with fuzz 2.
Are you sure your tree is clean and up to date? There's no reason for this patch to not apply, standalone or after 1/1 v1 or v2. In any case, this set and the next are withdrawn as i realized i mistakenly assumed AVStereo3DView was a new enum, when it's not. I'll be sending a new set later.
thx
[...]
_______________________________________________ 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".
On Sat, Jun 22, 2024 at 06:34:49PM -0300, James Almer wrote:
On 6/22/2024 6:25 PM, Michael Niedermayer wrote:
On Fri, Jun 21, 2024 at 10:25:31PM -0300, James Almer wrote:
Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/mov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
doesnt apply automatically with "git am" with the v2
Applying: avformat/mov: default to Monoscopic view when parsing eyes box error: sha1 information is lacking or useless (libavformat/mov.c). error: could not build fake ancestor Patch failed at 0001 avformat/mov: default to Monoscopic view when parsing eyes box
it applies with patch but inability to automatically apply patches could affect tools which try to test patches posted
git am --show-current-patch=diff | patch -p1 patching file libavformat/mov.c Hunk #1 succeeded at 6546 with fuzz 2.
Are you sure your tree is clean and up to date? There's no reason for this patch to not apply, standalone or after 1/1 v1 or v2.
the patch says this: index 50e171c960..4fa39cf4fd 100644 git fetch origin git fetch jamrial git show 50e171c960 fatal: ambiguous argument '50e171c960': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' git show 4fa39cf4fd fatal: ambiguous argument '4fa39cf4fd': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' so i think the blob this patch was based on is not in any repository known to my git It might be able to apply the patch anyway but not having the full file this patch is based on makes it harder for git. I did have other patches applied. so git would try to merge this in and if needed produce conflict markers but given that it doesnt seem to have the file this was based on it freaked out thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB While the State exists there can be no freedom; when there is freedom there will be no State. -- Vladimir Lenin
Given that a video stream/frame may have only one view coded, or both packed in an undefined way, and as the values of AVStereo3DView and AVStereo3DType may clash (namely if type is AV_STEREO3D_2D, then AV_STEREO3D_VIEW_PACKED would be invalid, and if it's anything other than it, then only AV_STEREO3D_VIEW_PACKED would be valid), this commit adds a new type value AV_STEREO3D_VIEW that signals the user that AVStereo3D.view contains information about the nature of the stream, with the added constrain that AVStereo3D.view should be ignored if AVStereo3D.type is anything other than AV_STEREO3D_VIEW. Signed-off-by: James Almer <jamrial@gmail.com> --- This is the only way i could think of to work around the fact AVStereo3DType and AVStereo3DView just can't work well together if we want to keep AVStereo backwards compatible. libavutil/stereo3d.c | 1 + libavutil/stereo3d.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libavutil/stereo3d.c b/libavutil/stereo3d.c index 0c0cad127c..e8e5030db9 100644 --- a/libavutil/stereo3d.c +++ b/libavutil/stereo3d.c @@ -65,6 +65,7 @@ static const char * const stereo3d_type_names[] = { [AV_STEREO3D_SIDEBYSIDE_QUINCUNX] = "side by side (quincunx subsampling)", [AV_STEREO3D_LINES] = "interleaved lines", [AV_STEREO3D_COLUMNS] = "interleaved columns", + [AV_STEREO3D_VIEW] = "view defined", }; static const char * const stereo3d_view_names[] = { diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h index 77340f72b2..e3af519e03 100644 --- a/libavutil/stereo3d.h +++ b/libavutil/stereo3d.h @@ -136,6 +136,14 @@ enum AVStereo3DType { * @endcode */ AV_STEREO3D_COLUMNS, + + /** + * Video may be monoscopic, or stereoscopic where either the + * packing is unknown or only one view is present. + * + * @see AVStereo3DView + */ + AV_STEREO3D_VIEW, }; /** @@ -207,7 +215,8 @@ typedef struct AVStereo3D { int flags; /** - * Determines which views are packed. + * Determines which views are packed. This field should be ignored when + * @ref type is set to anything other than AV_STEREO3D_VIEW. */ enum AVStereo3DView view; -- 2.45.2
Quoting James Almer (2024-06-22 04:41:11)
Given that a video stream/frame may have only one view coded, or both packed in an undefined way, and as the values of AVStereo3DView and AVStereo3DType may clash (namely if type is AV_STEREO3D_2D, then AV_STEREO3D_VIEW_PACKED would be invalid, and if it's anything other than it, then only AV_STEREO3D_VIEW_PACKED would be valid), this commit adds a new type value AV_STEREO3D_VIEW that signals the user that AVStereo3D.view contains information about the nature of the stream, with the added constrain that AVStereo3D.view should be ignored if AVStereo3D.type is anything other than AV_STEREO3D_VIEW.
Signed-off-by: James Almer <jamrial@gmail.com> --- This is the only way i could think of to work around the fact AVStereo3DType and AVStereo3DView just can't work well together if we want to keep AVStereo backwards compatible.
I don't really see what actual problem is this supposed to address, rather it seems to me it just muddles the situation further. When type is AV_STEREO3D_2D, the video is monoscopic and everything else in AVStereo3D should be ignored. In this light I also don't see the point of patch 1. Nontrivial values of AVStereo3DView are meaningful only for a stereoscopic non-packed video, i.e. AV_STEREO3D_FRAMESEQUENCE. -- Anton Khirnov
Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/dump.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/dump.c b/libavformat/dump.c index 61a2c6a29f..33d72b7e18 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -259,9 +259,10 @@ static void dump_stereo3d(void *ctx, const AVPacketSideData *sd, int log_level) stereo = (const AVStereo3D *)sd->data; - av_log(ctx, log_level, "%s, view: %s, primary eye: %s", - av_stereo3d_type_name(stereo->type), av_stereo3d_view_name(stereo->view), - av_stereo3d_primary_eye_name(stereo->primary_eye)); + av_log(ctx, log_level, "%s", av_stereo3d_type_name(stereo->type)); + if (stereo->type == AV_STEREO3D_VIEW) + av_log(ctx, log_level, ", view: %s", av_stereo3d_view_name(stereo->view)); + av_log(ctx, log_level, ", primary eye: %s", av_stereo3d_primary_eye_name(stereo->primary_eye)); if (stereo->baseline) av_log(ctx, log_level, ", baseline: %"PRIu32"", stereo->baseline); if (stereo->horizontal_disparity_adjustment.num && stereo->horizontal_disparity_adjustment.den) -- 2.45.2
av_stereo3d_alloc() is not useful in scenarios where you need to know the runtime size of AVStereo3D. Signed-off-by: James Almer <jamrial@gmail.com> --- libavutil/stereo3d.c | 8 ++++++++ libavutil/stereo3d.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/libavutil/stereo3d.c b/libavutil/stereo3d.c index e8e5030db9..c182b18e52 100644 --- a/libavutil/stereo3d.c +++ b/libavutil/stereo3d.c @@ -32,6 +32,11 @@ static void get_defaults(AVStereo3D *stereo) } AVStereo3D *av_stereo3d_alloc(void) +{ + return av_stereo3d_alloc_size(NULL); +} + +AVStereo3D *av_stereo3d_alloc_size(size_t *size) { AVStereo3D *stereo = av_mallocz(sizeof(AVStereo3D)); if (!stereo) @@ -39,6 +44,9 @@ AVStereo3D *av_stereo3d_alloc(void) get_defaults(stereo); + if (size) + *size = sizeof(*stereo); + return stereo; } diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h index e3af519e03..31167c14fa 100644 --- a/libavutil/stereo3d.h +++ b/libavutil/stereo3d.h @@ -251,6 +251,14 @@ typedef struct AVStereo3D { */ AVStereo3D *av_stereo3d_alloc(void); +/** + * Allocate an AVStereo3D structure and set its fields to default values. + * The resulting struct can be freed using av_freep(). + * + * @return An AVStereo3D filled with default values or NULL on failure. + */ +AVStereo3D *av_stereo3d_alloc_size(size_t *size); + /** * Allocate a complete AVFrameSideData and add it to the frame. * -- 2.45.2
It's not part of the libavutil ABI. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/isom.h | 1 + libavformat/mov.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 35b767a52c..a0498f45e5 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -247,6 +247,7 @@ typedef struct MOVStreamContext { int32_t *display_matrix; AVStereo3D *stereo3d; + size_t stereo3d_size; AVSphericalMapping *spherical; size_t spherical_size; AVMasteringDisplayMetadata *mastering; diff --git a/libavformat/mov.c b/libavformat/mov.c index 9b2ce1f167..07c0ec3ec4 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -6332,7 +6332,7 @@ static int mov_read_st3d(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } - sc->stereo3d = av_stereo3d_alloc(); + sc->stereo3d = av_stereo3d_alloc_size(&sc->stereo3d_size); if (!sc->stereo3d) return AVERROR(ENOMEM); @@ -6695,7 +6695,7 @@ static int mov_read_eyes(MOVContext *c, AVIOContext *pb, MOVAtom atom) } if (!sc->stereo3d) { - sc->stereo3d = av_stereo3d_alloc(); + sc->stereo3d = av_stereo3d_alloc_size(&sc->stereo3d_size); if (!sc->stereo3d) return AVERROR(ENOMEM); } @@ -6782,7 +6782,7 @@ static int mov_read_hfov(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!sc->stereo3d) { - sc->stereo3d = av_stereo3d_alloc(); + sc->stereo3d = av_stereo3d_alloc_size(&sc->stereo3d_size); if (!sc->stereo3d) return AVERROR(ENOMEM); } @@ -6831,7 +6831,7 @@ static int mov_parse_uuid_spherical(MOVStreamContext *sc, AVIOContext *pb, size_ else mode = AV_STEREO3D_2D; - sc->stereo3d = av_stereo3d_alloc(); + sc->stereo3d = av_stereo3d_alloc_size(&sc->stereo3d_size); if (!sc->stereo3d) goto out; @@ -10032,7 +10032,7 @@ static int mov_read_header(AVFormatContext *s) if (sc->stereo3d) { if (!av_packet_side_data_add(&st->codecpar->coded_side_data, &st->codecpar->nb_coded_side_data, AV_PKT_DATA_STEREO3D, - (uint8_t *)sc->stereo3d, sizeof(*sc->stereo3d), 0)) + (uint8_t *)sc->stereo3d, sc->stereo3d_size, 0)) return AVERROR(ENOMEM); sc->stereo3d = NULL; -- 2.45.2
It's not part of the libavutil ABI. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/matroskadec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 6bc5fa621e..d1a135ed63 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2253,8 +2253,9 @@ static int mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mo STEREOMODE_STEREO3D_MAPPING(STEREO_MODE_CONV, NOTHING) }; AVStereo3D *stereo; + size_t size; - stereo = av_stereo3d_alloc(); + stereo = av_stereo3d_alloc_size(&size); if (!stereo) return AVERROR(ENOMEM); @@ -2262,7 +2263,7 @@ static int mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mo stereo->flags = stereo_mode_conv[stereo_mode].flags; if (!av_packet_side_data_add(&st->codecpar->coded_side_data, &st->codecpar->nb_coded_side_data, - AV_PKT_DATA_STEREO3D, stereo, sizeof(*stereo), 0)) { + AV_PKT_DATA_STEREO3D, stereo, size, 0)) { av_freep(&stereo); return AVERROR(ENOMEM); } -- 2.45.2
We need a way to signal the frame has a single view that doesn't map to any particular eye, and it should be the default one. Signed-off-by: James Almer <jamrial@gmail.com> --- Now updating the fate test, to show how type and view clashed as is. libavutil/stereo3d.c | 3 ++- libavutil/stereo3d.h | 9 +++++++-- tests/ref/fate/matroska-spherical-mono | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libavutil/stereo3d.c b/libavutil/stereo3d.c index 19e81e4124..0c0cad127c 100644 --- a/libavutil/stereo3d.c +++ b/libavutil/stereo3d.c @@ -68,9 +68,10 @@ static const char * const stereo3d_type_names[] = { }; static const char * const stereo3d_view_names[] = { - [AV_STEREO3D_VIEW_PACKED] = "packed", + [AV_STEREO3D_VIEW_MONO] = "monoscopic", [AV_STEREO3D_VIEW_LEFT] = "left", [AV_STEREO3D_VIEW_RIGHT] = "right", + [AV_STEREO3D_VIEW_PACKED] = "packed", }; static const char * const stereo3d_primary_eye_names[] = { diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h index 00a5c3900e..77340f72b2 100644 --- a/libavutil/stereo3d.h +++ b/libavutil/stereo3d.h @@ -143,9 +143,9 @@ enum AVStereo3DType { */ enum AVStereo3DView { /** - * Frame contains two packed views. + * Frame is monoscopic. */ - AV_STEREO3D_VIEW_PACKED, + AV_STEREO3D_VIEW_MONO, /** * Frame contains only the left view. @@ -156,6 +156,11 @@ enum AVStereo3DView { * Frame contains only the right view. */ AV_STEREO3D_VIEW_RIGHT, + + /** + * Frame contains two packed views. + */ + AV_STEREO3D_VIEW_PACKED, }; /** diff --git a/tests/ref/fate/matroska-spherical-mono b/tests/ref/fate/matroska-spherical-mono index b108596350..aa17e9c624 100644 --- a/tests/ref/fate/matroska-spherical-mono +++ b/tests/ref/fate/matroska-spherical-mono @@ -3,7 +3,7 @@ side_data_type=Stereo 3D type=2D inverted=0 -view=packed +view=monoscopic primary_eye=none baseline=0 horizontal_disparity_adjustment=0/1 -- 2.45.2
Signed-off-by: James Almer <jamrial@gmail.com> --- fftools/ffprobe.c | 3 ++- tests/ref/fate/matroska-spherical-mono | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index d7ba980ff9..f9124ad5d7 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2544,7 +2544,8 @@ static void print_pkt_side_data(WriterContext *w, const AVStereo3D *stereo = (AVStereo3D *)sd->data; print_str("type", av_stereo3d_type_name(stereo->type)); print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT)); - print_str("view", av_stereo3d_view_name(stereo->view)); + if (stereo->type == AV_STEREO3D_VIEW) + print_str("view", av_stereo3d_view_name(stereo->view)); print_str("primary_eye", av_stereo3d_primary_eye_name(stereo->primary_eye)); print_int("baseline", stereo->baseline); print_q("horizontal_disparity_adjustment", stereo->horizontal_disparity_adjustment, '/'); diff --git a/tests/ref/fate/matroska-spherical-mono b/tests/ref/fate/matroska-spherical-mono index aa17e9c624..254bb9903f 100644 --- a/tests/ref/fate/matroska-spherical-mono +++ b/tests/ref/fate/matroska-spherical-mono @@ -3,7 +3,6 @@ side_data_type=Stereo 3D type=2D inverted=0 -view=monoscopic primary_eye=none baseline=0 horizontal_disparity_adjustment=0/1 -- 2.45.2
On date Saturday 2024-06-22 00:37:01 -0300, James Almer wrote:
Signed-off-by: James Almer <jamrial@gmail.com> --- fftools/ffprobe.c | 3 ++- tests/ref/fate/matroska-spherical-mono | 1 - 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index d7ba980ff9..f9124ad5d7 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2544,7 +2544,8 @@ static void print_pkt_side_data(WriterContext *w, const AVStereo3D *stereo = (AVStereo3D *)sd->data; print_str("type", av_stereo3d_type_name(stereo->type)); print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
- print_str("view", av_stereo3d_view_name(stereo->view)); + if (stereo->type == AV_STEREO3D_VIEW) + print_str("view", av_stereo3d_view_name(stereo->view));
probably we should use print_str_opt to follow the other fields logic [...]
participants (4)
-
Anton Khirnov -
James Almer -
Michael Niedermayer -
Stefano Sabatini