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
37#include "libavutil/pixdesc.h"37#include "libavutil/pixdesc.h"
38#include "libavutil/log.h"38#include "libavutil/log.h"
39#include "libavutil/base64.h"39#include "libavutil/base64.h"
40#include "libavutil/opt.h"
40#include "avcodec.h"41#include "avcodec.h"
41#include "codec_internal.h"42#include "codec_internal.h"
42#include "encode.h"43#include "encode.h"
@@ -45,6 +46,7 @@ · 2 unmodified lines
45#include <theora/theoraenc.h>46#include <theora/theoraenc.h>
46 47
47typedef struct TheoraContext {48typedef struct TheoraContext {
49 AVClass *av_class; /**< class for AVOptions */
48 th_enc_ctx *t_state;50 th_enc_ctx *t_state;
49 uint8_t *stats;51 uint8_t *stats;
50 int stats_size;52 int stats_size;
@@ -52,8 +54,21 @@ typedef struct TheoraContext { · 1 unmodified line
52 int uv_hshift;54 int uv_hshift;
53 int uv_vshift;55 int uv_vshift;
54 int keyframe_mask;56 int keyframe_mask;
57 int speed_level;
55} TheoraContext;58} TheoraContext;
56 59
60static 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
65static 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/** Concatenate an ogg_packet into the extradata. */72/** Concatenate an ogg_packet into the extradata. */
58static int concatenate_packet(unsigned int* offset,73static int concatenate_packet(unsigned int* offset,
59 AVCodecContext* avc_context,74 AVCodecContext* avc_context,
@@ -244,6 +259,15 @@ static av_cold int encode_init(AVCodecContext* avc_context) · 184 unmodified lines
244 return AVERROR_EXTERNAL;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 // need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers271 // need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers
248 if (avc_context->flags & AV_CODEC_FLAG_PASS1) {272 if (avc_context->flags & AV_CODEC_FLAG_PASS1) {
249 if ((ret = get_stats(avc_context, 0)) < 0)273 if ((ret = get_stats(avc_context, 0)) < 0)
@@ -389,6 +413,7 @@ const FFCodec ff_libtheora_encoder = { · 139 unmodified lines
389 .close = encode_close,413 .close = encode_close,
390 FF_CODEC_ENCODE_CB(encode_frame),414 FF_CODEC_ENCODE_CB(encode_frame),
391 CODEC_PIXFMTS(AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P),415 CODEC_PIXFMTS(AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P),
416 .p.priv_class = &theora_class,
392 .color_ranges = AVCOL_RANGE_MPEG,417 .color_ranges = AVCOL_RANGE_MPEG,
393 .p.wrapper_name = "libtheora",418 .p.wrapper_name = "libtheora",
394};419};

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