video: support setting libswscale chroma position

This commit is contained in:
wm4 2013-07-25 23:02:23 +02:00
parent 24e50ee74e
commit 9cc5630fd5
6 changed files with 41 additions and 1 deletions

12
configure vendored
View File

@ -2647,6 +2647,17 @@ fi
echores "$_avcodec_has_text_flag_api"
echocheck "libavcodec avcodec_enum_to_chroma_pos API"
_avcodec_has_chroma_pos_api=no
statement_check libavcodec/avcodec.h 'int x, y; avcodec_enum_to_chroma_pos(&x, &y, AVCHROMA_LOC_UNSPECIFIED)' && _avcodec_has_chroma_pos_api=yes
if test "$_avcodec_has_chroma_pos_api" = yes ; then
def_avcodec_has_chroma_pos_api='#define HAVE_AVCODEC_CHROMA_POS_API 1'
else
def_avcodec_has_chroma_pos_api='#define HAVE_AVCODEC_CHROMA_POS_API 0'
fi
echores "$_avcodec_has_chroma_pos_api"
echocheck "libavutil QP API"
_avutil_has_qp_api=no
statement_check libavutil/frame.h 'av_frame_get_qp_table(NULL, NULL, NULL)' && _avutil_has_qp_api=yes
@ -3169,6 +3180,7 @@ $def_zlib
$def_avutil_has_refcounting
$def_avutil_has_qp_api
$def_avcodec_has_text_flag_api
$def_avcodec_has_chroma_pos_api
$def_libpostproc
$def_libavdevice
$def_libavfilter

View File

@ -116,6 +116,15 @@ enum mp_chroma_location avchroma_location_to_mp(int avloc)
}
}
int mp_chroma_location_to_av(enum mp_chroma_location mploc)
{
switch (mploc) {
case MP_CHROMA_LEFT: return AVCHROMA_LOC_LEFT;
case MP_CHROMA_CENTER: return AVCHROMA_LOC_CENTER;
default: return AVCHROMA_LOC_UNSPECIFIED;
}
}
// Return location of chroma samples relative to luma samples. 0/0 means
// centered. Other possible values are -1 (top/left) and +1 (right/bottom).
void mp_get_chroma_location(enum mp_chroma_location loc, int *x, int *y)

View File

@ -144,6 +144,7 @@ int mp_csp_levels_to_avcol_range(enum mp_csp_levels range);
enum mp_csp mp_csp_guess_colorspace(int width, int height);
enum mp_chroma_location avchroma_location_to_mp(int avloc);
int mp_chroma_location_to_av(enum mp_chroma_location mploc);
void mp_get_chroma_location(enum mp_chroma_location loc, int *x, int *y);

View File

@ -411,7 +411,8 @@ bool mp_image_params_equals(const struct mp_image_params *p1,
p1->w == p2->w && p1->h == p2->h &&
p1->d_w == p2->d_w && p1->d_h == p2->d_h &&
p1->colorspace == p2->colorspace &&
p1->colorlevels == p2->colorlevels;
p1->colorlevels == p2->colorlevels &&
p1->chroma_location == p2->chroma_location;
}
void mp_image_params_from_image(struct mp_image_params *params,
@ -426,6 +427,7 @@ void mp_image_params_from_image(struct mp_image_params *params,
.d_h = image->display_h,
.colorspace = image->colorspace,
.colorlevels = image->levels,
.chroma_location = image->chroma_location,
};
}

View File

@ -387,6 +387,7 @@ static bool resize(struct vo *vo)
.d_w = p->dst_w,
.d_h = p->dst_h,
};
mp_image_params_guess_csp(&p->sws->dst);
if (mp_sws_reinit(p->sws) < 0)
return false;

View File

@ -19,6 +19,7 @@
#include <assert.h>
#include <libswscale/swscale.h>
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
#include "sws_utils.h"
@ -227,6 +228,20 @@ int mp_sws_reinit(struct mp_sws_context *ctx)
av_opt_set_double(ctx->sws, "param0", ctx->params[0], 0);
av_opt_set_double(ctx->sws, "param1", ctx->params[1], 0);
#if HAVE_AVCODEC_CHROMA_POS_API
int cr_src = mp_chroma_location_to_av(src->chroma_location);
int cr_dst = mp_chroma_location_to_av(dst->chroma_location);
int cr_xpos, cr_ypos;
if (avcodec_enum_to_chroma_pos(&cr_xpos, &cr_ypos, cr_src) >= 0) {
av_opt_set_int(ctx->sws, "src_h_chr_pos", cr_xpos, 0);
av_opt_set_int(ctx->sws, "src_v_chr_pos", cr_ypos, 0);
}
if (avcodec_enum_to_chroma_pos(&cr_xpos, &cr_ypos, cr_dst) >= 0) {
av_opt_set_int(ctx->sws, "dst_h_chr_pos", cr_xpos, 0);
av_opt_set_int(ctx->sws, "dst_v_chr_pos", cr_ypos, 0);
}
#endif
// This can fail even with normal operation, e.g. if a conversion path
// simply does not support these settings.
sws_setColorspaceDetails(ctx->sws, sws_getCoefficients(s_csp), s_range,