diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2013-08-08 20:27:24 +0200 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2013-09-22 16:20:54 +0200 |
commit | 547c2f002a87f4412a83c23b0d60364be5e7ce58 (patch) | |
tree | b7ae4ce31ea8d8344a54c1290a4f690936d46a80 /libavcodec | |
parent | a5cbf1991c3d04b0be3c23ee0a7096b5a365cc85 (diff) | |
download | ffmpeg-547c2f002a87f4412a83c23b0d60364be5e7ce58.tar.gz |
Make decoding alpha optional for some codecs.
For codecs where decoding of a whole plane can simply
be skipped, we should offer applications to not decode
alpha for better performance (ca. 30% less CPU usage
and 40% reduced memory bandwidth).
It also means applications do not need to implement support
(even if it is rather simple) for YUVA formats in order to be
able to play these files.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/avcodec.h | 13 | ||||
-rw-r--r-- | libavcodec/ffv1dec.c | 1 | ||||
-rw-r--r-- | libavcodec/options_table.h | 1 | ||||
-rw-r--r-- | libavcodec/proresdec2.c | 1 | ||||
-rw-r--r-- | libavcodec/proresdec_lgpl.c | 3 | ||||
-rw-r--r-- | libavcodec/vp56.c | 7 |
6 files changed, 22 insertions, 4 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 997a00cbf6..61048f4dcf 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2865,6 +2865,19 @@ typedef struct AVCodecContext { #define FF_SUB_CHARENC_MODE_AUTOMATIC 0 ///< libavcodec will select the mode itself #define FF_SUB_CHARENC_MODE_PRE_DECODER 1 ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv + /** + * Skip processing alpha if supported by codec. + * Note that if the format uses pre-multiplied alpha (common with VP6, + * and recommended due to better video quality/compression) + * the image will look as if alpha-blended onto a black background. + * However for formats that do not use pre-multiplied alpha + * there might be serious artefacts (though e.g. libswscale currently + * assumes pre-multiplied alpha anyway). + * + * - decoding: set by user + * - encoding: unused + */ + int skip_alpha; } AVCodecContext; AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 87cc2ca450..57a566bb62 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -641,6 +641,7 @@ static int read_header(FFV1Context *f) } if (f->colorspace == 0) { + if (f->avctx->skip_alpha) f->transparency = 0; if (!f->transparency && !f->chroma_planes) { if (f->avctx->bits_per_raw_sample <= 8) f->avctx->pix_fmt = AV_PIX_FMT_GRAY8; diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index e9cdfc4ac4..8c025fe076 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -380,6 +380,7 @@ static const AVOption avcodec_options[] = { {"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_AUTOMATIC}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"}, {"pre_decoder", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_PRE_DECODER}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"}, {"refcounted_frames", NULL, OFFSET(refcounted_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, A|V|D }, +{"skip_alpha", "Skip processing alpha", OFFSET(skip_alpha), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, V|D }, {NULL}, }; diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c index 9a8861cb22..4950652ed9 100644 --- a/libavcodec/proresdec2.c +++ b/libavcodec/proresdec2.c @@ -97,6 +97,7 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, av_log(avctx, AV_LOG_ERROR, "Invalid alpha mode %d\n", ctx->alpha_info); return AVERROR_INVALIDDATA; } + if (avctx->skip_alpha) ctx->alpha_info = 0; av_dlog(avctx, "frame type %d\n", ctx->frame_type); diff --git a/libavcodec/proresdec_lgpl.c b/libavcodec/proresdec_lgpl.c index 2fef2c6e43..04aeb16ab5 100644 --- a/libavcodec/proresdec_lgpl.c +++ b/libavcodec/proresdec_lgpl.c @@ -140,6 +140,7 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, av_log(avctx, AV_LOG_ERROR, "Invalid alpha mode %d\n", ctx->alpha_info); return AVERROR_INVALIDDATA; } + if (avctx->skip_alpha) ctx->alpha_info = 0; switch (ctx->chroma_factor) { case 2: @@ -609,7 +610,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata) coff[2] = coff[1] + u_data_size; v_data_size = hdr_size > 7 ? AV_RB16(buf + 6) : slice_data_size - coff[2]; coff[3] = coff[2] + v_data_size; - a_data_size = slice_data_size - coff[3]; + a_data_size = ctx->alpha_info ? slice_data_size - coff[3] : 0; /* if V or alpha component size is negative that means that previous component sizes are too large */ diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c index 25801ea6c0..d67eaa6b0d 100644 --- a/libavcodec/vp56.c +++ b/libavcodec/vp56.c @@ -530,7 +530,7 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF) < 0) return -1; - if (s->has_alpha) { + if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) { av_frame_unref(s->alpha_context->frames[VP56_FRAME_CURRENT]); if ((ret = av_frame_ref(s->alpha_context->frames[VP56_FRAME_CURRENT], p)) < 0) { av_frame_unref(p); @@ -545,7 +545,7 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, } } - if (s->has_alpha) { + if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) { int bak_w = avctx->width; int bak_h = avctx->height; int bak_cw = avctx->coded_width; @@ -567,7 +567,7 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, } } - avctx->execute2(avctx, ff_vp56_decode_mbs, 0, 0, s->has_alpha + 1); + avctx->execute2(avctx, ff_vp56_decode_mbs, 0, 0, (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) + 1); if ((res = av_frame_ref(data, p)) < 0) return res; @@ -690,6 +690,7 @@ av_cold int ff_vp56_init_context(AVCodecContext *avctx, VP56Context *s, s->avctx = avctx; avctx->pix_fmt = has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P; + if (avctx->skip_alpha) avctx->pix_fmt = AV_PIX_FMT_YUV420P; ff_h264chroma_init(&s->h264chroma, 8); ff_hpeldsp_init(&s->hdsp, avctx->flags); |