FFmpeg
Loading...
Searching...
No Matches
qp_table.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <stdint.h>
20
21#include "libavutil/frame.h"
22#include "libavutil/mem.h"
24
25#include "qp_table.h"
26
27int ff_qp_table_extract(AVFrame *frame, int8_t **table, int *table_w, int *table_h,
28 enum AVVideoEncParamsType *qscale_type)
29{
32 unsigned int mb_h = (frame->height + 15) / 16;
33 unsigned int mb_w = (frame->width + 15) / 16;
34 unsigned int nb_mb = mb_h * mb_w;
35 unsigned int block_idx;
36
37 *table = NULL;
38
40 if (!sd)
41 return 0;
42 par = (AVVideoEncParams *)sd->data;
43 if ((par->type != AV_VIDEO_ENC_PARAMS_MPEG2 &&
45 (par->nb_blocks != 0 && par->nb_blocks != nb_mb))
46 return AVERROR(ENOSYS);
47
48 *table = av_malloc(nb_mb);
49 if (!*table)
50 return AVERROR(ENOMEM);
51 if (table_w)
52 *table_w = mb_w;
53 if (table_h)
54 *table_h = mb_h;
55 if (qscale_type)
56 *qscale_type = par->type;
57
58 if (par->nb_blocks == 0) {
59 memset(*table, par->qp, nb_mb);
60 return 0;
61 }
62
63 for (block_idx = 0; block_idx < nb_mb; block_idx++) {
65 (*table)[block_idx] = par->qp + b->delta_qp;
66 }
67
68 return 0;
69}
#define NULL
Definition coverity.c:32
static AVFrame * frame
reference-counted frame API
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
@ AV_FRAME_DATA_VIDEO_ENC_PARAMS
Encoding parameters for a video frame, as described by AVVideoEncParams.
Definition frame.h:170
#define b
Definition input.c:43
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
static const uint16_t table[]
Definition prosumer.c:203
int ff_qp_table_extract(AVFrame *frame, int8_t **table, int *table_w, int *table_h, enum AVVideoEncParamsType *qscale_type)
Extract a libpostproc-compatible QP table - an 8-bit QP value per 16x16 macroblock,...
Definition qp_table.c:27
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
Data structure for storing block-level encoding information.
Video encoding parameters for a given frame.
enum AVVideoEncParamsType type
Type of the parameters (the codec they are used with).
unsigned int nb_blocks
Number of blocks in the array.
int32_t qp
Base quantisation parameter for the frame.
static av_always_inline AVVideoBlockParams * av_video_enc_params_block(AVVideoEncParams *par, unsigned int idx)
Get the block at the specified idx.
AVVideoEncParamsType
@ AV_VIDEO_ENC_PARAMS_MPEG2
@ AV_VIDEO_ENC_PARAMS_H264
H.264 stores: