FFmpeg
enc_recon_frame_test.c
Go to the documentation of this file.
1 /*
2  * copyright (c) 2022 Anton Khirnov <anton@khirnov.net>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
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
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /* A test for AV_CODEC_FLAG_RECON_FRAME
22  * TODO: dump reconstructed frames to disk */
23 
24 #include <stdio.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 
28 #include "decode_simple.h"
29 
30 #include "libavutil/adler32.h"
31 #include "libavutil/common.h"
32 #include "libavutil/error.h"
33 #include "libavutil/frame.h"
34 #include "libavutil/imgutils.h"
35 #include "libavutil/opt.h"
36 
37 #include "libavformat/avformat.h"
38 
39 #include "libavcodec/avcodec.h"
40 #include "libavcodec/codec.h"
41 
42 #include "libswscale/swscale.h"
43 
44 typedef struct FrameChecksum {
45  int64_t ts;
46  uint32_t checksum[4];
48 
49 typedef struct PrivData {
52 
53  int64_t pts_in;
54 
57 
58  struct SwsContext *scaler;
59 
64 } PrivData;
65 
66 static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts,
67  const AVFrame *frame)
68 {
70  int shift_h[4] = { 0 }, shift_v[4] = { 0 };
71 
72  c = av_realloc_array(*pc, *nb_c + 1, sizeof(*c));
73  if (!c)
74  return AVERROR(ENOMEM);
75  *pc = c;
76  (*nb_c)++;
77 
78  c += *nb_c - 1;
79  memset(c, 0, sizeof(*c));
80 
81  av_pix_fmt_get_chroma_sub_sample(frame->format, &shift_h[1], &shift_v[1]);
82  shift_h[2] = shift_h[1];
83  shift_v[2] = shift_v[1];
84 
85  c->ts = ts;
86  for (int p = 0; frame->data[p]; p++) {
87  const uint8_t *data = frame->data[p];
88  int linesize = av_image_get_linesize(frame->format, frame->width, p);
89  uint32_t checksum = 0;
90 
91  for (int j = 0; j < frame->height >> shift_v[p]; j++) {
92  checksum = av_adler32_update(checksum, data, linesize);
93  data += frame->linesize[p];
94  }
95 
96  c->checksum[p] = checksum;
97  }
98 
99  return 0;
100 }
101 
102 static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
103 {
104  AVFrame *f = pd->frame_recon;
105  int ret;
106 
107  ret = avcodec_receive_frame(pd->enc, f);
108  if (ret < 0) {
109  fprintf(stderr, "Error retrieving a reconstructed frame\n");
110  return ret;
111  }
112 
113  // the encoder's internal format (in which the reconsturcted frames are
114  // exported) may be different from the user-facing pixel format
115  if (f->format != pd->enc->pix_fmt) {
116  if (!pd->scaler) {
117  pd->scaler = sws_getContext(f->width, f->height, f->format,
118  f->width, f->height, pd->enc->pix_fmt,
120  if (!pd->scaler)
121  return AVERROR(ENOMEM);
122  }
123 
124  ret = sws_scale_frame(pd->scaler, pd->frame, f);
125  if (ret < 0) {
126  fprintf(stderr, "Error converting pixel formats\n");
127  return ret;
128  }
129 
130  av_frame_unref(f);
131  f = pd->frame;
132  }
133 
135  pkt->pts, f);
136  av_frame_unref(f);
137 
138  return 0;
139 }
140 
142 {
143  PrivData *pd = dc->opaque;
144  int ret;
145 
146  if (!avcodec_is_open(pd->enc)) {
147  if (!frame) {
148  fprintf(stderr, "No input frames were decoded\n");
149  return AVERROR_INVALIDDATA;
150  }
151 
152  pd->enc->width = frame->width;
153  pd->enc->height = frame->height;
154  pd->enc->pix_fmt = frame->format;
155  pd->enc->thread_count = dc->decoder->thread_count;
156  pd->enc->thread_type = dc->decoder->thread_type;
157 
158  // real timestamps do not matter for this test, so we just
159  // pretend the input is 25fps CFR to avoid any timestamp issues
160  pd->enc->time_base = (AVRational){ 1, 25 };
161 
162  ret = avcodec_open2(pd->enc, NULL, NULL);
163  if (ret < 0) {
164  fprintf(stderr, "Error opening the encoder\n");
165  return ret;
166  }
167  }
168 
169  if (frame) {
170  frame->pts = pd->pts_in++;
171 
172  // avoid forcing coded frame type
174  }
175 
177  if (ret < 0) {
178  fprintf(stderr, "Error submitting a frame for encoding\n");
179  return ret;
180  }
181 
182  while (1) {
183  AVPacket *pkt = pd->pkt;
184 
186  if (ret == AVERROR(EAGAIN))
187  break;
188  else if (ret == AVERROR_EOF)
189  pkt = NULL;
190  else if (ret < 0) {
191  fprintf(stderr, "Error receiving a frame from the encoder\n");
192  return ret;
193  }
194 
195  if (pkt) {
196  ret = recon_frame_process(pd, pkt);
197  if (ret < 0)
198  return ret;
199  }
200 
201  if (!avcodec_is_open(pd->dec)) {
202  if (!pkt) {
203  fprintf(stderr, "No packets were received from the encoder\n");
204  return AVERROR(EINVAL);
205  }
206 
207  pd->dec->width = pd->enc->width;
208  pd->dec->height = pd->enc->height;
209  pd->dec->pix_fmt = pd->enc->pix_fmt;
210  pd->dec->thread_count = dc->decoder->thread_count;
211  pd->dec->thread_type = dc->decoder->thread_type;
212  if (pd->enc->extradata_size) {
213  pd->dec->extradata = av_memdup(pd->enc->extradata,
215  if (!pd->dec->extradata)
216  return AVERROR(ENOMEM);
217  }
218 
219  ret = avcodec_open2(pd->dec, NULL, NULL);
220  if (ret < 0) {
221  fprintf(stderr, "Error opening the decoder\n");
222  return ret;
223  }
224  }
225 
226  ret = avcodec_send_packet(pd->dec, pkt);
227  if (ret < 0) {
228  fprintf(stderr, "Error sending a packet to decoder\n");
229  return ret;
230  }
231 
232  while (1) {
233  ret = avcodec_receive_frame(pd->dec, pd->frame);
234  if (ret == AVERROR(EAGAIN))
235  break;
236  else if (ret == AVERROR_EOF)
237  return 0;
238  else if (ret < 0) {
239  fprintf(stderr, "Error receving a frame from decoder\n");
240  return ret;
241  }
242 
244  pd->frame->pts, pd->frame);
245  av_frame_unref(pd->frame);
246  if (ret < 0)
247  return ret;
248  }
249 
250  }
251 
252  return 0;
253 }
254 
255 static int frame_checksum_compare(const void *a, const void *b)
256 {
257  const FrameChecksum *ca = a;
258  const FrameChecksum *cb = b;
259  if (ca->ts == cb->ts)
260  return 0;
261  return FFSIGN(ca->ts - cb->ts);
262 }
263 
264 int main(int argc, char **argv)
265 {
266  PrivData pd;
268 
269  const char *filename, *enc_name, *enc_opts, *thread_type = NULL, *nb_threads = NULL;
270  const AVCodec *enc, *dec;
271  int ret = 0, max_frames = 0;
272 
273  if (argc < 4) {
274  fprintf(stderr,
275  "Usage: %s <input file> <encoder> <encoder options> "
276  "[<max frame count> [<thread count> <thread type>]\n",
277  argv[0]);
278  return 0;
279  }
280 
281  filename = argv[1];
282  enc_name = argv[2];
283  enc_opts = argv[3];
284  if (argc >= 5)
285  max_frames = strtol(argv[4], NULL, 0);
286  if (argc >= 6)
287  nb_threads = argv[5];
288  if (argc >= 7)
289  thread_type = argv[6];
290 
291  memset(&dc, 0, sizeof(dc));
292  memset(&pd, 0, sizeof(pd));
293 
295  if (!enc) {
296  fprintf(stderr, "No such encoder: %s\n", enc_name);
297  return 1;
298  }
300  fprintf(stderr, "Encoder '%s' cannot ouput reconstructed frames\n",
301  enc->name);
302  return 1;
303  }
304 
305  dec = avcodec_find_decoder(enc->id);
306  if (!dec) {
307  fprintf(stderr, "No decoder for: %s\n", avcodec_get_name(enc->id));
308  return 1;
309  }
310 
311  pd.enc = avcodec_alloc_context3(enc);
312  if (!pd.enc) {
313  fprintf(stderr, "Error allocating encoder\n");
314  return 1;
315  }
316 
317  ret = av_set_options_string(pd.enc, enc_opts, "=", ",");
318  if (ret < 0) {
319  fprintf(stderr, "Error setting encoder options\n");
320  goto fail;
321  }
323 
324  pd.dec = avcodec_alloc_context3(dec);
325  if (!pd.dec) {
326  fprintf(stderr, "Error allocating decoder\n");
327  goto fail;
328  }
329 
332 
333  pd.frame = av_frame_alloc();
335  pd.pkt = av_packet_alloc();
336  if (!pd.frame ||!pd.frame_recon || !pd.pkt) {
337  ret = 1;
338  goto fail;
339  }
340 
341  ret = ds_open(&dc, filename, 0);
342  if (ret < 0) {
343  fprintf(stderr, "Error opening the file\n");
344  goto fail;
345  }
346 
347  dc.process_frame = process_frame;
348  dc.opaque = &pd;
349  dc.max_frames = max_frames;
350 
351  ret = av_dict_set(&dc.decoder_opts, "threads", nb_threads, 0);
352  ret |= av_dict_set(&dc.decoder_opts, "thread_type", thread_type, 0);
353 
354  ret = ds_run(&dc);
355  if (ret < 0)
356  goto fail;
357 
359  fprintf(stderr, "Mismatching frame counts: recon=%zu decoded=%zu\n",
361  ret = 1;
362  goto fail;
363  }
364 
365  // reconstructed frames are in coded order, sort them by pts into presentation order
366  qsort(pd.checksums_recon, pd.nb_checksums_recon, sizeof(*pd.checksums_recon),
368 
369  for (size_t i = 0; i < pd.nb_checksums_decoded; i++) {
370  const FrameChecksum *d = &pd.checksums_decoded[i];
371  const FrameChecksum *r = &pd.checksums_recon[i];
372 
373  for (int p = 0; p < FF_ARRAY_ELEMS(d->checksum); p++)
374  if (d->checksum[p] != r->checksum[p]) {
375  fprintf(stderr, "Checksum mismatch in frame ts=%"PRId64", plane %d\n",
376  d->ts, p);
377  ret = 1;
378  goto fail;
379  }
380  }
381  fprintf(stderr, "All %zu encoded frames match\n", pd.nb_checksums_decoded);
382 
383 fail:
388  av_frame_free(&pd.frame);
390  av_packet_free(&pd.pkt);
391  ds_free(&dc);
392  return !!ret;
393 }
AVCodec
AVCodec.
Definition: codec.h:187
avcodec_receive_packet
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Definition: encode.c:556
r
const char * r
Definition: vf_curves.c:126
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:241
recon_frame_process
static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
Definition: enc_recon_frame_test.c:102
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1412
AV_CODEC_CAP_ENCODER_RECON_FRAME
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
Definition: codec.h:174
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
AVFrame::width
int width
Definition: frame.h:412
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:206
PrivData::pts_in
int64_t pts_in
Definition: enc_recon_frame_test.c:53
enc_name
const char enc_name[6]
Definition: rtp.c:36
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:148
SwsContext::nb_threads
int nb_threads
Number of threads used for scaling.
Definition: swscale_internal.h:341
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:708
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:74
ds_open
int ds_open(DecodeContext *dc, const char *url, int stream_idx)
Definition: decode_simple.c:119
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
av_set_options_string
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
Definition: opt.c:1587
SWS_BITEXACT
#define SWS_BITEXACT
Definition: swscale.h:91
fail
#define fail()
Definition: checkasm.h:138
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1532
FFSIGN
#define FFSIGN(a)
Definition: common.h:66
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
av_pix_fmt_get_chroma_sub_sample
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2992
PrivData::dec
AVCodecContext * dec
Definition: enc_recon_frame_test.c:51
frame_checksum_compare
static int frame_checksum_compare(const void *a, const void *b)
Definition: enc_recon_frame_test.c:255
codec.h
ds_run
int ds_run(DecodeContext *dc)
Definition: decode_simple.c:65
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:88
pkt
AVPacket * pkt
Definition: movenc.c:59
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:543
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:153
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
avcodec_receive_frame
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
Definition: avcodec.c:713
AVCodecContext::thread_type
int thread_type
Which multithreading methods to use.
Definition: avcodec.h:1542
process_frame
static int process_frame(DecodeContext *dc, AVFrame *frame)
Definition: enc_recon_frame_test.c:141
frame
static AVFrame * frame
Definition: demux_decode.c:54
frame_hash
static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts, const AVFrame *frame)
Definition: enc_recon_frame_test.c:66
NULL
#define NULL
Definition: coverity.c:32
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:168
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
adler32.h
avcodec_open2
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: avcodec.c:128
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
FrameChecksum
Definition: enc_recon_frame_test.c:44
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
FrameChecksum::checksum
uint32_t checksum[4]
Definition: enc_recon_frame_test.c:46
av_adler32_update
AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)
Calculate the Adler32 checksum of a buffer.
Definition: adler32.c:44
error.h
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:975
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:563
f
f
Definition: af_crystalizer.c:121
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:442
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
sws_getContext
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:2096
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
AV_PICTURE_TYPE_NONE
@ AV_PICTURE_TYPE_NONE
Undefined.
Definition: avutil.h:278
frame.h
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:63
PrivData::checksums_recon
FrameChecksum * checksums_recon
Definition: enc_recon_frame_test.c:62
AVCodec::id
enum AVCodecID id
Definition: codec.h:201
av_image_get_linesize
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
Definition: imgutils.c:76
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:417
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:709
sws_scale_frame
int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
Definition: swscale.c:1184
AV_CODEC_FLAG_RECON_FRAME
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding th...
Definition: avcodec.h:260
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:484
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:542
common.h
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:622
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCodecContext::height
int height
Definition: avcodec.h:621
avcodec_send_frame
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
Definition: encode.c:518
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:658
avcodec.h
ret
ret
Definition: filter_design.txt:187
avformat.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
main
int main(int argc, char **argv)
Definition: enc_recon_frame_test.c:264
AVCodecContext
main external API structure.
Definition: avcodec.h:441
PrivData::nb_checksums_recon
size_t nb_checksums_recon
Definition: enc_recon_frame_test.c:63
AVFrame::height
int height
Definition: frame.h:412
PrivData::checksums_decoded
FrameChecksum * checksums_decoded
Definition: enc_recon_frame_test.c:60
PrivData
Definition: enc_recon_frame_test.c:49
PrivData::pkt
AVPacket * pkt
Definition: enc_recon_frame_test.c:55
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:338
PrivData::enc
AVCodecContext * enc
Definition: enc_recon_frame_test.c:50
AVPacket
This structure stores compressed data.
Definition: packet.h:468
PrivData::nb_checksums_decoded
size_t nb_checksums_decoded
Definition: enc_recon_frame_test.c:61
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
PrivData::frame
AVFrame * frame
Definition: enc_recon_frame_test.c:56
ds_free
void ds_free(DecodeContext *dc)
Definition: decode_simple.c:108
PrivData::scaler
struct SwsContext * scaler
Definition: enc_recon_frame_test.c:58
d
d
Definition: ffmpeg_filter.c:368
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
decode_simple.h
FrameChecksum::ts
int64_t ts
Definition: enc_recon_frame_test.c:45
PrivData::frame_recon
AVFrame * frame_recon
Definition: enc_recon_frame_test.c:56
SwsContext
Definition: swscale_internal.h:299
DecodeContext
Definition: decode.c:53
swscale.h
avcodec_find_encoder_by_name
const AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: allcodecs.c:998