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/mem.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 {
46  int64_t ts;
47  uint32_t checksum[4];
49 
50 typedef struct PrivData {
53 
54  int64_t pts_in;
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  for (int j = 0; j < frame->height >> shift_v[p]; j++) {
93  checksum = av_adler32_update(checksum, data, linesize);
94  data += frame->linesize[p];
95  }
96 
97  c->checksum[p] = checksum;
98  }
99 
100  return 0;
101 }
102 
103 static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
104 {
105  AVFrame *f = pd->frame_recon;
106  int ret;
107 
108  ret = avcodec_receive_frame(pd->enc, f);
109  if (ret < 0) {
110  fprintf(stderr, "Error retrieving a reconstructed frame\n");
111  return ret;
112  }
113 
114  // the encoder's internal format (in which the reconsturcted frames are
115  // exported) may be different from the user-facing pixel format
116  if (f->format != pd->enc->pix_fmt) {
117  if (!pd->scaler) {
118  pd->scaler = sws_getContext(f->width, f->height, f->format,
119  f->width, f->height, pd->enc->pix_fmt,
121  if (!pd->scaler)
122  return AVERROR(ENOMEM);
123  }
124 
125  ret = sws_scale_frame(pd->scaler, pd->frame, f);
126  if (ret < 0) {
127  fprintf(stderr, "Error converting pixel formats\n");
128  return ret;
129  }
130 
131  av_frame_unref(f);
132  f = pd->frame;
133  }
134 
136  pkt->pts, f);
137  av_frame_unref(f);
138 
139  return 0;
140 }
141 
143 {
144  PrivData *pd = dc->opaque;
145  int ret;
146 
147  if (!avcodec_is_open(pd->enc)) {
148  if (!frame) {
149  fprintf(stderr, "No input frames were decoded\n");
150  return AVERROR_INVALIDDATA;
151  }
152 
153  pd->enc->width = frame->width;
154  pd->enc->height = frame->height;
155  pd->enc->pix_fmt = frame->format;
156  pd->enc->thread_count = dc->decoder->thread_count;
157  pd->enc->thread_type = dc->decoder->thread_type;
158 
159  // real timestamps do not matter for this test, so we just
160  // pretend the input is 25fps CFR to avoid any timestamp issues
161  pd->enc->time_base = (AVRational){ 1, 25 };
162 
163  ret = avcodec_open2(pd->enc, NULL, NULL);
164  if (ret < 0) {
165  fprintf(stderr, "Error opening the encoder\n");
166  return ret;
167  }
168  }
169 
170  if (frame) {
171  frame->pts = pd->pts_in++;
172 
173  // avoid forcing coded frame type
174  frame->pict_type = AV_PICTURE_TYPE_NONE;
175  }
176 
178  if (ret < 0) {
179  fprintf(stderr, "Error submitting a frame for encoding\n");
180  return ret;
181  }
182 
183  while (1) {
184  AVPacket *pkt = pd->pkt;
185 
187  if (ret == AVERROR(EAGAIN))
188  break;
189  else if (ret == AVERROR_EOF)
190  pkt = NULL;
191  else if (ret < 0) {
192  fprintf(stderr, "Error receiving a frame from the encoder\n");
193  return ret;
194  }
195 
196  if (pkt) {
197  ret = recon_frame_process(pd, pkt);
198  if (ret < 0)
199  return ret;
200  }
201 
202  if (!avcodec_is_open(pd->dec)) {
203  if (!pkt) {
204  fprintf(stderr, "No packets were received from the encoder\n");
205  return AVERROR(EINVAL);
206  }
207 
208  pd->dec->width = pd->enc->width;
209  pd->dec->height = pd->enc->height;
210  pd->dec->pix_fmt = pd->enc->pix_fmt;
211  pd->dec->thread_count = dc->decoder->thread_count;
212  pd->dec->thread_type = dc->decoder->thread_type;
213  if (pd->enc->extradata_size) {
214  pd->dec->extradata = av_memdup(pd->enc->extradata,
216  if (!pd->dec->extradata)
217  return AVERROR(ENOMEM);
218  }
219 
220  ret = avcodec_open2(pd->dec, NULL, NULL);
221  if (ret < 0) {
222  fprintf(stderr, "Error opening the decoder\n");
223  return ret;
224  }
225  }
226 
227  ret = avcodec_send_packet(pd->dec, pkt);
228  if (ret < 0) {
229  fprintf(stderr, "Error sending a packet to decoder\n");
230  return ret;
231  }
232 
233  while (1) {
234  ret = avcodec_receive_frame(pd->dec, pd->frame);
235  if (ret == AVERROR(EAGAIN))
236  break;
237  else if (ret == AVERROR_EOF)
238  return 0;
239  else if (ret < 0) {
240  fprintf(stderr, "Error receving a frame from decoder\n");
241  return ret;
242  }
243 
245  pd->frame->pts, pd->frame);
246  av_frame_unref(pd->frame);
247  if (ret < 0)
248  return ret;
249  }
250 
251  }
252 
253  return 0;
254 }
255 
256 static int frame_checksum_compare(const void *a, const void *b)
257 {
258  const FrameChecksum *ca = a;
259  const FrameChecksum *cb = b;
260  if (ca->ts == cb->ts)
261  return 0;
262  return FFSIGN(ca->ts - cb->ts);
263 }
264 
265 int main(int argc, char **argv)
266 {
267  PrivData pd;
269 
270  const char *filename, *enc_name, *enc_opts, *thread_type = NULL, *nb_threads = NULL;
271  const AVCodec *enc, *dec;
272  int ret = 0, max_frames = 0;
273 
274  if (argc < 4) {
275  fprintf(stderr,
276  "Usage: %s <input file> <encoder> <encoder options> "
277  "[<max frame count> [<thread count> <thread type>]\n",
278  argv[0]);
279  return 0;
280  }
281 
282  filename = argv[1];
283  enc_name = argv[2];
284  enc_opts = argv[3];
285  if (argc >= 5)
286  max_frames = strtol(argv[4], NULL, 0);
287  if (argc >= 6)
288  nb_threads = argv[5];
289  if (argc >= 7)
290  thread_type = argv[6];
291 
292  memset(&dc, 0, sizeof(dc));
293  memset(&pd, 0, sizeof(pd));
294 
296  if (!enc) {
297  fprintf(stderr, "No such encoder: %s\n", enc_name);
298  return 1;
299  }
301  fprintf(stderr, "Encoder '%s' cannot output reconstructed frames\n",
302  enc->name);
303  return 1;
304  }
305 
306  dec = avcodec_find_decoder(enc->id);
307  if (!dec) {
308  fprintf(stderr, "No decoder for: %s\n", avcodec_get_name(enc->id));
309  return 1;
310  }
311 
312  pd.enc = avcodec_alloc_context3(enc);
313  if (!pd.enc) {
314  fprintf(stderr, "Error allocating encoder\n");
315  return 1;
316  }
317 
318  ret = av_set_options_string(pd.enc, enc_opts, "=", ",");
319  if (ret < 0) {
320  fprintf(stderr, "Error setting encoder options\n");
321  goto fail;
322  }
324 
325  pd.dec = avcodec_alloc_context3(dec);
326  if (!pd.dec) {
327  fprintf(stderr, "Error allocating decoder\n");
328  goto fail;
329  }
330 
333 
334  pd.frame = av_frame_alloc();
336  pd.pkt = av_packet_alloc();
337  if (!pd.frame ||!pd.frame_recon || !pd.pkt) {
338  ret = 1;
339  goto fail;
340  }
341 
342  ret = ds_open(&dc, filename, 0);
343  if (ret < 0) {
344  fprintf(stderr, "Error opening the file\n");
345  goto fail;
346  }
347 
348  dc.process_frame = process_frame;
349  dc.opaque = &pd;
350  dc.max_frames = max_frames;
351 
352  ret = av_dict_set(&dc.decoder_opts, "threads", nb_threads, 0);
353  ret |= av_dict_set(&dc.decoder_opts, "thread_type", thread_type, 0);
354 
355  ret = ds_run(&dc);
356  if (ret < 0)
357  goto fail;
358 
360  fprintf(stderr, "Mismatching frame counts: recon=%zu decoded=%zu\n",
362  ret = 1;
363  goto fail;
364  }
365 
366  // reconstructed frames are in coded order, sort them by pts into presentation order
367  qsort(pd.checksums_recon, pd.nb_checksums_recon, sizeof(*pd.checksums_recon),
369 
370  for (size_t i = 0; i < pd.nb_checksums_decoded; i++) {
371  const FrameChecksum *d = &pd.checksums_decoded[i];
372  const FrameChecksum *r = &pd.checksums_recon[i];
373 
374  for (int p = 0; p < FF_ARRAY_ELEMS(d->checksum); p++)
375  if (d->checksum[p] != r->checksum[p]) {
376  fprintf(stderr, "Checksum mismatch in frame ts=%"PRId64", plane %d\n",
377  d->ts, p);
378  ret = 1;
379  goto fail;
380  }
381  }
382  fprintf(stderr, "All %zu encoded frames match\n", pd.nb_checksums_decoded);
383 
384 fail:
389  av_frame_free(&pd.frame);
391  av_packet_free(&pd.pkt);
392  ds_free(&dc);
393  return !!ret;
394 }
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:541
r
const char * r
Definition: vf_curves.c:127
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:246
recon_frame_process
static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
Definition: enc_recon_frame_test.c:103
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
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:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:486
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:343
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:693
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
ds_open
int ds_open(DecodeContext *dc, const char *url, int stream_idx)
Definition: decode_simple.c:119
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
SWS_BITEXACT
#define SWS_BITEXACT
Definition: swscale.h:91
fail
#define fail()
Definition: checkasm.h:182
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1583
FFSIGN
#define FFSIGN(a)
Definition: common.h:74
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:2993
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:256
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:148
pkt
AVPacket * pkt
Definition: movenc.c:60
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:217
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:698
AVCodecContext::thread_type
int thread_type
Which multithreading methods to use.
Definition: avcodec.h:1593
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:1793
process_frame
static int process_frame(DecodeContext *dc, AVFrame *frame)
Definition: enc_recon_frame_test.c:142
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:142
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:964
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
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:2102
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: packet.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:406
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:696
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:1185
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:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:517
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:606
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:508
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
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:264
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:265
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
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
mem.h
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:501
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:108
PrivData::scaler
struct SwsContext * scaler
Definition: enc_recon_frame_test.c:59
d
d
Definition: ffmpeg_filter.c:424
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
imgutils.h
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:301
DecodeContext
Definition: decode.c:57
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:987