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/avassert.h"
32 #include "libavutil/common.h"
33 #include "libavutil/error.h"
34 #include "libavutil/frame.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/opt.h"
37 
38 #include "libavformat/avformat.h"
39 
40 #include "libavcodec/avcodec.h"
41 #include "libavcodec/codec.h"
42 
43 #include "libswscale/swscale.h"
44 
45 typedef struct FrameChecksum {
47  uint32_t checksum[4];
49 
50 typedef struct PrivData {
53 
55 
58 
59  struct SwsContext *scaler;
60 
65 } PrivData;
66 
67 static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts,
68  const AVFrame *frame)
69 {
71  int shift_h[4] = { 0 }, shift_v[4] = { 0 };
72 
73  c = av_realloc_array(*pc, *nb_c + 1, sizeof(*c));
74  if (!c)
75  return AVERROR(ENOMEM);
76  *pc = c;
77  (*nb_c)++;
78 
79  c += *nb_c - 1;
80  memset(c, 0, sizeof(*c));
81 
82  av_pix_fmt_get_chroma_sub_sample(frame->format, &shift_h[1], &shift_v[1]);
83  shift_h[2] = shift_h[1];
84  shift_v[2] = shift_v[1];
85 
86  c->ts = ts;
87  for (int p = 0; frame->data[p]; p++) {
88  const uint8_t *data = frame->data[p];
89  int linesize = av_image_get_linesize(frame->format, frame->width, p);
90  uint32_t checksum = 0;
91 
92  av_assert0(linesize >= 0);
93 
94  for (int j = 0; j < frame->height >> shift_v[p]; j++) {
95  checksum = av_adler32_update(checksum, data, linesize);
96  data += frame->linesize[p];
97  }
98 
99  c->checksum[p] = checksum;
100  }
101 
102  return 0;
103 }
104 
105 static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
106 {
107  AVFrame *f = pd->frame_recon;
108  int ret;
109 
110  ret = avcodec_receive_frame(pd->enc, f);
111  if (ret < 0) {
112  fprintf(stderr, "Error retrieving a reconstructed frame\n");
113  return ret;
114  }
115 
116  // the encoder's internal format (in which the reconsturcted frames are
117  // exported) may be different from the user-facing pixel format
118  if (f->format != pd->enc->pix_fmt) {
119  if (!pd->scaler) {
120  pd->scaler = sws_getContext(f->width, f->height, f->format,
121  f->width, f->height, pd->enc->pix_fmt,
123  if (!pd->scaler)
124  return AVERROR(ENOMEM);
125  }
126 
127  ret = sws_scale_frame(pd->scaler, pd->frame, f);
128  if (ret < 0) {
129  fprintf(stderr, "Error converting pixel formats\n");
130  return ret;
131  }
132 
133  av_frame_unref(f);
134  f = pd->frame;
135  }
136 
138  pkt->pts, f);
139  av_frame_unref(f);
140 
141  return 0;
142 }
143 
145 {
146  PrivData *pd = dc->opaque;
147  int ret;
148 
149  if (!avcodec_is_open(pd->enc)) {
150  if (!frame) {
151  fprintf(stderr, "No input frames were decoded\n");
152  return AVERROR_INVALIDDATA;
153  }
154 
155  pd->enc->width = frame->width;
156  pd->enc->height = frame->height;
157  pd->enc->pix_fmt = frame->format;
158  pd->enc->thread_count = dc->decoder->thread_count;
159  pd->enc->thread_type = dc->decoder->thread_type;
160 
161  // real timestamps do not matter for this test, so we just
162  // pretend the input is 25fps CFR to avoid any timestamp issues
163  pd->enc->time_base = (AVRational){ 1, 25 };
164 
165  ret = avcodec_open2(pd->enc, NULL, NULL);
166  if (ret < 0) {
167  fprintf(stderr, "Error opening the encoder\n");
168  return ret;
169  }
170  }
171 
172  if (frame) {
173  frame->pts = pd->pts_in++;
174 
175  // avoid forcing coded frame type
177  }
178 
180  if (ret < 0) {
181  fprintf(stderr, "Error submitting a frame for encoding\n");
182  return ret;
183  }
184 
185  while (1) {
186  AVPacket *pkt = pd->pkt;
187 
189  if (ret == AVERROR(EAGAIN))
190  break;
191  else if (ret == AVERROR_EOF)
192  pkt = NULL;
193  else if (ret < 0) {
194  fprintf(stderr, "Error receiving a frame from the encoder\n");
195  return ret;
196  }
197 
198  if (pkt) {
199  ret = recon_frame_process(pd, pkt);
200  if (ret < 0)
201  return ret;
202  }
203 
204  if (!avcodec_is_open(pd->dec)) {
205  if (!pkt) {
206  fprintf(stderr, "No packets were received from the encoder\n");
207  return AVERROR(EINVAL);
208  }
209 
210  pd->dec->width = pd->enc->width;
211  pd->dec->height = pd->enc->height;
212  pd->dec->pix_fmt = pd->enc->pix_fmt;
213  pd->dec->thread_count = dc->decoder->thread_count;
214  pd->dec->thread_type = dc->decoder->thread_type;
215  if (pd->enc->extradata_size) {
216  pd->dec->extradata = av_memdup(pd->enc->extradata,
218  if (!pd->dec->extradata)
219  return AVERROR(ENOMEM);
220  }
221 
222  ret = avcodec_open2(pd->dec, NULL, NULL);
223  if (ret < 0) {
224  fprintf(stderr, "Error opening the decoder\n");
225  return ret;
226  }
227  }
228 
229  ret = avcodec_send_packet(pd->dec, pkt);
230  if (ret < 0) {
231  fprintf(stderr, "Error sending a packet to decoder\n");
232  return ret;
233  }
234 
235  while (1) {
236  ret = avcodec_receive_frame(pd->dec, pd->frame);
237  if (ret == AVERROR(EAGAIN))
238  break;
239  else if (ret == AVERROR_EOF)
240  return 0;
241  else if (ret < 0) {
242  fprintf(stderr, "Error receving a frame from decoder\n");
243  return ret;
244  }
245 
247  pd->frame->pts, pd->frame);
248  av_frame_unref(pd->frame);
249  if (ret < 0)
250  return ret;
251  }
252 
253  }
254 
255  return 0;
256 }
257 
258 static int frame_checksum_compare(const void *a, const void *b)
259 {
260  const FrameChecksum *ca = a;
261  const FrameChecksum *cb = b;
262  if (ca->ts == cb->ts)
263  return 0;
264  return FFSIGN(ca->ts - cb->ts);
265 }
266 
267 int main(int argc, char **argv)
268 {
269  PrivData pd;
271 
272  const char *filename, *enc_name, *enc_opts, *thread_type = NULL, *nb_threads = NULL;
273  const AVCodec *enc, *dec;
274  int ret = 0, max_frames = 0;
275 
276  if (argc < 4) {
277  fprintf(stderr,
278  "Usage: %s <input file> <encoder> <encoder options> "
279  "[<max frame count> [<thread count> <thread type>]\n",
280  argv[0]);
281  return 0;
282  }
283 
284  filename = argv[1];
285  enc_name = argv[2];
286  enc_opts = argv[3];
287  if (argc >= 5)
288  max_frames = strtol(argv[4], NULL, 0);
289  if (argc >= 6)
290  nb_threads = argv[5];
291  if (argc >= 7)
292  thread_type = argv[6];
293 
294  memset(&dc, 0, sizeof(dc));
295  memset(&pd, 0, sizeof(pd));
296 
298  if (!enc) {
299  fprintf(stderr, "No such encoder: %s\n", enc_name);
300  return 1;
301  }
303  fprintf(stderr, "Encoder '%s' cannot output reconstructed frames\n",
304  enc->name);
305  return 1;
306  }
307 
308  dec = avcodec_find_decoder(enc->id);
309  if (!dec) {
310  fprintf(stderr, "No decoder for: %s\n", avcodec_get_name(enc->id));
311  return 1;
312  }
313 
314  pd.enc = avcodec_alloc_context3(enc);
315  if (!pd.enc) {
316  fprintf(stderr, "Error allocating encoder\n");
317  return 1;
318  }
319 
320  ret = av_set_options_string(pd.enc, enc_opts, "=", ",");
321  if (ret < 0) {
322  fprintf(stderr, "Error setting encoder options\n");
323  goto fail;
324  }
326 
327  pd.dec = avcodec_alloc_context3(dec);
328  if (!pd.dec) {
329  fprintf(stderr, "Error allocating decoder\n");
330  goto fail;
331  }
332 
335 
336  pd.frame = av_frame_alloc();
338  pd.pkt = av_packet_alloc();
339  if (!pd.frame ||!pd.frame_recon || !pd.pkt) {
340  ret = 1;
341  goto fail;
342  }
343 
344  ret = ds_open(&dc, filename, 0);
345  if (ret < 0) {
346  fprintf(stderr, "Error opening the file\n");
347  goto fail;
348  }
349 
350  dc.process_frame = process_frame;
351  dc.opaque = &pd;
352  dc.max_frames = max_frames;
353 
354  ret = av_dict_set(&dc.decoder_opts, "threads", nb_threads, 0);
355  ret |= av_dict_set(&dc.decoder_opts, "thread_type", thread_type, 0);
356 
357  ret = ds_run(&dc);
358  if (ret < 0)
359  goto fail;
360 
362  fprintf(stderr, "Mismatching frame counts: recon=%zu decoded=%zu\n",
364  ret = 1;
365  goto fail;
366  }
367 
368  // reconstructed frames are in coded order, sort them by pts into presentation order
369  qsort(pd.checksums_recon, pd.nb_checksums_recon, sizeof(*pd.checksums_recon),
371 
372  for (size_t i = 0; i < pd.nb_checksums_decoded; i++) {
373  const FrameChecksum *d = &pd.checksums_decoded[i];
374  const FrameChecksum *r = &pd.checksums_recon[i];
375 
376  for (int p = 0; p < FF_ARRAY_ELEMS(d->checksum); p++)
377  if (d->checksum[p] != r->checksum[p]) {
378  fprintf(stderr, "Checksum mismatch in frame ts=%"PRId64", plane %d\n",
379  d->ts, p);
380  ret = 1;
381  goto fail;
382  }
383  }
384  fprintf(stderr, "All %zu encoded frames match\n", pd.nb_checksums_decoded);
385 
386 fail:
391  av_frame_free(&pd.frame);
393  av_packet_free(&pd.pkt);
394  ds_free(&dc);
395  return !!ret;
396 }
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:540
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:105
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:1420
int64_t
long long int64_t
Definition: coverity.c:34
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:130
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:456
AVFrame::width
int width
Definition: frame.h:416
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:206
PrivData::pts_in
int64_t pts_in
Definition: enc_recon_frame_test.c:54
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:676
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:120
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
SWS_BITEXACT
#define SWS_BITEXACT
Definition: swscale.h:91
fail
#define fail()
Definition: checkasm.h:179
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1582
FFSIGN
#define FFSIGN(a)
Definition: common.h:73
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
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:2990
PrivData::dec
AVCodecContext * dec
Definition: enc_recon_frame_test.c:52
frame_checksum_compare
static int frame_checksum_compare(const void *a, const void *b)
Definition: enc_recon_frame_test.c:258
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:118
avassert.h
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:524
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
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:681
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVCodecContext::thread_type
int thread_type
Which multithreading methods to use.
Definition: avcodec.h:1592
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:1776
process_frame
static int process_frame(DecodeContext *dc, AVFrame *frame)
Definition: enc_recon_frame_test.c:144
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:67
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:164
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:45
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:47
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:971
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:544
f
f
Definition: af_crystalizer.c:121
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:446
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:2094
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:431
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:63
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:409
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:675
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:264
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:515
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
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:576
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCodecContext::height
int height
Definition: avcodec.h:618
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:507
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
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:267
AVCodecContext
main external API structure.
Definition: avcodec.h:445
PrivData::nb_checksums_recon
size_t nb_checksums_recon
Definition: enc_recon_frame_test.c:64
AVFrame::height
int height
Definition: frame.h:416
PrivData::checksums_decoded
FrameChecksum * checksums_decoded
Definition: enc_recon_frame_test.c:61
PrivData
Definition: enc_recon_frame_test.c:50
PrivData::pkt
AVPacket * pkt
Definition: enc_recon_frame_test.c:56
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:342
PrivData::enc
AVCodecContext * enc
Definition: enc_recon_frame_test.c:51
AVPacket
This structure stores compressed data.
Definition: packet.h:499
PrivData::nb_checksums_decoded
size_t nb_checksums_decoded
Definition: enc_recon_frame_test.c:62
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:57
ds_free
void ds_free(DecodeContext *dc)
Definition: decode_simple.c:109
PrivData::scaler
struct SwsContext * scaler
Definition: enc_recon_frame_test.c:59
d
d
Definition: ffmpeg_filter.c:409
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
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:389
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:46
PrivData::frame_recon
AVFrame * frame_recon
Definition: enc_recon_frame_test.c:57
SwsContext
Definition: swscale_internal.h:299
DecodeContext
Definition: decode.c:54
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:994