History

libtheoraenc: Add encoding speed level option

Bernat Arlandis committed 1 year ago

Commit 3cd4fa91 parent 157d3b01 file · +25 −0Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/libtheoraenc.c+25−0
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #include "libavutil/pixdesc.h"
3838 #include "libavutil/log.h"
3939 #include "libavutil/base64.h"
40+#include "libavutil/opt.h"
4041 #include "avcodec.h"
4142 #include "codec_internal.h"
4243 #include "encode.h"
@@ -45,6 +46,7 @@ · 2 unmodified lines
4546 #include <theora/theoraenc.h>
4647
4748 typedef struct TheoraContext {
49+ AVClass *av_class; /**< class for AVOptions */
4850 th_enc_ctx *t_state;
4951 uint8_t *stats;
5052 int stats_size;
@@ -52,8 +54,21 @@ typedef struct TheoraContext { · 1 unmodified line
5254 int uv_hshift;
5355 int uv_vshift;
5456 int keyframe_mask;
57+ int speed_level;
5558 } TheoraContext;
5659
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+
5772 /** Concatenate an ogg_packet into the extradata. */
5873 static int concatenate_packet(unsigned int* offset,
5974 AVCodecContext* avc_context,
@@ -244,6 +259,15 @@ static av_cold int encode_init(AVCodecContext* avc_context) · 184 unmodified lines
244259 return AVERROR_EXTERNAL;
245260 }
246261
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+
247271 // need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers
248272 if (avc_context->flags & AV_CODEC_FLAG_PASS1) {
249273 if ((ret = get_stats(avc_context, 0)) < 0)
@@ -389,6 +413,7 @@ const FFCodec ff_libtheora_encoder = { · 139 unmodified lines
389413 .close = encode_close,
390414 FF_CODEC_ENCODE_CB(encode_frame),
391415 CODEC_PIXFMTS(AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P),
416+ .p.priv_class = &theora_class,
392417 .color_ranges = AVCOL_RANGE_MPEG,
393418 .p.wrapper_name = "libtheora",
394419 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t