FFmpeg
Loading...
Searching...
No Matches
video_enc_params.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
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdint.h>
20#include <stdio.h>
21
22#include "libavutil/frame.h"
23#include "libavutil/mem.h"
25
26int main(void)
27{
31 size_t size;
32
33 static const struct {
35 const char *name;
36 } types[] = {
37 { AV_VIDEO_ENC_PARAMS_VP9, "VP9" },
38 { AV_VIDEO_ENC_PARAMS_H264, "H264" },
39 { AV_VIDEO_ENC_PARAMS_MPEG2, "MPEG2" },
40 };
41
42 /* av_video_enc_params_alloc - each type with blocks */
43 printf("Testing av_video_enc_params_alloc()\n");
44 for (int i = 0; i < 3; i++) {
45 par = av_video_enc_params_alloc(types[i].type, 4, &size);
46 if (par) {
47 printf("%s: OK, type=%d, nb_blocks=%u, size>0=%s\n",
48 types[i].name, par->type, par->nb_blocks,
49 size > 0 ? "yes" : "no");
50 av_free(par);
51 } else {
52 printf("%s: FAIL\n", types[i].name);
53 }
54 }
55
56 /* zero blocks */
58 if (par) {
59 printf("zero blocks: OK, nb_blocks=%u\n", par->nb_blocks);
60 av_free(par);
61 } else {
62 printf("zero blocks: FAIL\n");
63 }
64
65 /* alloc without size */
67 printf("alloc (no size): %s\n", par ? "OK" : "FAIL");
68 av_free(par);
69
70 /* av_video_enc_params_block - write and read back */
71 printf("\nTesting av_video_enc_params_block()\n");
73 if (par) {
74 par->qp = 26;
75 par->delta_qp[0][0] = -2;
76 par->delta_qp[0][1] = -1;
77 printf("frame qp=%d, delta_qp[0]={%d,%d}\n",
78 par->qp, par->delta_qp[0][0], par->delta_qp[0][1]);
79
80 for (int i = 0; i < 3; i++) {
82 if ((uint8_t *)block != (uint8_t *)par + par->blocks_offset +
83 (size_t)i * par->block_size)
84 printf("block %d: pointer inconsistent with blocks_offset/block_size\n", i);
85 block->src_x = i * 16;
86 block->src_y = i * 16;
87 block->w = 16;
88 block->h = 16;
89 block->delta_qp = i - 1;
90 }
91 for (int i = 0; i < 3; i++) {
93 printf("block %d: src=(%d,%d) size=%dx%d delta_qp=%d\n",
94 i, block->src_x, block->src_y,
95 block->w, block->h, block->delta_qp);
96 }
97 av_free(par);
98 }
99
100 /* av_video_enc_params_create_side_data */
101 printf("\nTesting av_video_enc_params_create_side_data()\n");
103 if (frame) {
106 if (par) {
107 printf("side_data: OK, type=%d, nb_blocks=%u\n",
108 par->type, par->nb_blocks);
110 block->delta_qp = 5;
112 printf("side_data block 0: delta_qp=%d\n", block->delta_qp);
113 } else {
114 printf("side_data: FAIL\n");
115 }
117 }
118
119 /* NONE type */
120 printf("\nTesting NONE type\n");
122 if (par) {
123 printf("NONE: OK, type=%d\n", par->type);
124 av_free(par);
125 } else {
126 printf("NONE: FAIL\n");
127 }
128
129 return 0;
130}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
static int16_t block[64]
Definition dct.c:125
static AVFrame * frame
reference-counted frame API
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
cl_device_type type
Memory handling functions.
const char * name
Definition qsvenc.c:142
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.
int32_t delta_qp[4][2]
Quantisation parameter offset from the base (per-frame) qp for a given plane (first index) and AC/DC ...
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.
size_t blocks_offset
Offset in bytes from the beginning of this structure at which the array of blocks starts.
#define av_free(p)
int main(void)
int size
AVVideoEncParams * av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type, unsigned int nb_blocks)
Allocates memory for AVEncodeInfoFrame plus an array of nb_blocks AVEncodeInfoBlock in the given AVFr...
AVVideoEncParams * av_video_enc_params_alloc(enum AVVideoEncParamsType type, unsigned int nb_blocks, size_t *out_size)
Allocates memory for AVVideoEncParams of the given type, plus an array of nb_blocks AVVideoBlockParam...
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_NONE
@ AV_VIDEO_ENC_PARAMS_VP9
VP9 stores:
@ AV_VIDEO_ENC_PARAMS_MPEG2
@ AV_VIDEO_ENC_PARAMS_H264
H.264 stores: