Unified · Split
| @@ -37,6 +37,7 @@ · 36 unmodified lines | ||
| 37 | 37 | #include "libavutil/pixdesc.h" |
| 38 | 38 | #include "libavutil/log.h" |
| 39 | 39 | #include "libavutil/base64.h" |
| 40 | +#include "libavutil/opt.h" | |
| 40 | 41 | #include "avcodec.h" |
| 41 | 42 | #include "codec_internal.h" |
| 42 | 43 | #include "encode.h" |
| @@ -45,6 +46,7 @@ · 2 unmodified lines | ||
| 45 | 46 | #include <theora/theoraenc.h> |
| 46 | 47 | |
| 47 | 48 | typedef struct TheoraContext { |
| 49 | + AVClass *av_class; /**< class for AVOptions */ | |
| 48 | 50 | th_enc_ctx *t_state; |
| 49 | 51 | uint8_t *stats; |
| 50 | 52 | int stats_size; |
| @@ -52,8 +54,21 @@ typedef struct TheoraContext { · 1 unmodified line | ||
| 52 | 54 | int uv_hshift; |
| 53 | 55 | int uv_vshift; |
| 54 | 56 | int keyframe_mask; |
| 57 | + int speed_level; | |
| 55 | 58 | } TheoraContext; |
| 56 | 59 | |
| 60 | +static const AVOption options[] = { | |
| 61 | + { "speed_level", "Sets the encoding speed level", offsetof(TheoraContext, speed_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, | |
| 62 | + { NULL } | |
| 63 | +}; | |
| 64 | + | |
| 65 | +static const AVClass theora_class = { | |
| 66 | + .class_name = "libtheora", | |
| 67 | + .item_name = av_default_item_name, | |
| 68 | + .option = options, | |
| 69 | + .version = LIBAVUTIL_VERSION_INT, | |
| 70 | +}; | |
| 71 | + | |
| 57 | 72 | /** Concatenate an ogg_packet into the extradata. */ |
| 58 | 73 | static int concatenate_packet(unsigned int* offset, |
| 59 | 74 | AVCodecContext* avc_context, |
| @@ -244,6 +259,15 @@ static av_cold int encode_init(AVCodecContext* avc_context) · 184 unmodified lines | ||
| 244 | 259 | return AVERROR_EXTERNAL; |
| 245 | 260 | } |
| 246 | 261 | |
| 262 | + // Set encoding speed level | |
| 263 | + if (h->speed_level != -1) { | |
| 264 | + int max_speed_level; | |
| 265 | + int speed_level = h->speed_level; | |
| 266 | + th_encode_ctl(h->t_state, TH_ENCCTL_GET_SPLEVEL_MAX, &max_speed_level, sizeof(max_speed_level)); | |
| 267 | + speed_level = FFMIN(speed_level, max_speed_level); | |
| 268 | + th_encode_ctl(h->t_state, TH_ENCCTL_SET_SPLEVEL, &speed_level, sizeof(speed_level)); | |
| 269 | + } | |
| 270 | + | |
| 247 | 271 | // need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers |
| 248 | 272 | if (avc_context->flags & AV_CODEC_FLAG_PASS1) { |
| 249 | 273 | if ((ret = get_stats(avc_context, 0)) < 0) |
| @@ -389,6 +413,7 @@ const FFCodec ff_libtheora_encoder = { · 139 unmodified lines | ||
| 389 | 413 | .close = encode_close, |
| 390 | 414 | FF_CODEC_ENCODE_CB(encode_frame), |
| 391 | 415 | CODEC_PIXFMTS(AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P), |
| 416 | + .p.priv_class = &theora_class, | |
| 392 | 417 | .color_ranges = AVCOL_RANGE_MPEG, |
| 393 | 418 | .p.wrapper_name = "libtheora", |
| 394 | 419 | }; |