Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/vf-format-stereo-in.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
change `--vf=format:stereo-in=no` to keep the source stereo 3D mode, `--vf=format:stereo-in=mono` now overrides it with 2D
3 changes: 2 additions & 1 deletion DOCS/man/vf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ Available mpv-only filters are:
``<stereo-in>``
Set the stereo mode the video is assumed to be encoded in. Use
``--vf=format:stereo-in=help`` to list all available modes. Check with
the ``stereo3d`` filter documentation to see what the names mean.
the ``stereo3d`` filter documentation to see what the names mean. The
default ``no`` keeps the mode signaled by the source.

``<rotate>``
Set the rotation the video is assumed to be encoded with in degrees.
Expand Down
3 changes: 2 additions & 1 deletion filters/f_decoder_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ static void fix_image_params(struct priv *p,
if (m.p_w <= 0 || m.p_h <= 0)
m.p_w = m.p_h = 1;

m.stereo3d = p->codec->stereo_mode;
if (!m.stereo3d)
Comment thread
danielcamposramos marked this conversation as resolved.
m.stereo3d = p->codec->stereo_mode;

if (!mp_rect_equals(&p->codec->crop, &(struct mp_rect){0})) {
struct mp_rect crop = p->codec->crop;
Expand Down
8 changes: 4 additions & 4 deletions video/csputils.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ const struct m_opt_choice_alternatives pl_alpha_names[] = {
{0}
};

// The short name _must_ match with what vf_stereo3d accepts (if supported).
// The short names follow the input format names of the vf_stereo3d.
// The long name in comments is closer to the Matroska spec (StereoMode element).
// The numeric index matches the Matroska StereoMode value. If you add entries
// that don't match Matroska, make sure demux_mkv.c rejects them properly.
const struct m_opt_choice_alternatives mp_stereo3d_names[] = {
{"no", -1}, // disable/invalid
{"no", -1}, // unset, vf_format keeps the source mode
{"mono", 0},
{"sbs2l", 1}, // "side_by_side_left"
{"ab2r", 2}, // "top_bottom_right"
Expand All @@ -144,8 +144,8 @@ const struct m_opt_choice_alternatives mp_stereo3d_names[] = {
{"checkl", 5}, // "checkboard_left" (unsupported by vf_stereo3d)
{"irr", 6}, // "row_interleaved_right"
{"irl", 7}, // "row_interleaved_left"
{"icr", 8}, // "column_interleaved_right" (unsupported by vf_stereo3d)
{"icl", 9}, // "column_interleaved_left" (unsupported by vf_stereo3d)
{"icr", 8}, // "column_interleaved_right"
{"icl", 9}, // "column_interleaved_left"
{"arcc", 10}, // "anaglyph_cyan_red" (Matroska: unclear which mode)
{"sbs2r", 11}, // "side_by_side_right"
{"agmc", 12}, // "anaglyph_green_magenta" (Matroska: unclear which mode)
Expand Down
12 changes: 10 additions & 2 deletions video/csputils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ extern const struct m_opt_choice_alternatives mp_csp_light_names[];
// The numeric values (except -1) match the Matroska StereoMode element value.
enum mp_stereo3d_mode {
MP_STEREO3D_INVALID = -1,
/* only modes explicitly referenced in the code are listed */
MP_STEREO3D_MONO = 0,
MP_STEREO3D_SBS2L = 1,
MP_STEREO3D_AB2R = 2,
MP_STEREO3D_AB2L = 3,
MP_STEREO3D_CHECKR = 4,
MP_STEREO3D_CHECKL = 5,
MP_STEREO3D_IRR = 6,
MP_STEREO3D_IRL = 7,
MP_STEREO3D_ICR = 8,
MP_STEREO3D_ICL = 9,
MP_STEREO3D_ARCC = 10,
MP_STEREO3D_SBS2R = 11,
/* no explicit enum entries for most valid values */
MP_STEREO3D_AGMC = 12,
MP_STEREO3D_AL = 13,
MP_STEREO3D_AR = 14,
MP_STEREO3D_COUNT = 15, // 14 is last valid mode
};

Expand Down
3 changes: 2 additions & 1 deletion video/filter/vf_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void set_params(struct vf_format_opts *p, struct mp_image_params *out,
out->light = p->light;
if (p->chroma_location)
out->chroma_location = p->chroma_location;
if (p->stereo_in)
if (p->stereo_in >= 0)
out->stereo3d = p->stereo_in;
if (p->rotate >= 0)
out->rotate = p->rotate;
Expand Down Expand Up @@ -304,6 +304,7 @@ const struct mp_user_filter_entry vf_format = {
.name = "format",
.priv_size = sizeof(OPT_BASE_STRUCT),
.priv_defaults = &(const OPT_BASE_STRUCT){
.stereo_in = -1,
.rotate = -1,
.dovi = true,
.enhancement_layer = true,
Expand Down
28 changes: 28 additions & 0 deletions video/mp_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <libavutil/hwcontext.h>
#include <libavutil/intreadwrite.h>
#include <libavutil/rational.h>
#include <libavutil/stereo3d.h>
#include <libavcodec/avcodec.h>
#include <libavutil/mastering_display_metadata.h>
#include <libplacebo/utils/libav.h>
Expand Down Expand Up @@ -1079,6 +1080,29 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
}
}

static enum mp_stereo3d_mode stereo3d_from_av(const AVStereo3D *s3d)
{
bool inv = s3d->flags & AV_STEREO3D_FLAG_INVERT;
switch (s3d->type) {
case AV_STEREO3D_SIDEBYSIDE:
case AV_STEREO3D_SIDEBYSIDE_QUINCUNX:
return inv ? MP_STEREO3D_SBS2R : MP_STEREO3D_SBS2L;
case AV_STEREO3D_TOPBOTTOM:
return inv ? MP_STEREO3D_AB2R : MP_STEREO3D_AB2L;
case AV_STEREO3D_CHECKERBOARD:
return inv ? MP_STEREO3D_CHECKR : MP_STEREO3D_CHECKL;
case AV_STEREO3D_LINES:
return inv ? MP_STEREO3D_IRR : MP_STEREO3D_IRL;
case AV_STEREO3D_COLUMNS:
return inv ? MP_STEREO3D_ICR : MP_STEREO3D_ICL;
case AV_STEREO3D_FRAMESEQUENCE:
return inv ? MP_STEREO3D_AR : MP_STEREO3D_AL;
default:
// AV_STEREO3D_2D and types mpv has no mode for.
return MP_STEREO3D_MONO;
}
}

// Create a new mp_image reference to av_frame.
struct mp_image *mp_image_from_av_frame(struct AVFrame *src)
{
Expand Down Expand Up @@ -1131,6 +1155,10 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src)

dst->params.chroma_location = pl_chroma_from_av(src->chroma_location);

sd = av_frame_get_side_data(src, AV_FRAME_DATA_STEREO3D);
if (sd)
dst->params.stereo3d = stereo3d_from_av((const AVStereo3D *)sd->data);

if (src->opaque_ref) {
struct mp_image_params *p = (void *)src->opaque_ref->data;
dst->params.stereo3d = p->stereo3d;
Expand Down
21 changes: 0 additions & 21 deletions video/out/gpu/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ struct mpgl_osd_part {
struct ra_tex *texture;
int w, h;
int num_subparts;
int prev_num_subparts;
struct sub_bitmap *subparts;
int num_vertices;
struct vertex *vertices;
Expand All @@ -66,7 +65,6 @@ struct mpgl_osd {
struct mpgl_osd_part *parts[MAX_OSD_PARTS];
const struct ra_format *fmt_table[SUBBITMAP_COUNT];
bool formats[SUBBITMAP_COUNT];
bool change_flag; // for reporting to API user only
// temporary
int stereo_mode;
struct mp_osd_res osd_res;
Expand All @@ -81,7 +79,6 @@ struct mpgl_osd *mpgl_osd_init(struct ra *ra, struct mp_log *log,
.log = log,
.osd = osd,
.ra = ra,
.change_flag = true,
.scratch = talloc_zero_size(ctx, 1),
};

Expand Down Expand Up @@ -194,7 +191,6 @@ static void gen_osd_cb(void *pctx, struct sub_bitmaps *imgs)
ok = false;

osd->change_id = imgs->change_id;
ctx->change_flag = true;
}
osd->num_subparts = ok ? imgs->num_parts : 0;

Expand Down Expand Up @@ -325,15 +321,6 @@ void mpgl_osd_generate(struct mpgl_osd *ctx, struct mp_osd_res res, double pts,

osd_draw(ctx->osd, ctx->osd_res, pts, draw_flags, ctx->formats, gen_osd_cb, ctx);
ctx->stereo_mode = stereo_mode;

// Parts going away does not necessarily result in gen_osd_cb() being called
// (not even with num_parts==0), so check this separately.
for (int n = 0; n < MAX_OSD_PARTS; n++) {
struct mpgl_osd_part *part = ctx->parts[n];
if (part->num_subparts != part->prev_num_subparts)
ctx->change_flag = true;
part->prev_num_subparts = part->num_subparts;
}
}

// See osd_resize() for remarks. This function is an optional optimization too.
Expand All @@ -342,11 +329,3 @@ void mpgl_osd_resize(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mod
set_res(ctx, res, stereo_mode);
osd_resize(ctx->osd, ctx->osd_res);
}

bool mpgl_osd_check_change(struct mpgl_osd *ctx, struct mp_osd_res *res,
double pts)
{
ctx->change_flag = false;
mpgl_osd_generate(ctx, *res, pts, 0, 0);
return ctx->change_flag;
}
2 changes: 0 additions & 2 deletions video/out/gpu/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ bool mpgl_osd_draw_prepare(struct mpgl_osd *ctx, int index,
struct gl_shader_cache *sc);
void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
struct gl_shader_cache *sc, const struct ra_fbo *fbo);
bool mpgl_osd_check_change(struct mpgl_osd *ctx, struct mp_osd_res *res,
double pts);

#endif
6 changes: 0 additions & 6 deletions video/out/gpu/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -3794,12 +3794,6 @@ void gl_video_set_osd_pts(struct gl_video *p, double pts)
p->osd_pts = pts;
}

bool gl_video_check_osd_change(struct gl_video *p, struct mp_osd_res *res,
double pts)
{
return p->osd ? mpgl_osd_check_change(p->osd, res, pts) : false;
}

void gl_video_resize(struct gl_video *p,
struct mp_rect *src, struct mp_rect *dst,
struct mp_osd_res *osd)
Expand Down
2 changes: 0 additions & 2 deletions video/out/gpu/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ void gl_video_set_fb_depth(struct gl_video *p, int fb_depth);
void gl_video_perfdata(struct gl_video *p, struct voctrl_performance_data *out);
void gl_video_set_clear_color(struct gl_video *p, struct m_color color);
void gl_video_set_osd_pts(struct gl_video *p, double pts);
bool gl_video_check_osd_change(struct gl_video *p, struct mp_osd_res *osd,
double pts);

void gl_video_screenshot(struct gl_video *p, struct vo_frame *frame,
struct voctrl_screenshot *args);
Expand Down