FFmpeg
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 
26 int main(void)
27 {
28  AVVideoEncParams *par;
30  AVFrame *frame;
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");
102  frame = av_frame_alloc();
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 }
AVVideoEncParams::qp
int32_t qp
Base quantisation parameter for the frame.
Definition: video_enc_params.h:103
AVVideoEncParams::blocks_offset
size_t blocks_offset
Offset in bytes from the beginning of this structure at which the array of blocks starts.
Definition: video_enc_params.h:86
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
printf
__device__ int printf(const char *,...)
AV_VIDEO_ENC_PARAMS_NONE
@ AV_VIDEO_ENC_PARAMS_NONE
Definition: video_enc_params.h:29
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
av_video_enc_params_alloc
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.
Definition: video_enc_params.c:27
AV_VIDEO_ENC_PARAMS_MPEG2
@ AV_VIDEO_ENC_PARAMS_MPEG2
Definition: video_enc_params.h:65
AVVideoEncParams::delta_qp
int32_t delta_qp[4][2]
Quantisation parameter offset from the base (per-frame) qp for a given plane (first index) and AC/DC ...
Definition: video_enc_params.h:109
AV_VIDEO_ENC_PARAMS_H264
@ AV_VIDEO_ENC_PARAMS_H264
H.264 stores:
Definition: video_enc_params.h:57
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AVVideoEncParams
Video encoding parameters for a given frame.
Definition: video_enc_params.h:73
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AVVideoEncParamsType
AVVideoEncParamsType
Definition: video_enc_params.h:28
AVVideoEncParams::type
enum AVVideoEncParamsType type
Type of the parameters (the codec they are used with).
Definition: video_enc_params.h:95
NULL
#define NULL
Definition: coverity.c:32
AVVideoEncParams::block_size
size_t block_size
Definition: video_enc_params.h:90
av_video_enc_params_create_side_data
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.
Definition: video_enc_params.c:58
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
size
int size
Definition: twinvq_data.h:10344
AVVideoEncParams::nb_blocks
unsigned int nb_blocks
Number of blocks in the array.
Definition: video_enc_params.h:81
frame.h
main
int main(void)
Definition: video_enc_params.c:26
AVVideoBlockParams
Data structure for storing block-level encoding information.
Definition: video_enc_params.h:120
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AV_VIDEO_ENC_PARAMS_VP9
@ AV_VIDEO_ENC_PARAMS_VP9
VP9 stores:
Definition: video_enc_params.h:44
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_video_enc_params_block
static av_always_inline AVVideoBlockParams * av_video_enc_params_block(AVVideoEncParams *par, unsigned int idx)
Get the block at the specified.
Definition: video_enc_params.h:143
video_enc_params.h