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/mem.h"
37 #include "libavutil/opt.h"
38 
39 #include "libavformat/avformat.h"
40 
41 #include "libavcodec/avcodec.h"
42 #include "libavcodec/codec.h"
43 
44 #include "libswscale/swscale.h"
45 
46 typedef struct FrameChecksum {
48  uint32_t checksum[4];
50 
51 typedef struct PrivData {
54 
56 
59 
60  struct SwsContext *scaler;
61 
66 } PrivData;
67 
68 static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts,
69  const AVFrame *frame)
70 {
72  int shift_h[4] = { 0 }, shift_v[4] = { 0 };
73 
74  c = av_realloc_array(*pc, *nb_c + 1, sizeof(*c));
75  if (!c)
76  return AVERROR(ENOMEM);
77  *pc = c;
78  (*nb_c)++;
79 
80  c += *nb_c - 1;
81  memset(c, 0, sizeof(*c));
82 
83  av_pix_fmt_get_chroma_sub_sample(frame->format, &shift_h[1], &shift_v[1]);
84  shift_h[2] = shift_h[1];
85  shift_v[2] = shift_v[1];
86 
87  c->ts = ts;
88  for (int p = 0; frame->data[p]; p++) {
89  const uint8_t *data = frame->data[p];
90  int linesize = av_image_get_linesize(frame->format, frame->width, p);
91  uint32_t checksum = 0;
92 
93  av_assert0(linesize >= 0);
94 
95  for (int j = 0; j < frame->height >> shift_v[p]; j++) {
96  checksum = av_adler32_update(checksum, data, linesize);
97  data += frame->linesize[p];
98  }
99 
100  c->checksum[p] = checksum;
101  }
102 
103  return 0;
104 }
105 
106 static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
107 {
108  AVFrame *f = pd->frame_recon;
109  int ret;
110 
111  ret = avcodec_receive_frame(pd->enc, f);
112  if (ret < 0) {
113  fprintf(stderr, "Error retrieving a reconstructed frame\n");
114  return ret;
115  }
116 
117  // the encoder's internal format (in which the reconsturcted frames are
118  // exported) may be different from the user-facing pixel format
119  if (f->format != pd->enc->pix_fmt) {
120  if (!pd->scaler) {
121  pd->scaler = sws_getContext(f->width, f->height, f->format,
122  f->width, f->height, pd->enc->pix_fmt,
124  if (!pd->scaler)
125  return AVERROR(ENOMEM);
126  }
127 
128  ret = sws_scale_frame(pd->scaler, pd->frame, f);
129  if (ret < 0) {
130  fprintf(stderr, "Error converting pixel formats\n");
131  return ret;
132  }
133 
134  av_frame_unref(f);
135  f = pd->frame;
136  }
137 
139  pkt->pts, f);
140  av_frame_unref(f);
141 
142  return 0;
143 }
144 
146 {
147  PrivData *pd = dc->opaque;
148  int ret;
149 
150  if (!avcodec_is_open(pd->enc)) {
151  if (!frame) {
152  fprintf(stderr, "No input frames were decoded\n");
153  return AVERROR_INVALIDDATA;
154  }
155 
156  pd->enc->width = frame->width;
157  pd->enc->height = frame->height;
158  pd->enc->pix_fmt = frame->format;
159  pd->enc->thread_count = dc->decoder->thread_count;
160  pd->enc->thread_type = dc->decoder->thread_type;
161 
162  // real timestamps do not matter for this test, so we just
163  // pretend the input is 25fps CFR to avoid any timestamp issues
164  pd->enc->time_base = (AVRational){ 1, 25 };
165 
166  ret = avcodec_open2(pd->enc, NULL, NULL);
167  if (ret < 0) {
168  fprintf(stderr, "Error opening the encoder\n");
169  return ret;
170  }
171  }
172 
173  if (frame) {
174  frame->pts = pd->pts_in++;
175 
176  // avoid forcing coded frame type
177  frame->pict_type = AV_PICTURE_TYPE_NONE;
178  }
179 
181  if (ret < 0) {
182  fprintf(stderr, "Error submitting a frame for encoding\n");
183  return ret;
184  }
185 
186  while (1) {
187  AVPacket *pkt = pd->pkt;
188 
190  if (ret == AVERROR(EAGAIN))
191  break;
192  else if (ret == AVERROR_EOF)
193  pkt = NULL;
194  else if (ret < 0) {
195  fprintf(stderr, "Error receiving a frame from the encoder\n");
196  return ret;
197  }
198 
199  if (pkt) {
200  ret = recon_frame_process(pd, pkt);
201  if (ret < 0)
202  return ret;
203  }
204 
205  if (!avcodec_is_open(pd->dec)) {
206  if (!pkt) {
207  fprintf(stderr, "No packets were received from the encoder\n");
208  return AVERROR(EINVAL);
209  }
210 
211  pd->dec->width = pd->enc->width;
212  pd->dec->height = pd->enc->height;
213  pd->dec->pix_fmt = pd->enc->pix_fmt;
214  pd->dec->thread_count = dc->decoder->thread_count;
215  pd->dec->thread_type = dc->decoder->thread_type;
216  if (pd->enc->extradata_size) {
217  pd->dec->extradata = av_memdup(pd->enc->extradata,
219  if (!pd->dec->extradata)
220  return AVERROR(ENOMEM);
221  }
222 
223  ret = avcodec_open2(pd->dec, NULL, NULL);
224  if (ret < 0) {
225  fprintf(stderr, "Error opening the decoder\n");
226  return ret;
227  }
228  }
229 
230  ret = avcodec_send_packet(pd->dec, pkt);
231  if (ret < 0) {
232  fprintf(stderr, "Error sending a packet to decoder\n");
233  return ret;
234  }
235 
236  while (1) {
237  ret = avcodec_receive_frame(pd->dec, pd->frame);
238  if (ret == AVERROR(EAGAIN))
239  break;
240  else if (ret == AVERROR_EOF)
241  return 0;
242  else if (ret < 0) {
243  fprintf(stderr, "Error receving a frame from decoder\n");
244  return ret;
245  }
246 
248  pd->frame->pts, pd->frame);
249  av_frame_unref(pd->frame);
250  if (ret < 0)
251  return ret;
252  }
253 
254  }
255 
256  return 0;
257 }
258 
259 static int frame_checksum_compare(const void *a, const void *b)
260 {
261  const FrameChecksum *ca = a;
262  const FrameChecksum *cb = b;
263  if (ca->ts == cb->ts)
264  return 0;
265  return FFSIGN(ca->ts - cb->ts);
266 }
267 
268 int main(int argc, char **argv)
269 {
270  PrivData pd;
272 
273  const char *filename, *enc_name, *enc_opts, *thread_type = NULL, *nb_threads = NULL;
274  const AVCodec *enc, *dec;
275  int ret = 0, max_frames = 0;
276 
277  if (argc < 4) {
278  fprintf(stderr,
279  "Usage: %s <input file> <encoder> <encoder options> "
280  "[<max frame count> [<thread count> <thread type>]\n",
281  argv[0]);
282  return 0;
283  }
284 
285  filename = argv[1];
286  enc_name = argv[2];
287  enc_opts = argv[3];
288  if (argc >= 5)
289  max_frames = strtol(argv[4], NULL, 0);
290  if (argc >= 6)
291  nb_threads = argv[5];
292  if (argc >= 7)
293  thread_type = argv[6];
294 
295  memset(&dc, 0, sizeof(dc));
296  memset(&pd, 0, sizeof(pd));
297 
299  if (!enc) {
300  fprintf(stderr, "No such encoder: %s\n", enc_name);
301  return 1;
302  }
304  fprintf(stderr, "Encoder '%s' cannot output reconstructed frames\n",
305  enc->name);
306  return 1;
307  }
308 
309  dec = avcodec_find_decoder(enc->id);
310  if (!dec) {
311  fprintf(stderr, "No decoder for: %s\n", avcodec_get_name(enc->id));
312  return 1;
313  }
314 
315  pd.enc = avcodec_alloc_context3(enc);
316  if (!pd.enc) {
317  fprintf(stderr, "Error allocating encoder\n");
318  return 1;
319  }
320 
321  ret = av_set_options_string(pd.enc, enc_opts, "=", ",");
322  if (ret < 0) {
323  fprintf(stderr, "Error setting encoder options\n");
324  goto fail;
325  }
327 
328  pd.dec = avcodec_alloc_context3(dec);
329  if (!pd.dec) {
330  fprintf(stderr, "Error allocating decoder\n");
331  goto fail;
332  }
333 
336 
337  pd.frame = av_frame_alloc();
339  pd.pkt = av_packet_alloc();
340  if (!pd.frame ||!pd.frame_recon || !pd.pkt) {
341  ret = 1;
342  goto fail;
343  }
344 
345  ret = ds_open(&dc, filename, 0);
346  if (ret < 0) {
347  fprintf(stderr, "Error opening the file\n");
348  goto fail;
349  }
350 
351  dc.process_frame = process_frame;
352  dc.opaque = &pd;
353  dc.max_frames = max_frames;
354 
355  ret = av_dict_set(&dc.decoder_opts, "threads", nb_threads, 0);
356  ret |= av_dict_set(&dc.decoder_opts, "thread_type", thread_type, 0);
357 
358  ret = ds_run(&dc);
359  if (ret < 0)
360  goto fail;
361 
363  fprintf(stderr, "Mismatching frame counts: recon=%zu decoded=%zu\n",
365  ret = 1;
366  goto fail;
367  }
368 
369  // reconstructed frames are in coded order, sort them by pts into presentation order
370  qsort(pd.checksums_recon, pd.nb_checksums_recon, sizeof(*pd.checksums_recon),
372 
373  for (size_t i = 0; i < pd.nb_checksums_decoded; i++) {
374  const FrameChecksum *d = &pd.checksums_decoded[i];
375  const FrameChecksum *r = &pd.checksums_recon[i];
376 
377  for (int p = 0; p < FF_ARRAY_ELEMS(d->checksum); p++)
378  if (d->checksum[p] != r->checksum[p]) {
379  fprintf(stderr, "Checksum mismatch in frame ts=%"PRId64", plane %d\n",
380  d->ts, p);
381  ret = 1;
382  goto fail;
383  }
384  }
385  fprintf(stderr, "All %zu encoded frames match\n", pd.nb_checksums_decoded);
386 
387 fail:
392  av_frame_free(&pd.frame);
394  av_packet_free(&pd.pkt);
395  ds_free(&dc);
396  return !!ret;
397 }
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:247
recon_frame_process
static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
Definition: enc_recon_frame_test.c:106
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:1424
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: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:55
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:696
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:120
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:115
fail
#define fail()
Definition: checkasm.h:188
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1587
FFSIGN
#define FFSIGN(a)
Definition: common.h:75
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:53
frame_checksum_compare
static int frame_checksum_compare(const void *a, const void *b)
Definition: enc_recon_frame_test.c:259
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
avassert.h
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:701
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:1597
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:1782
process_frame
static int process_frame(DecodeContext *dc, AVFrame *frame)
Definition: enc_recon_frame_test.c:145
frame_hash
static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts, const AVFrame *frame)
Definition: enc_recon_frame_test.c:68
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:46
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:48
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:967
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:122
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:2101
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:64
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:720
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:1187
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:526
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:608
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:268
AVCodecContext
main external API structure.
Definition: avcodec.h:445
PrivData::nb_checksums_recon
size_t nb_checksums_recon
Definition: enc_recon_frame_test.c:65
PrivData::checksums_decoded
FrameChecksum * checksums_decoded
Definition: enc_recon_frame_test.c:62
PrivData
Definition: enc_recon_frame_test.c:51
PrivData::pkt
AVPacket * pkt
Definition: enc_recon_frame_test.c:57
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:52
AVPacket
This structure stores compressed data.
Definition: packet.h:510
PrivData::nb_checksums_decoded
size_t nb_checksums_decoded
Definition: enc_recon_frame_test.c:63
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:58
ds_free
void ds_free(DecodeContext *dc)
Definition: decode_simple.c:109
PrivData::scaler
struct SwsContext * scaler
Definition: enc_recon_frame_test.c:60
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:47
PrivData::frame_recon
AVFrame * frame_recon
Definition: enc_recon_frame_test.c:58
SwsContext
Definition: swscale_internal.h:299
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:990