[FFmpeg-devel] [PATCH 04/13] lavc/videotoolboxenc: Add entropy setting
Rick Kern
kernrj at gmail.com
Sun Apr 10 05:50:09 CEST 2016
Add an entropy setting to choose between CAVLC and CABAC.
Signed-off-by: Rick Kern <kernrj at gmail.com>
---
libavcodec/videotoolboxenc.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 2bcd3ef..6586ca7 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -41,6 +41,12 @@ typedef enum VT_H264Profile {
H264_PROF_COUNT
} VT_H264Profile;
+typedef enum VTH264Entropy{
+ VT_ENTROPY_NOT_SET,
+ VT_CAVLC,
+ VT_CABAC
+} VTH264Entropy;
+
static const uint8_t start_code[] = { 0, 0, 0, 1 };
typedef struct BufNode {
@@ -70,6 +76,8 @@ typedef struct VTEncContext {
int64_t profile;
int64_t level;
+ int64_t entropy;
+
bool flushing;
bool has_b_frames;
bool warned_color_range;
@@ -623,6 +631,11 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
vtctx->has_b_frames = false;
}
+ if (vtctx->entropy == VT_CABAC && vtctx->profile == H264_PROF_BASELINE) {
+ av_log(avctx, AV_LOG_WARNING, "CABAC entropy requires 'main' or 'high' profile, but baseline was requested. Encode will not use CABAC entropy.\n");
+ vtctx->entropy = VT_ENTROPY_NOT_SET;
+ }
+
if (!get_vt_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
vtctx->session = NULL;
@@ -721,6 +734,21 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
}
}
+ if (vtctx->entropy != VT_ENTROPY_NOT_SET) {
+ CFStringRef entropy = vtctx->entropy == VT_CABAC ?
+ kVTH264EntropyMode_CABAC:
+ kVTH264EntropyMode_CAVLC;
+
+ status = VTSessionSetProperty(vtctx->session,
+ kVTCompressionPropertyKey_H264EntropyMode,
+ entropy);
+
+ if (status) {
+ av_log(avctx, AV_LOG_ERROR, "Error setting entropy property: %d\n", status);
+ return AVERROR_EXTERNAL;
+ }
+ }
+
status = VTCompressionSessionPrepareToEncodeFrames(vtctx->session);
if (status) {
av_log(avctx, AV_LOG_ERROR, "Error: cannot prepare encoder: %d\n", status);
@@ -1464,6 +1492,10 @@ static const AVOption options[] = {
{ "5.1", "Level 5.1", 0, AV_OPT_TYPE_CONST, { .i64 = 51 }, INT_MIN, INT_MAX, VE, "level" },
{ "5.2", "Level 5.2", 0, AV_OPT_TYPE_CONST, { .i64 = 52 }, INT_MIN, INT_MAX, VE, "level" },
+ { "entropy", "Entropy coding", OFFSET(entropy), AV_OPT_TYPE_INT, { .i64 = VT_ENTROPY_NOT_SET }, VT_ENTROPY_NOT_SET, VT_CABAC, VE, "entropy" },
+ { "cavlc", "CAVLC entropy coding", 0, AV_OPT_TYPE_CONST, { .i64 = VT_CAVLC }, INT_MIN, INT_MAX, VE, "entropy" },
+ { "cabac", "CABAC entropy coding", 0, AV_OPT_TYPE_CONST, { .i64 = VT_CABAC }, INT_MIN, INT_MAX, VE, "entropy" },
+
{ NULL },
};
--
2.7.4
More information about the ffmpeg-devel
mailing list