FFmpeg  2.1.1
mjpegenc.c
Go to the documentation of this file.
1 /*
2  * MJPEG encoder
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2003 Alex Beregszaszi
5  * Copyright (c) 2003-2004 Michael Niedermayer
6  *
7  * Support for external huffman table, various fixes (AVID workaround),
8  * aspecting, new decode_frame mechanism and apple mjpeg-b support
9  * by Alex Beregszaszi
10  *
11  * This file is part of FFmpeg.
12  *
13  * FFmpeg is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * FFmpeg is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with FFmpeg; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  */
27 
28 /**
29  * @file
30  * MJPEG encoder.
31  */
32 
33 #include "avcodec.h"
34 #include "mpegvideo.h"
35 #include "mjpeg.h"
36 #include "mjpegenc.h"
37 
38 /* use two quantizer tables (one for luminance and one for chrominance) */
39 /* not yet working */
40 #undef TWOMATRIXES
41 
42 
44 {
45  MJpegContext *m;
46 
47  if (s->width > 65500 || s->height > 65500) {
48  av_log(s, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n");
49  return -1;
50  }
51 
52  m = av_malloc(sizeof(MJpegContext));
53  if (!m)
54  return -1;
55 
56  s->min_qcoeff=-1023;
57  s->max_qcoeff= 1023;
58 
59  /* build all the huffman tables */
76 
77  s->mjpeg_ctx = m;
78  return 0;
79 }
80 
82 {
83  av_free(s->mjpeg_ctx);
84 }
85 
86 /* table_class: 0 = DC coef, 1 = AC coefs */
87 static int put_huffman_table(MpegEncContext *s, int table_class, int table_id,
88  const uint8_t *bits_table, const uint8_t *value_table)
89 {
90  PutBitContext *p = &s->pb;
91  int n, i;
92 
93  put_bits(p, 4, table_class);
94  put_bits(p, 4, table_id);
95 
96  n = 0;
97  for(i=1;i<=16;i++) {
98  n += bits_table[i];
99  put_bits(p, 8, bits_table[i]);
100  }
101 
102  for(i=0;i<n;i++)
103  put_bits(p, 8, value_table[i]);
104 
105  return n + 17;
106 }
107 
109 {
110  PutBitContext *p = &s->pb;
111  int i, j, size;
112  uint8_t *ptr;
113 
114  if (s->avctx->codec_id != AV_CODEC_ID_LJPEG) {
115  /* quant matrixes */
116  put_marker(p, DQT);
117 #ifdef TWOMATRIXES
118  put_bits(p, 16, 2 + 2 * (1 + 64));
119 #else
120  put_bits(p, 16, 2 + 1 * (1 + 64));
121 #endif
122  put_bits(p, 4, 0); /* 8 bit precision */
123  put_bits(p, 4, 0); /* table 0 */
124  for(i=0;i<64;i++) {
125  j = s->intra_scantable.permutated[i];
126  put_bits(p, 8, s->intra_matrix[j]);
127  }
128 #ifdef TWOMATRIXES
129  put_bits(p, 4, 0); /* 8 bit precision */
130  put_bits(p, 4, 1); /* table 1 */
131  for(i=0;i<64;i++) {
132  j = s->intra_scantable.permutated[i];
133  put_bits(p, 8, s->chroma_intra_matrix[j]);
134  }
135 #endif
136  }
137 
139  put_marker(p, DRI);
140  put_bits(p, 16, 4);
141  put_bits(p, 16, (s->width-1)/(8*s->mjpeg_hsample[0]) + 1);
142  }
143 
144  /* huffman table */
145  put_marker(p, DHT);
146  flush_put_bits(p);
147  ptr = put_bits_ptr(p);
148  put_bits(p, 16, 0); /* patched later */
149  size = 2;
154 
159  AV_WB16(ptr, size);
160 }
161 
163 {
164  PutBitContext *p = &s->pb;
165  int size;
166  uint8_t *ptr;
167 
168  if (s->avctx->sample_aspect_ratio.num /* && !lossless */)
169  {
170  /* JFIF header */
171  put_marker(p, APP0);
172  put_bits(p, 16, 16);
173  avpriv_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
174  put_bits(p, 16, 0x0102); /* v 1.02 */
175  put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
178  put_bits(p, 8, 0); /* thumbnail width */
179  put_bits(p, 8, 0); /* thumbnail height */
180  }
181 
182  /* comment */
183  if(!(s->flags & CODEC_FLAG_BITEXACT)){
184  put_marker(p, COM);
185  flush_put_bits(p);
186  ptr = put_bits_ptr(p);
187  put_bits(p, 16, 0); /* patched later */
189  size = strlen(LIBAVCODEC_IDENT)+3;
190  AV_WB16(ptr, size);
191  }
192 
193  if( s->avctx->pix_fmt == AV_PIX_FMT_YUV420P
195  ||s->avctx->pix_fmt == AV_PIX_FMT_YUV444P){
196  put_marker(p, COM);
197  flush_put_bits(p);
198  ptr = put_bits_ptr(p);
199  put_bits(p, 16, 0); /* patched later */
200  avpriv_put_string(p, "CS=ITU601", 1);
201  size = strlen("CS=ITU601")+3;
202  AV_WB16(ptr, size);
203  }
204 }
205 
207 {
208  const int lossless= s->avctx->codec_id != AV_CODEC_ID_MJPEG;
209  int i;
210 
211  put_marker(&s->pb, SOI);
212 
213  // hack for AMV mjpeg format
214  if(s->avctx->codec_id == AV_CODEC_ID_AMV) goto end;
215 
217 
219 
220  switch(s->avctx->codec_id){
221  case AV_CODEC_ID_MJPEG: put_marker(&s->pb, SOF0 ); break;
222  case AV_CODEC_ID_LJPEG: put_marker(&s->pb, SOF3 ); break;
223  default: av_assert0(0);
224  }
225 
226  put_bits(&s->pb, 16, 17);
227  if(lossless && (s->avctx->pix_fmt == AV_PIX_FMT_BGR0
228  || s->avctx->pix_fmt == AV_PIX_FMT_BGRA
229  || s->avctx->pix_fmt == AV_PIX_FMT_BGR24))
230  put_bits(&s->pb, 8, 9); /* 9 bits/component RCT */
231  else
232  put_bits(&s->pb, 8, 8); /* 8 bits/component */
233  put_bits(&s->pb, 16, s->height);
234  put_bits(&s->pb, 16, s->width);
235  put_bits(&s->pb, 8, 3); /* 3 components */
236 
237  /* Y component */
238  put_bits(&s->pb, 8, 1); /* component number */
239  put_bits(&s->pb, 4, s->mjpeg_hsample[0]); /* H factor */
240  put_bits(&s->pb, 4, s->mjpeg_vsample[0]); /* V factor */
241  put_bits(&s->pb, 8, 0); /* select matrix */
242 
243  /* Cb component */
244  put_bits(&s->pb, 8, 2); /* component number */
245  put_bits(&s->pb, 4, s->mjpeg_hsample[1]); /* H factor */
246  put_bits(&s->pb, 4, s->mjpeg_vsample[1]); /* V factor */
247 #ifdef TWOMATRIXES
248  put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
249 #else
250  put_bits(&s->pb, 8, 0); /* select matrix */
251 #endif
252 
253  /* Cr component */
254  put_bits(&s->pb, 8, 3); /* component number */
255  put_bits(&s->pb, 4, s->mjpeg_hsample[2]); /* H factor */
256  put_bits(&s->pb, 4, s->mjpeg_vsample[2]); /* V factor */
257 #ifdef TWOMATRIXES
258  put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
259 #else
260  put_bits(&s->pb, 8, 0); /* select matrix */
261 #endif
262 
263  /* scan header */
264  put_marker(&s->pb, SOS);
265  put_bits(&s->pb, 16, 12); /* length */
266  put_bits(&s->pb, 8, 3); /* 3 components */
267 
268  /* Y component */
269  put_bits(&s->pb, 8, 1); /* index */
270  put_bits(&s->pb, 4, 0); /* DC huffman table index */
271  put_bits(&s->pb, 4, 0); /* AC huffman table index */
272 
273  /* Cb component */
274  put_bits(&s->pb, 8, 2); /* index */
275  put_bits(&s->pb, 4, 1); /* DC huffman table index */
276  put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
277 
278  /* Cr component */
279  put_bits(&s->pb, 8, 3); /* index */
280  put_bits(&s->pb, 4, 1); /* DC huffman table index */
281  put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
282 
283  put_bits(&s->pb, 8, lossless ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */
284 
285  switch(s->avctx->codec_id){
286  case AV_CODEC_ID_MJPEG: put_bits(&s->pb, 8, 63); break; /* Se (not used) */
287  case AV_CODEC_ID_LJPEG: put_bits(&s->pb, 8, 0); break; /* not used */
288  default: av_assert0(0);
289  }
290 
291  put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */
292 
293 end:
294  s->esc_pos = put_bits_count(&s->pb) >> 3;
295  for(i=1; i<s->slice_context_count; i++)
296  s->thread_context[i]->esc_pos = 0;
297 }
298 
299 static void escape_FF(MpegEncContext *s, int start)
300 {
301  int size= put_bits_count(&s->pb) - start*8;
302  int i, ff_count;
303  uint8_t *buf= s->pb.buf + start;
304  int align= (-(size_t)(buf))&3;
305 
306  av_assert1((size&7) == 0);
307  size >>= 3;
308 
309  ff_count=0;
310  for(i=0; i<size && i<align; i++){
311  if(buf[i]==0xFF) ff_count++;
312  }
313  for(; i<size-15; i+=16){
314  int acc, v;
315 
316  v= *(uint32_t*)(&buf[i]);
317  acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
318  v= *(uint32_t*)(&buf[i+4]);
319  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
320  v= *(uint32_t*)(&buf[i+8]);
321  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
322  v= *(uint32_t*)(&buf[i+12]);
323  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
324 
325  acc>>=4;
326  acc+= (acc>>16);
327  acc+= (acc>>8);
328  ff_count+= acc&0xFF;
329  }
330  for(; i<size; i++){
331  if(buf[i]==0xFF) ff_count++;
332  }
333 
334  if(ff_count==0) return;
335 
336  flush_put_bits(&s->pb);
337  skip_put_bytes(&s->pb, ff_count);
338 
339  for(i=size-1; ff_count; i--){
340  int v= buf[i];
341 
342  if(v==0xFF){
343  buf[i+ff_count]= 0;
344  ff_count--;
345  }
346 
347  buf[i+ff_count]= v;
348  }
349 }
350 
352 {
353  int length, i;
354  PutBitContext *pbc = &s->pb;
355  int mb_y = s->mb_y - !s->mb_x;
356  length= (-put_bits_count(pbc))&7;
357  if(length) put_bits(pbc, length, (1<<length)-1);
358 
359  flush_put_bits(&s->pb);
360  escape_FF(s, s->esc_pos);
361 
362  if((s->avctx->active_thread_type & FF_THREAD_SLICE) && mb_y < s->mb_height)
363  put_marker(pbc, RST0 + (mb_y&7));
364  s->esc_pos = put_bits_count(pbc) >> 3;
365 
366  for(i=0; i<3; i++)
367  s->last_dc[i] = 128 << s->intra_dc_precision;
368 }
369 
371 {
372 
373  av_assert1((s->header_bits&7)==0);
374 
375 
376  put_marker(&s->pb, EOI);
377 }
378 
380  uint8_t *huff_size, uint16_t *huff_code)
381 {
382  int mant, nbits;
383 
384  if (val == 0) {
385  put_bits(&s->pb, huff_size[0], huff_code[0]);
386  } else {
387  mant = val;
388  if (val < 0) {
389  val = -val;
390  mant--;
391  }
392 
393  nbits= av_log2_16bit(val) + 1;
394 
395  put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
396 
397  put_sbits(&s->pb, nbits, mant);
398  }
399 }
400 
401 static void encode_block(MpegEncContext *s, int16_t *block, int n)
402 {
403  int mant, nbits, code, i, j;
404  int component, dc, run, last_index, val;
405  MJpegContext *m = s->mjpeg_ctx;
406  uint8_t *huff_size_ac;
407  uint16_t *huff_code_ac;
408 
409  /* DC coef */
410  component = (n <= 3 ? 0 : (n&1) + 1);
411  dc = block[0]; /* overflow is impossible */
412  val = dc - s->last_dc[component];
413  if (n < 4) {
415  huff_size_ac = m->huff_size_ac_luminance;
416  huff_code_ac = m->huff_code_ac_luminance;
417  } else {
419  huff_size_ac = m->huff_size_ac_chrominance;
420  huff_code_ac = m->huff_code_ac_chrominance;
421  }
422  s->last_dc[component] = dc;
423 
424  /* AC coefs */
425 
426  run = 0;
427  last_index = s->block_last_index[n];
428  for(i=1;i<=last_index;i++) {
429  j = s->intra_scantable.permutated[i];
430  val = block[j];
431  if (val == 0) {
432  run++;
433  } else {
434  while (run >= 16) {
435  put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
436  run -= 16;
437  }
438  mant = val;
439  if (val < 0) {
440  val = -val;
441  mant--;
442  }
443 
444  nbits= av_log2(val) + 1;
445  code = (run << 4) | nbits;
446 
447  put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
448 
449  put_sbits(&s->pb, nbits, mant);
450  run = 0;
451  }
452  }
453 
454  /* output EOB only if not already 64 values */
455  if (last_index < 63 || run != 0)
456  put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]);
457 }
458 
459 void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[6][64])
460 {
461  int i;
462  if (s->chroma_format == CHROMA_444) {
463  encode_block(s, block[0], 0);
464  encode_block(s, block[2], 2);
465  encode_block(s, block[4], 4);
466  encode_block(s, block[8], 8);
467  encode_block(s, block[5], 5);
468  encode_block(s, block[9], 9);
469 
470  if (16*s->mb_x+8 < s->width) {
471  encode_block(s, block[1], 1);
472  encode_block(s, block[3], 3);
473  encode_block(s, block[6], 6);
474  encode_block(s, block[10], 10);
475  encode_block(s, block[7], 7);
476  encode_block(s, block[11], 11);
477  }
478  } else {
479  for(i=0;i<5;i++) {
480  encode_block(s, block[i], i);
481  }
482  if (s->chroma_format == CHROMA_420) {
483  encode_block(s, block[5], 5);
484  } else {
485  encode_block(s, block[6], 6);
486  encode_block(s, block[5], 5);
487  encode_block(s, block[7], 7);
488  }
489  }
490 
491  s->i_tex_bits += get_bits_diff(s);
492 }
493 
494 // maximum over s->mjpeg_vsample[i]
495 #define V_MAX 2
497  const AVFrame *pic_arg, int *got_packet)
498 
499 {
500  MpegEncContext *s = avctx->priv_data;
501  AVFrame pic = *pic_arg;
502  int i;
503 
504  //CODEC_FLAG_EMU_EDGE have to be cleared
506  return -1;
507 
508  //picture should be flipped upside-down
509  for(i=0; i < 3; i++) {
510  pic.data[i] += (pic.linesize[i] * (s->mjpeg_vsample[i] * (8 * s->mb_height -((s->height/V_MAX)&7)) - 1 ));
511  pic.linesize[i] *= -1;
512  }
513  return ff_MPV_encode_picture(avctx, pkt, &pic, got_packet);
514 }
515 
516 #if CONFIG_MJPEG_ENCODER
517 AVCodec ff_mjpeg_encoder = {
518  .name = "mjpeg",
519  .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
520  .type = AVMEDIA_TYPE_VIDEO,
521  .id = AV_CODEC_ID_MJPEG,
522  .priv_data_size = sizeof(MpegEncContext),
524  .encode2 = ff_MPV_encode_picture,
527  .pix_fmts = (const enum AVPixelFormat[]){
529  },
530 };
531 #endif
532 #if CONFIG_AMV_ENCODER
533 AVCodec ff_amv_encoder = {
534  .name = "amv",
535  .long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
536  .type = AVMEDIA_TYPE_VIDEO,
537  .id = AV_CODEC_ID_AMV,
538  .priv_data_size = sizeof(MpegEncContext),
540  .encode2 = amv_encode_picture,
542  .pix_fmts = (const enum AVPixelFormat[]){
544  },
545 };
546 #endif
Definition: mjpeg.h:115
const char const char void * val
Definition: avisynth_c.h:671
float v
const char * s
Definition: avisynth_c.h:668
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: mjpegenc.c:459
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:180
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:160
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
Definition: mjpeg.c:73
uint16_t chroma_intra_matrix[64]
Definition: mpegvideo.h:477
int acc
Definition: yuv2rgb.c:512
MJPEG encoder.
int ff_MPV_encode_end(AVCodecContext *avctx)
int mjpeg_hsample[3]
horizontal sampling factors, default = {2, 1, 1}
Definition: mpegvideo.h:632
planar YUV 4:2:2, 16bpp, (1 Cr &amp; Cb sample per 2x1 Y samples)
Definition: avcodec.h:4538
int num
numerator
Definition: rational.h:44
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1517
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1342
Definition: mjpeg.h:74
int min_qcoeff
minimum encodable coefficient
Definition: mpegvideo.h:483
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
Definition: mjpeg.c:70
mpegvideo header.
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
Definition: mjpeg.c:99
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
Definition: mjpegenc.c:43
uint8_t permutated[64]
Definition: dsputil.h:113
uint8_t run
Definition: svq3.c:145
Pixel format.
Definition: avcodec.h:4533
AVCodec.
Definition: avcodec.h:2922
#define av_cold
Definition: avcodec.h:653
MJPEG encoder and decoder.
uint16_t huff_code_dc_chrominance[12]
Definition: mjpegenc.h:44
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: avcodec.h:4537
#define V_MAX
Definition: mjpegenc.c:495
uint16_t huff_code_ac_luminance[256]
Definition: mjpegenc.h:47
uint8_t
#define CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:831
static void encode_block(MpegEncContext *s, int16_t *block, int n)
Definition: mjpegenc.c:401
static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
Definition: mjpegenc.c:496
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
#define CHROMA_420
Definition: mpegvideo.h:681
int intra_dc_precision
Definition: mpegvideo.h:671
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
Definition: mjpeg.c:127
uint8_t huff_size_dc_chrominance[12]
Definition: mjpegenc.h:43
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:714
int mb_height
number of MBs horizontally &amp; vertically
Definition: mpegvideo.h:281
Definition: mjpeg.h:77
int max_qcoeff
maximum encodable coefficient
Definition: mpegvideo.h:484
Definition: mjpeg.h:83
#define CHROMA_444
Definition: mpegvideo.h:683
int ff_MPV_encode_init(AVCodecContext *avctx)
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideo.h:880
uint16_t huff_code_ac_chrominance[256]
Definition: mjpegenc.h:49
int slice_context_count
number of used thread_contexts
Definition: mpegvideo.h:323
uint8_t huff_size_ac_luminance[256]
Definition: mjpegenc.h:46
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:207
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
int last_dc[3]
last DC values for MPEG1
Definition: mpegvideo.h:352
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
packed BGR 8:8:8, 32bpp, BGR0BGR0...
Definition: avcodec.h:4692
unsigned m
Definition: audioconvert.c:186
Definition: mjpeg.h:43
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: avcodec.h:4548
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:2608
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:2615
Definition: mjpeg.h:60
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1234
uint8_t * buf
Definition: put_bits.h:44
uint8_t huff_size_ac_chrominance[256]
Definition: mjpegenc.h:48
Libavcodec external API header.
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:73
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Definition: put_bits.h:216
void ff_mjpeg_encode_picture_header(MpegEncContext *s)
Definition: mjpegenc.c:206
Definition: mjpeg.h:76
static void jpeg_put_comments(MpegEncContext *s)
Definition: mjpegenc.c:162
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
Definition: mjpeg.c:65
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
const uint8_t avpriv_mjpeg_val_dc[12]
Definition: mjpeg.c:67
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:295
int n
Definition: avisynth_c.h:588
Definition: mjpeg.h:46
Definition: mjpeg.h:75
struct MJpegContext * mjpeg_ctx
Definition: mpegvideo.h:630
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: avcodec.h:4546
int mjpeg_vsample[3]
vertical sampling factors, default = {2, 1, 1}
Definition: mpegvideo.h:631
const AVS_VideoInfo int align
Definition: avisynth_c.h:695
planar YUV 4:2:0, 12bpp, (1 Cr &amp; Cb sample per 2x2 Y samples)
Definition: avcodec.h:4534
struct MpegEncContext * thread_context[MAX_THREADS]
Definition: mpegvideo.h:322
enum AVCodecID codec_id
Definition: avcodec.h:1157
void ff_mjpeg_encode_close(MpegEncContext *s)
Definition: mjpegenc.c:81
main external API structure.
Definition: avcodec.h:1146
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:538
ScanTable intra_scantable
Definition: mpegvideo.h:300
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:249
void ff_mjpeg_encode_picture_trailer(MpegEncContext *s)
Definition: mjpegenc.c:370
static void jpeg_table_header(MpegEncContext *s)
Definition: mjpegenc.c:108
void * buf
Definition: avisynth_c.h:594
planar YUV 4:4:4, 24bpp, (1 Cr &amp; Cb sample per 1x1 Y samples)
Definition: avcodec.h:4539
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
#define AV_WB16(p, darg)
Definition: intreadwrite.h:237
#define LIBAVCODEC_IDENT
Definition: version.h:43
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
void * priv_data
Definition: avcodec.h:1182
static int put_huffman_table(MpegEncContext *s, int table_class, int table_id, const uint8_t *bits_table, const uint8_t *value_table)
Definition: mjpegenc.c:87
MpegEncContext.
Definition: mpegvideo.h:245
const uint8_t avpriv_mjpeg_val_ac_luminance[]
Definition: mjpeg.c:75
struct AVCodecContext * avctx
Definition: mpegvideo.h:247
uint16_t huff_code_dc_luminance[12]
Definition: mjpegenc.h:42
PutBitContext pb
bit output
Definition: mpegvideo.h:318
uint8_t huff_size_dc_luminance[12]
Definition: mjpegenc.h:41
#define CODEC_FLAG_EMU_EDGE
Don&#39;t draw edges.
Definition: avcodec.h:706
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:815
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:89
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:811
void ff_mjpeg_encode_stuffing(MpegEncContext *s)
Definition: mjpegenc.c:351
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: avcodec.h:4565
Definition: mjpeg.h:65
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1498
int den
denominator
Definition: rational.h:45
static void put_marker(PutBitContext *p, int code)
Definition: mjpeg.h:122
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
Definition: mjpeg.c:102
Definition: mjpeg.h:79
#define av_log2_16bit
Definition: intmath.h:90
#define av_log2
Definition: intmath.h:89
void ff_mjpeg_encode_dc(MpegEncContext *s, int val, uint8_t *huff_size, uint16_t *huff_code)
Definition: mjpegenc.c:379
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
Definition: bitstream.c:52
int flags
AVCodecContext.flags (HQ, MV4, ...)
Definition: mpegvideo.h:264
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
Definition: mpegvideo.h:476
void INT64 start
Definition: avisynth_c.h:594
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static void escape_FF(MpegEncContext *s, int start)
Definition: mjpegenc.c:299
static AVPacket pkt
Definition: demuxing.c:52
const char int length
Definition: avisynth_c.h:668
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: avcodec.h:4547
This structure stores compressed data.
Definition: avcodec.h:1040
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, AVFrame *frame, int *got_packet)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
static int16_t block[64]
Definition: dct-test.c:198