diff --git ffpresets/libvpx-1080p.ffpreset ffpresets/libvpx-1080p.ffpreset
new file mode 100644
index 0000000..71d7a73
-
|
+
|
|
| 1 | vcodec=libvpx |
| 2 | g=120 |
| 3 | rc_lookahead=16 |
| 4 | level=216 |
| 5 | profile=1 |
| 6 | qmax=42 |
| 7 | qmin=10 |
| 8 | token_partitions=4 |
| 9 | vb=2M |
| 10 | |
| 11 | #ignored unless using -pass 2 |
| 12 | maxrate=24M |
| 13 | minrate=100k |
diff --git ffpresets/libvpx-1080p50_60.ffpreset ffpresets/libvpx-1080p50_60.ffpreset
new file mode 100644
index 0000000..1b447ca
-
|
+
|
|
| 1 | vcodec=libvpx |
| 2 | g=120 |
| 3 | rc_lookahead=25 |
| 4 | level=216 |
| 5 | profile=1 |
| 6 | qmax=42 |
| 7 | qmin=10 |
| 8 | token_partitions=4 |
| 9 | vb=2M |
| 10 | |
| 11 | #ignored unless using -pass 2 |
| 12 | maxrate=24M |
| 13 | minrate=100k |
diff --git ffpresets/libvpx-360p.ffpreset ffpresets/libvpx-360p.ffpreset
new file mode 100644
index 0000000..dea0468
-
|
+
|
|
| 1 | vcodec=libvpx |
| 2 | g=120 |
| 3 | rc_lookahead=16 |
| 4 | level=216 |
| 5 | profile=0 |
| 6 | qmax=51 |
| 7 | qmin=1 |
| 8 | vb=768k |
| 9 | |
| 10 | #ignored unless using -pass 2 |
| 11 | maxrate=1.5M |
| 12 | minrate=40k |
diff --git ffpresets/libvpx-720p.ffpreset ffpresets/libvpx-720p.ffpreset
new file mode 100644
index 0000000..adc9c3a
-
|
+
|
|
| 1 | vcodec=libvpx |
| 2 | g=120 |
| 3 | rc_lookahead=16 |
| 4 | level=216 |
| 5 | profile=0 |
| 6 | qmax=42 |
| 7 | qmin=10 |
| 8 | token_partitions=4 |
| 9 | vb=2M |
| 10 | |
| 11 | #ignored unless using -pass 2 |
| 12 | maxrate=24M |
| 13 | minrate=100k |
diff --git ffpresets/libvpx-720p50_60.ffpreset ffpresets/libvpx-720p50_60.ffpreset
new file mode 100644
index 0000000..e9b361e
-
|
+
|
|
| 1 | vcodec=libvpx |
| 2 | g=120 |
| 3 | rc_lookahead=25 |
| 4 | level=216 |
| 5 | profile=0 |
| 6 | qmax=42 |
| 7 | qmin=10 |
| 8 | token_partitions=4 |
| 9 | vb=2M |
| 10 | |
| 11 | #ignored unless using -pass 2 |
| 12 | maxrate=24M |
| 13 | minrate=100k |
diff --git libavcodec/avcodec.h libavcodec/avcodec.h
index 974e87c..3afd41b 100644
|
|
|
30 | 30 | #include "libavutil/avutil.h" |
31 | 31 | |
32 | 32 | #define LIBAVCODEC_VERSION_MAJOR 52 |
33 | | #define LIBAVCODEC_VERSION_MINOR 72 |
| 33 | #define LIBAVCODEC_VERSION_MINOR 73 |
34 | 34 | #define LIBAVCODEC_VERSION_MICRO 2 |
35 | 35 | |
36 | 36 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
… |
… |
typedef struct RcOverride{ |
598 | 598 | #define CODEC_FLAG2_MBTREE 0x00040000 ///< Use macroblock tree ratecontrol (x264 only) |
599 | 599 | #define CODEC_FLAG2_PSY 0x00080000 ///< Use psycho visual optimizations. |
600 | 600 | #define CODEC_FLAG2_SSIM 0x00100000 ///< Compute SSIM during encoding, error[] values are undefined. |
| 601 | #define CODEC_FLAG2_ALT_REF 0x00400000 ///< Allow encoder to insert alternate reference frames (VP8 only) |
601 | 602 | |
602 | 603 | /* Unsupported options : |
603 | 604 | * Syntax Arithmetic coding (SAC) |
… |
… |
typedef struct AVCodecContext { |
2652 | 2653 | * - decoding: unused |
2653 | 2654 | */ |
2654 | 2655 | int rc_lookahead; |
| 2656 | |
| 2657 | /** |
| 2658 | * Number of token partitions. |
| 2659 | * Indicates number of sub-streams in the bitstream. Used for parallelized |
| 2660 | * decoding. |
| 2661 | * Valid values are 1, 2, 4 & 8 |
| 2662 | * - encoding: Set by user. |
| 2663 | * - decoding: unused |
| 2664 | * |
| 2665 | * \attention VP8 specific |
| 2666 | */ |
| 2667 | int token_partitions; |
2655 | 2668 | } AVCodecContext; |
2656 | 2669 | |
2657 | 2670 | /** |
diff --git libavcodec/libvpxenc.c libavcodec/libvpxenc.c
index fa393b8..3801800 100644
|
|
|
36 | 36 | * One encoded frame returned from the library. |
37 | 37 | */ |
38 | 38 | struct FrameListData { |
39 | | void *buf; /**≤ compressed data buffer */ |
40 | | size_t sz; /**≤ length of compressed data */ |
41 | | int64_t pts; /**≤ time stamp to show frame |
| 39 | void *buf; /**< compressed data buffer */ |
| 40 | size_t sz; /**< length of compressed data */ |
| 41 | int64_t pts; /**< time stamp to show frame |
42 | 42 | (in timebase units) */ |
43 | | unsigned long duration; /**≤ duration to show frame |
| 43 | unsigned long duration; /**< duration to show frame |
44 | 44 | (in timebase units) */ |
45 | | uint32_t flags; /**≤ flags for this frame */ |
| 45 | uint32_t flags; /**< flags for this frame */ |
46 | 46 | struct FrameListData *next; |
47 | 47 | }; |
48 | 48 | |
… |
… |
static av_cold int vp8_init(AVCodecContext *avctx) |
218 | 218 | } |
219 | 219 | dump_enc_cfg(avctx, &enccfg); |
220 | 220 | |
| 221 | /* With altref set an additional frame at the same pts may be produced. |
| 222 | Increasing the time_base gives the library a window to place these frames |
| 223 | ensuring strictly increasing timestamps. */ |
| 224 | if (avctx->flags2 & CODEC_FLAG2_ALT_REF) { |
| 225 | avctx->ticks_per_frame = 2; |
| 226 | avctx->time_base = av_mul_q(avctx->time_base, |
| 227 | (AVRational){1, avctx->ticks_per_frame}); |
| 228 | } |
| 229 | |
221 | 230 | enccfg.g_w = avctx->width; |
222 | 231 | enccfg.g_h = avctx->height; |
223 | 232 | enccfg.g_timebase.num = avctx->time_base.num; |
224 | 233 | enccfg.g_timebase.den = avctx->time_base.den; |
225 | 234 | enccfg.g_threads = avctx->thread_count; |
| 235 | enccfg.g_lag_in_frames= FFMIN(avctx->rc_lookahead, 25); //0-25, avoids init failure |
226 | 236 | |
227 | 237 | if (avctx->flags & CODEC_FLAG_PASS1) |
228 | 238 | enccfg.g_pass = VPX_RC_FIRST_PASS; |
… |
… |
static av_cold int vp8_init(AVCodecContext *avctx) |
277 | 287 | enccfg.rc_twopass_stats_in = ctx->twopass_stats; |
278 | 288 | } |
279 | 289 | |
280 | | ctx->deadline = VPX_DL_GOOD_QUALITY; |
| 290 | /* 0-3: For non-zero values the encoder increasingly optimizes for reduced |
| 291 | complexity playback on low powered devices at the expense of encode |
| 292 | quality. */ |
| 293 | if (avctx->profile != FF_PROFILE_UNKNOWN) |
| 294 | enccfg.g_profile = avctx->profile; |
| 295 | switch (FFABS(avctx->level) / 100) { |
| 296 | case 1: |
| 297 | ctx->deadline = VPX_DL_BEST_QUALITY; |
| 298 | break; |
| 299 | case 2: |
| 300 | default: |
| 301 | ctx->deadline = VPX_DL_GOOD_QUALITY; |
| 302 | break; |
| 303 | case 3: |
| 304 | ctx->deadline = VPX_DL_REALTIME; |
| 305 | break; |
| 306 | } |
| 307 | av_log(avctx, AV_LOG_DEBUG, "Using deadline: %lu\n", ctx->deadline); |
| 308 | |
| 309 | if (avctx->level != FF_LEVEL_UNKNOWN) { |
| 310 | enccfg.g_error_resilient = avctx->level < 0; |
| 311 | cpuused = FFABS(avctx->level) % 100 - 16; //[-16,16] |
| 312 | } |
281 | 313 | |
282 | 314 | dump_enc_cfg(avctx, &enccfg); |
283 | 315 | /* Construct Encoder Context */ |
… |
… |
static av_cold int vp8_init(AVCodecContext *avctx) |
291 | 323 | av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n"); |
292 | 324 | codecctl_int(avctx, VP8E_SET_CPUUSED, cpuused); |
293 | 325 | codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction); |
| 326 | codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF, !!(avctx->flags2 & CODEC_FLAG2_ALT_REF)); |
| 327 | codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->token_partitions)); |
294 | 328 | |
295 | 329 | //provide dummy value to initialize wrapper, values will be updated each _encode() |
296 | 330 | vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1, |
diff --git libavcodec/options.c libavcodec/options.c
index 6835352..d619dcf 100644
|
|
static const AVOption options[]={ |
411 | 411 | {"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, 1.0, 0, FLT_MAX, V|E}, |
412 | 412 | {"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, 40, 0, INT_MAX, V|E}, |
413 | 413 | {"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SSIM, INT_MIN, INT_MAX, V|E, "flags2"}, |
| 414 | {"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_ALT_REF, INT_MIN, INT_MAX, V|E, "flags2"}, |
| 415 | {"token_partitions", "Number of sub-streams in bitstream (1,2,4,8). Used for parallelized decoding.", OFFSET(token_partitions), FF_OPT_TYPE_INT, 1, 1, INT_MAX, V|E}, |
414 | 416 | {NULL}, |
415 | 417 | }; |
416 | 418 | |