Commit b368edde authored by Christophe Massiot's avatar Christophe Massiot

* modules/codec/ffmpeg: New options to fine-tune advanced encoder options.

 * modules/codec/ffmpeg/video.c: Better handling of aspect ratio change.
parent 26bebc75
......@@ -140,6 +140,8 @@ struct encoder_sys_t
vlc_bool_t b_mpeg4_matrix;
vlc_bool_t b_trellis;
int i_quality; /* for VBR */
float f_lumi_masking, f_dark_masking, f_p_masking, f_border_masking;
int i_luma_elim, i_chroma_elim;
/* Used to work around stupid timestamping behaviour in libavcodec */
uint64_t i_framenum;
......@@ -150,7 +152,9 @@ static const char *ppsz_enc_options[] = {
"keyint", "bframes", "vt", "qmin", "qmax", "hq", "strict-rc",
"rc-buffer-size", "rc-buffer-aggressivity", "pre-me", "hurry-up",
"interlace", "i-quant-factor", "noise-reduction", "mpeg4-matrix",
"trellis", "qscale", "strict", NULL
"trellis", "qscale", "strict", "lumi-masking", "dark-masking",
"p-masking", "border-masking", "luma-elim-threshold",
"chroma-elim-threshold", NULL
};
/*****************************************************************************
......@@ -313,6 +317,19 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
if( val.i_int < - 1 || val.i_int > 1 ) val.i_int = 0;
p_context->strict_std_compliance = val.i_int;
var_Get( p_enc, ENC_CFG_PREFIX "lumi-masking", &val );
p_sys->f_lumi_masking = val.f_float;
var_Get( p_enc, ENC_CFG_PREFIX "dark-masking", &val );
p_sys->f_dark_masking = val.f_float;
var_Get( p_enc, ENC_CFG_PREFIX "p-masking", &val );
p_sys->f_p_masking = val.f_float;
var_Get( p_enc, ENC_CFG_PREFIX "border-masking", &val );
p_sys->f_border_masking = val.f_float;
var_Get( p_enc, ENC_CFG_PREFIX "luma-elim-threshold", &val );
p_sys->i_luma_elim = val.i_int;
var_Get( p_enc, ENC_CFG_PREFIX "chroma-elim-threshold", &val );
p_sys->i_chroma_elim = val.i_int;
if( p_enc->fmt_in.i_cat == VIDEO_ES )
{
int i_aspect_num, i_aspect_den;
......@@ -344,6 +361,13 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
p_context->i_quant_offset = 0.0;
p_context->i_quant_factor = -0.8;
p_context->lumi_masking = p_sys->f_lumi_masking;
p_context->dark_masking = p_sys->f_dark_masking;
p_context->p_masking = p_sys->f_p_masking;
p_context->border_masking = p_sys->f_border_masking;
p_context->luma_elim_threshold = p_sys->i_luma_elim;
p_context->chroma_elim_threshold = p_sys->i_chroma_elim;
if( p_sys->i_key_int > 0 )
p_context->gop_size = p_sys->i_key_int;
p_context->max_b_frames =
......
......@@ -163,6 +163,18 @@ vlc_module_begin();
ENC_QSCALE_TEXT, ENC_QSCALE_LONGTEXT, VLC_TRUE );
add_integer( ENC_CFG_PREFIX "strict", 0, NULL,
ENC_STRICT_TEXT, ENC_STRICT_LONGTEXT, VLC_TRUE );
add_float( ENC_CFG_PREFIX "lumi-masking", 0.0, NULL,
ENC_LUMI_MASKING_TEXT, ENC_LUMI_MASKING_LONGTEXT, VLC_TRUE );
add_float( ENC_CFG_PREFIX "dark-masking", 0.0, NULL,
ENC_DARK_MASKING_TEXT, ENC_DARK_MASKING_LONGTEXT, VLC_TRUE );
add_float( ENC_CFG_PREFIX "p-masking", 0.0, NULL,
ENC_P_MASKING_TEXT, ENC_P_MASKING_LONGTEXT, VLC_TRUE );
add_float( ENC_CFG_PREFIX "border-masking", 0.0, NULL,
ENC_BORDER_MASKING_TEXT, ENC_BORDER_MASKING_LONGTEXT, VLC_TRUE );
add_integer( ENC_CFG_PREFIX "luma-elim-threshold", 0, NULL,
ENC_LUMA_ELIM_TEXT, ENC_LUMA_ELIM_LONGTEXT, VLC_TRUE );
add_integer( ENC_CFG_PREFIX "chroma-elim-threshold", 0, NULL,
ENC_CHROMA_ELIM_TEXT, ENC_CHROMA_ELIM_LONGTEXT, VLC_TRUE );
/* demux submodule */
add_submodule();
......
......@@ -249,3 +249,29 @@ void E_(ClosePostproc)( decoder_t *, void * );
#define ENC_STRICT_TEXT N_( "Strict standard compliance" )
#define ENC_STRICT_LONGTEXT N_( "Allows you to force a strict standard " \
"compliance when encoding (accepted values: -1, 0, 1)." )
#define ENC_LUMI_MASKING_TEXT N_( "Luminance masking" )
#define ENC_LUMI_MASKING_LONGTEXT N_( "Allows you to raise the quantizer for " \
"very bright macroblocks (default: 0.0)." )
#define ENC_DARK_MASKING_TEXT N_( "Darkness masking" )
#define ENC_DARK_MASKING_LONGTEXT N_( "Allows you to raise the quantizer for " \
"very dark macroblocks (default: 0.0)." )
#define ENC_P_MASKING_TEXT N_( "Motion masking" )
#define ENC_P_MASKING_LONGTEXT N_( "Allows you to raise the quantizer for " \
"macroblocks with a high temporal complexity (default: 0.0)." )
#define ENC_BORDER_MASKING_TEXT N_( "Border masking" )
#define ENC_BORDER_MASKING_LONGTEXT N_( "Allows you to raise the quantizer " \
"for macroblocks at the border of the frame (default: 0.0)." )
#define ENC_LUMA_ELIM_TEXT N_( "Luminance elimination" )
#define ENC_LUMA_ELIM_LONGTEXT N_( "Eliminates luminance blocks when " \
"the PSNR isn't much changed (default: 0.0). The H264 specification " \
"recommends -4." )
#define ENC_CHROMA_ELIM_TEXT N_( "Chrominance elimination" )
#define ENC_CHROMA_ELIM_LONGTEXT N_( "Eliminates chrominance blocks when " \
"the PSNR isn't much changed (default: 0.0). The H264 specification " \
"recommends 7." )
......@@ -579,12 +579,35 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
/* Set the PTS */
if( p_sys->p_ff_pic->pts ) p_sys->i_pts = p_sys->p_ff_pic->pts;
/* Sanity check (seems to be needed for some streams ) */
/* Sanity check (seems to be needed for some streams) */
if( p_sys->p_ff_pic->pict_type == FF_B_TYPE )
{
p_sys->b_has_b_frames = VLC_TRUE;
}
if( !p_dec->fmt_in.video.i_aspect )
{
/* Fetch again the aspect ratio in case it changed */
#if LIBAVCODEC_BUILD >= 4687
p_dec->fmt_out.video.i_aspect =
VOUT_ASPECT_FACTOR
* ( av_q2d(p_sys->p_context->sample_aspect_ratio)
* p_sys->p_context->width / p_sys->p_context->height );
p_dec->fmt_out.video.i_sar_num
= p_sys->p_context->sample_aspect_ratio.num;
p_dec->fmt_out.video.i_sar_den
= p_sys->p_context->sample_aspect_ratio.den;
#else
p_dec->fmt_out.video.i_aspect =
VOUT_ASPECT_FACTOR * p_sys->p_context->aspect_ratio;
#endif
if( p_dec->fmt_out.video.i_aspect == 0 )
{
p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR
* p_sys->p_context->width / p_sys->p_context->height;
}
}
/* Send decoded frame to vout */
if( p_sys->i_pts )
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment