2
2
* Copyright (c) 2010, Google, Inc.
4
* This file is part of FFmpeg.
4
* This file is part of Libav.
6
* FFmpeg is free software; you can redistribute it and/or
6
* Libav is free software; you can redistribute it and/or
7
7
* modify it under the terms of the GNU Lesser General Public
8
8
* License as published by the Free Software Foundation; either
9
9
* version 2.1 of the License, or (at your option) any later version.
11
* FFmpeg is distributed in the hope that it will be useful,
11
* Libav is distributed in the hope that it will be useful,
12
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
14
* Lesser General Public License for more details.
16
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with FFmpeg; if not, write to the Free Software
17
* License along with Libav; if not, write to the Free Software
18
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36
36
* One encoded frame returned from the library.
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
42
(in timebase units) */
43
unsigned long duration; /**≤ duration to show frame
44
(in timebase units) */
45
uint32_t flags; /**≤ flags for this 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
(in timebase units) */
43
unsigned long duration; /**< duration to show frame
44
(in timebase units) */
45
uint32_t flags; /**< flags for this frame */
46
46
struct FrameListData *next;
237
237
enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
238
238
AV_ROUND_NEAR_INF);
240
//convert [1,51] -> [0,63]
241
enccfg.rc_min_quantizer = ((avctx->qmin * 5 + 1) >> 2) - 1;
242
enccfg.rc_max_quantizer = ((avctx->qmax * 5 + 1) >> 2) - 1;
240
enccfg.rc_min_quantizer = avctx->qmin;
241
enccfg.rc_max_quantizer = avctx->qmax;
242
enccfg.rc_dropframe_thresh = avctx->frame_skip_threshold;
244
//0-100 (0 => CBR, 100 => VBR)
245
enccfg.rc_2pass_vbr_bias_pct = round(avctx->qcompress * 100);
246
enccfg.rc_2pass_vbr_minsection_pct =
247
avctx->rc_min_rate * 100LL / avctx->bit_rate;
248
if (avctx->rc_max_rate)
249
enccfg.rc_2pass_vbr_maxsection_pct =
250
avctx->rc_max_rate * 100LL / avctx->bit_rate;
252
if (avctx->rc_buffer_size)
254
avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
255
if (avctx->rc_initial_buffer_occupancy)
256
enccfg.rc_buf_initial_sz =
257
avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
258
enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
260
//_enc_init() will balk if kf_min_dist differs from max w/VPX_KF_AUTO
244
261
if (avctx->keyint_min == avctx->gop_size)
245
enccfg.kf_mode = VPX_KF_FIXED;
246
//_enc_init() will balk if kf_min_dist is set in this case
247
if (enccfg.kf_mode != VPX_KF_AUTO)
248
262
enccfg.kf_min_dist = avctx->keyint_min;
249
263
enccfg.kf_max_dist = avctx->gop_size;
280
294
ctx->deadline = VPX_DL_GOOD_QUALITY;
295
/* 0-3: For non-zero values the encoder increasingly optimizes for reduced
296
complexity playback on low powered devices at the expense of encode
298
if (avctx->profile != FF_PROFILE_UNKNOWN)
299
enccfg.g_profile = avctx->profile;
282
301
dump_enc_cfg(avctx, &enccfg);
283
302
/* Construct Encoder Context */
291
310
av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n");
292
311
codecctl_int(avctx, VP8E_SET_CPUUSED, cpuused);
293
312
codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction);
313
codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices));
295
315
//provide dummy value to initialize wrapper, values will be updated each _encode()
296
316
vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
460
480
coded_size = queue_frames(avctx, buf, buf_size, avctx->coded_frame);
462
482
if (!frame && avctx->flags & CODEC_FLAG_PASS1) {
463
unsigned int b64_size = ((ctx->twopass_stats.sz + 2) / 3) * 4 + 1;
483
unsigned int b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);
465
485
avctx->stats_out = av_malloc(b64_size);
466
486
if (!avctx->stats_out) {