36 #define DEFAULT_SLICE_MB_WIDTH 8
38 #define FF_PROFILE_PRORES_PROXY 0
39 #define FF_PROFILE_PRORES_LT 1
40 #define FF_PROFILE_PRORES_STANDARD 2
41 #define FF_PROFILE_PRORES_HQ 3
56 0, 1, 8, 9, 2, 3, 10, 11,
57 16, 17, 24, 25, 18, 19, 26, 27,
58 4, 5, 12, 20, 13, 6, 7, 14,
59 21, 28, 29, 22, 15, 23, 30, 31,
60 32, 33, 40, 48, 41, 34, 35, 42,
61 49, 56, 57, 50, 43, 36, 37, 44,
62 51, 58, 59, 52, 45, 38, 39, 46,
63 53, 60, 61, 54, 47, 55, 62, 63
68 4, 7, 9, 11, 13, 14, 15, 63,
69 7, 7, 11, 12, 14, 15, 63, 63,
70 9, 11, 13, 14, 15, 63, 63, 63,
71 11, 11, 13, 14, 63, 63, 63, 63,
72 11, 13, 14, 63, 63, 63, 63, 63,
73 13, 14, 63, 63, 63, 63, 63, 63,
74 13, 63, 63, 63, 63, 63, 63, 63,
75 63, 63, 63, 63, 63, 63, 63, 63
77 4, 5, 6, 7, 9, 11, 13, 15,
78 5, 5, 7, 8, 11, 13, 15, 17,
79 6, 7, 9, 11, 13, 15, 15, 17,
80 7, 7, 9, 11, 13, 15, 17, 19,
81 7, 9, 11, 13, 14, 16, 19, 23,
82 9, 11, 13, 14, 16, 19, 23, 29,
83 9, 11, 13, 15, 17, 21, 28, 35,
84 11, 13, 16, 17, 21, 28, 35, 41
86 4, 4, 5, 5, 6, 7, 7, 9,
87 4, 4, 5, 6, 7, 7, 9, 9,
88 5, 5, 6, 7, 7, 9, 9, 10,
89 5, 5, 6, 7, 7, 9, 9, 10,
90 5, 6, 7, 7, 8, 9, 10, 12,
91 6, 7, 7, 8, 9, 10, 12, 15,
92 6, 7, 7, 9, 10, 11, 14, 17,
93 7, 7, 9, 10, 11, 14, 17, 21
95 4, 4, 4, 4, 4, 4, 4, 4,
96 4, 4, 4, 4, 4, 4, 4, 4,
97 4, 4, 4, 4, 4, 4, 4, 4,
98 4, 4, 4, 4, 4, 4, 4, 5,
99 4, 4, 4, 4, 4, 4, 5, 5,
100 4, 4, 4, 4, 4, 5, 5, 6,
101 4, 4, 4, 4, 5, 5, 6, 7,
102 4, 4, 4, 4, 5, 6, 7, 7
108 4, 7, 9, 11, 13, 14, 63, 63,
109 7, 7, 11, 12, 14, 63, 63, 63,
110 9, 11, 13, 14, 63, 63, 63, 63,
111 11, 11, 13, 14, 63, 63, 63, 63,
112 11, 13, 14, 63, 63, 63, 63, 63,
113 13, 14, 63, 63, 63, 63, 63, 63,
114 13, 63, 63, 63, 63, 63, 63, 63,
115 63, 63, 63, 63, 63, 63, 63, 63
117 4, 5, 6, 7, 9, 11, 13, 15,
118 5, 5, 7, 8, 11, 13, 15, 17,
119 6, 7, 9, 11, 13, 15, 15, 17,
120 7, 7, 9, 11, 13, 15, 17, 19,
121 7, 9, 11, 13, 14, 16, 19, 23,
122 9, 11, 13, 14, 16, 19, 23, 29,
123 9, 11, 13, 15, 17, 21, 28, 35,
124 11, 13, 16, 17, 21, 28, 35, 41
126 4, 4, 5, 5, 6, 7, 7, 9,
127 4, 4, 5, 6, 7, 7, 9, 9,
128 5, 5, 6, 7, 7, 9, 9, 10,
129 5, 5, 6, 7, 7, 9, 9, 10,
130 5, 6, 7, 7, 8, 9, 10, 12,
131 6, 7, 7, 8, 9, 10, 12, 15,
132 6, 7, 7, 9, 10, 11, 14, 17,
133 7, 7, 9, 10, 11, 14, 17, 21
135 4, 4, 4, 4, 4, 4, 4, 4,
136 4, 4, 4, 4, 4, 4, 4, 4,
137 4, 4, 4, 4, 4, 4, 4, 4,
138 4, 4, 4, 4, 4, 4, 4, 5,
139 4, 4, 4, 4, 4, 4, 5, 5,
140 4, 4, 4, 4, 4, 5, 5, 6,
141 4, 4, 4, 4, 5, 5, 6, 7,
142 4, 4, 4, 4, 5, 6, 7, 7
152 int qmat_luma[16][64];
153 int qmat_chroma[16][64];
158 unsigned int rice_order, exp_order, switch_bits, first_exp, exp, zeros,
162 switch_bits = codebook & 3;
163 rice_order = codebook >> 5;
164 exp_order = (codebook >> 2) & 7;
166 first_exp = ((switch_bits + 1) << rice_order);
168 if (val >= first_exp) {
170 val += (1 << exp_order);
172 zeros = exp - exp_order + switch_bits + 1;
175 }
else if (rice_order) {
176 mask = (1 << rice_order) - 1;
177 put_bits(pb, (val >> rice_order), 0);
179 put_bits(pb, rice_order, val & mask);
186 #define QSCALE(qmat,ind,val) ((val) / (qmat[ind]))
187 #define TO_GOLOMB(val) ((val << 1) ^ (val >> 31))
188 #define DIFF_SIGN(val, sign) ((val >> 31) ^ sign)
189 #define IS_NEGATIVE(val) (((val >> 31) ^ -1) + 1)
190 #define TO_GOLOMB2(val,sign) (val==0 ? 0 : (val << 1) + sign)
194 int sign = (val >> 31);
195 return (val ^ sign) - sign;
198 #define FIRST_DC_CB 0xB8
203 int blocks_per_slice,
int *qmat)
207 int new_dc,
delta, diff_sign, new_code;
209 prev_dc =
QSCALE(qmat, 0, in[0] - 16384);
213 code = 5; sign = 0; idx = 64;
214 for (i = 1; i < blocks_per_slice; i++, idx += 64) {
215 new_dc =
QSCALE(qmat, 0, in[idx] - 16384);
216 delta = new_dc - prev_dc;
229 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
231 0x28, 0x28, 0x28, 0x4C };
234 int16_t *
in,
int blocks_per_slice,
int *qmat)
240 for (i = 1; i < 64; i++) {
242 for (j = 0; j < blocks_per_slice; j++) {
243 int val =
QSCALE(qmat, indp, in[(j << 6) + indp]);
266 int16_t *p = (int16_t*)pixels;
270 for (i = 0; i < 8; i++) {
271 for (j = 0; j < 8; j++) {
287 int *qmat,
int chroma)
290 int i, blocks_per_slice;
294 for (i = 0; i < mb_count; i++) {
296 fdct_get(src + 8 * src_stride, src_stride,
block + ((2 - chroma) << 6));
299 fdct_get(src + 16 + 8 * src_stride, src_stride,
block + (3 << 6));
302 block += (256 >> chroma);
303 src += (32 >> chroma);
306 blocks_per_slice = mb_count << (2 - chroma);
318 int chroma_stride,
unsigned mb_count,
uint8_t *
buf,
unsigned data_size,
319 unsigned* y_data_size,
unsigned* u_data_size,
unsigned* v_data_size,
325 buf, data_size, ctx->
qmat_luma[qp - 1], 0);
329 chroma_stride, buf + *y_data_size, data_size - *y_data_size,
333 chroma_stride, buf + *y_data_size + *u_data_size,
334 data_size - *y_data_size - *u_data_size,
338 return *y_data_size + *u_data_size + *v_data_size;
343 unsigned dst_width,
unsigned dst_height)
346 int box_width =
FFMIN(width - x, dst_width);
347 int box_height =
FFMIN(height - y, dst_height);
348 int i, j, src_stride = stride >> 1;
349 uint16_t last_pix, *last_line;
351 src += y * src_stride + x;
352 for (i = 0; i < box_height; ++i) {
353 for (j = 0; j < box_width; ++j) {
356 last_pix = dst[j - 1];
357 for (; j < dst_width; j++)
362 last_line = dst - dst_width;
363 for (; i < dst_height; i++) {
364 for (j = 0; j < dst_width; ++j) {
365 dst[j] = last_line[j];
372 int mb_y,
unsigned mb_count,
uint8_t *
buf,
unsigned data_size,
375 int luma_stride, chroma_stride;
376 int hdr_size = 6, slice_size;
377 uint8_t *dest_y, *dest_u, *dest_v;
378 unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0;
381 int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3;
382 int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3;
387 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride + (mb_x << 5);
388 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride + (mb_x << 4);
389 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride + (mb_x << 4);
395 (uint16_t *) ctx->
fill_y, mb_count << 4, 16);
398 (uint16_t *) ctx->
fill_u, mb_count << 3, 16);
401 (uint16_t *) ctx->
fill_v, mb_count << 3, 16);
404 mb_count << 5, mb_count << 4, mb_count, buf + hdr_size,
405 data_size - hdr_size, &y_data_size, &u_data_size, &v_data_size,
409 luma_stride, chroma_stride, mb_count, buf + hdr_size,
410 data_size - hdr_size, &y_data_size, &u_data_size, &v_data_size,
417 luma_stride, chroma_stride, mb_count, buf + hdr_size,
418 data_size - hdr_size, &y_data_size, &u_data_size,
421 }
else if (slice_size < low_bytes && *qp
426 luma_stride, chroma_stride, mb_count, buf + hdr_size,
427 data_size - hdr_size, &y_data_size, &u_data_size,
433 buf[0] = hdr_size << 3;
438 return hdr_size + y_data_size + u_data_size + v_data_size;
444 int mb_width = (avctx->
width + 15) >> 4;
445 int mb_height = (avctx->
height + 15) >> 4;
446 int hdr_size, sl_size, i;
447 int mb_y, sl_data_size, qp;
448 int unsafe_bot, unsafe_right;
449 uint8_t *sl_data, *sl_data_sizes;
450 int slice_per_line = 0, rem = mb_width;
453 slice_per_line += rem >> i;
458 hdr_size = 8; sl_data_size = buf_size - hdr_size;
459 sl_data_sizes = buf + hdr_size;
460 sl_data = sl_data_sizes + (slice_per_line * mb_height * 2);
461 for (mb_y = 0; mb_y < mb_height; mb_y++) {
464 while (mb_x < mb_width) {
465 while (mb_width - mb_x < slice_mb_count)
466 slice_mb_count >>= 1;
468 unsafe_bot = (avctx->
height & 0xf) && (mb_y == mb_height - 1);
469 unsafe_right = (avctx->
width & 0xf) && (mb_x + slice_mb_count == mb_width);
471 sl_size =
encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count,
472 sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp);
474 bytestream_put_be16(&sl_data_sizes, sl_size);
476 sl_data_size -= sl_size;
477 mb_x += slice_mb_count;
481 buf[0] = hdr_size << 3;
482 AV_WB32(buf + 1, sl_data - buf);
483 AV_WB16(buf + 5, slice_per_line * mb_height);
486 return sl_data -
buf;
490 const AVFrame *pict,
int *got_packet)
492 int header_size = 148;
503 pkt->
size - header_size - 8);
505 bytestream_put_be32(&buf, pic_size + 8 + header_size);
508 bytestream_put_be16(&buf, header_size);
509 bytestream_put_be16(&buf, 0);
511 bytestream_put_be16(&buf, avctx->
width);
512 bytestream_put_be16(&buf, avctx->
height);
526 pkt->
size = pic_size + 8 + header_size;
535 for (i = 0; i < 64; i++)
536 dst[i] = src[i] * scale;
548 if (avctx->
width & 0x1) {
550 "frame width needs to be multiple of 2\n");
554 if ((avctx->
height & 0xf) || (avctx->
width & 0xf)) {
565 "encoding with ProRes standard (apcn) profile\n");
572 "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch]\n",
579 for (i = 1; i <= 16; i++) {
void ff_jpeg_fdct_islow_10(int16_t *data)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
const char const char void * val
This structure describes decoded (raw) audio or video data.
static const uint8_t QMAT_LUMA[4][64]
static const int bitrate_table[5]
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define TO_GOLOMB2(val, sign)
static av_cold int init(AVCodecContext *avctx)
static av_always_inline unsigned encode_slice_data(AVCodecContext *avctx, uint8_t *dest_y, uint8_t *dest_u, uint8_t *dest_v, int luma_stride, int chroma_stride, unsigned mb_count, uint8_t *buf, unsigned data_size, unsigned *y_data_size, unsigned *u_data_size, unsigned *v_data_size, int qp)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
uint8_t qmat_chroma[64]
dequantization matrix for chroma
static av_cold int prores_encode_init(AVCodecContext *avctx)
#define DECLARE_ALIGNED(n, t, v)
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.
static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, int mb_x, int mb_y, unsigned mb_count, uint8_t *buf, unsigned data_size, int unsafe, int *qp)
#define FF_PROFILE_PRORES_PROXY
static int encode_slice_plane(AVCodecContext *avctx, int mb_count, uint8_t *src, int src_stride, uint8_t *buf, unsigned buf_size, int *qmat, int chroma)
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int prores_encode_picture(AVCodecContext *avctx, const AVFrame *pic, uint8_t *buf, const int buf_size)
#define CODEC_CAP_INTRA_ONLY
Codec is intra only.
static void encode_dc_coeffs(PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat)
static const uint8_t QMAT_CHROMA[4][64]
static const uint8_t progressive_scan[64]
const char * name
Name of the codec implementation.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static const uint8_t frame_size[4]
static const uint8_t lev_to_cb[10]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
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-> in
static const uint16_t mask[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_cold int prores_encode_close(AVCodecContext *avctx)
Libavcodec external API header.
AVPixelFormat
Pixel format.
int flags
A combination of AV_PKT_FLAG values.
static av_always_inline int get_level(int val)
enum AVPictureType pict_type
Picture type of the frame.
static void scale_mat(const uint8_t *src, int *dst, int scale)
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
static const AVProfile profiles[]
int width
picture width / height.
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 ...
#define FF_PROFILE_PRORES_STANDARD
#define DEFAULT_SLICE_MB_WIDTH
#define FF_PROFILE_UNKNOWN
AVCodec ff_prores_encoder
#define AV_LOG_INFO
Standard information.
const char * name
short name for the profile
main external API structure.
static const uint8_t dc_codebook[7]
static void close(AVCodecParserContext *s)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
BYTE int const BYTE int int int height
AVFrame * coded_frame
the picture in the bitstream
#define QSCALE(qmat, ind, val)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static void encode_codeword(PutBitContext *pb, int val, int codebook)
static const uint16_t scale[4]
static void subimage_with_fill(uint16_t *src, unsigned x, unsigned y, unsigned stride, unsigned width, unsigned height, uint16_t *dst, unsigned dst_width, unsigned dst_height)
AVCodec ff_prores_aw_encoder
static const int qp_start_table[4]
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int key_frame
1 -> keyframe, 0-> not
#define AV_PIX_FMT_YUV422P10
uint8_t qmat_luma[64]
dequantization matrix for luma
#define FF_PROFILE_PRORES_HQ
#define DIFF_SIGN(val, sign)
static const uint8_t run_to_cb[16]
#define FF_PROFILE_PRORES_LT
This structure stores compressed data.
static void encode_ac_coeffs(AVCodecContext *avctx, PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const int qp_end_table[4]
static void fdct_get(uint8_t *pixels, int stride, int16_t *block)