47 for (
int i = 0;
i < 128;
i++) {
55 len = (
run >> 4) * huff_size_ac[0xf0];
60 len += huff_size_ac[
code] + nbits;
75 int nbits,
code, table_id;
85 size_t total_bits = 0;
95 total_bits += huff_size[table_id][
code] + nbits;
98 bytes_needed = (total_bits + 7) / 8;
133 &ac_chrominance_ctx };
134 for (
int i = 0;
i < 4;
i++)
187 int mb_y =
s->mb_y - !
s->mb_x;
200 s->intra_ac_vlc_length =
202 s->intra_chroma_ac_vlc_length =
206 s->pred,
s->intra_matrix,
s->chroma_intra_matrix);
219 if ((
s->avctx->active_thread_type &
FF_THREAD_SLICE) && mb_y < s->mb_height - 1)
224 for (
int i = 0;
i < 3;
i++)
225 s->last_dc[
i] = 128 <<
s->intra_dc_precision;
233 size_t num_mbs, num_blocks, num_codes;
237 s->mb_width = (
s->width + 15) / 16;
238 s->mb_height = (
s->height + 15) / 16;
240 switch (
s->chroma_format) {
248 num_mbs =
s->mb_width *
s->mb_height;
249 num_blocks = num_mbs * blocks_per_mb;
250 num_codes = num_blocks * 64;
264 if (
s->width > 65500 ||
s->height > 65500) {
298 s->intra_ac_vlc_length =
300 s->intra_chroma_ac_vlc_length =
331 c->table_id = table_id;
359 s->huff_buffer[
s->huff_ncode].mant = mant;
374 int component,
dc, last_index,
val,
run;
378 component = (n <= 3 ? 0 : (n&1) + 1);
379 table_id = (n <= 3 ? 0 : 1);
381 val =
dc -
s->last_dc[component];
385 s->last_dc[component] =
dc;
390 last_index =
s->block_last_index[n];
393 for(
i=1;
i<=last_index;
i++) {
394 j =
s->intra_scantable.permutated[
i];
410 if (last_index < 63 ||
run != 0)
416 int mant, nbits,
code,
i, j;
417 int component,
dc,
run, last_index,
val;
420 uint16_t *huff_code_ac;
423 component = (n <= 3 ? 0 : (n&1) + 1);
425 val =
dc -
s->last_dc[component];
435 s->last_dc[component] =
dc;
440 last_index =
s->block_last_index[n];
441 for(
i=1;
i<=last_index;
i++) {
442 j =
s->intra_scantable.permutated[
i];
448 put_bits(&
s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
468 if (last_index < 63 ||
run != 0)
469 put_bits(&
s->pb, huff_size_ac[0], huff_code_ac[0]);
484 if (16*
s->mb_x+8 <
s->width) {
513 if (16*
s->mb_x+8 <
s->width) {
538 #if CONFIG_AMV_ENCODER
542 const AVFrame *pic_arg,
int *got_packet)
547 int chroma_h_shift, chroma_v_shift;
553 "Heights which are not a multiple of 16 might fail with some decoders, "
554 "use vstrict=-1 / -strict -1 to use %d anyway.\n", avctx->
height);
555 av_log(avctx,
AV_LOG_WARNING,
"If you have a device that plays AMV videos, please test if videos "
556 "with such heights work with it and report your findings to ffmpeg-devel@ffmpeg.org\n");
564 for(
i=0;
i < 3;
i++) {
565 int vsample =
i ? 2 >> chroma_v_shift : 2;
575 #define OFFSET(x) offsetof(MpegEncContext, x)
576 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
589 #if CONFIG_MJPEG_ENCODER
590 static const AVClass mjpeg_class = {
611 .priv_class = &mjpeg_class,
616 #if CONFIG_AMV_ENCODER
617 static const AVClass amv_class = {
631 .encode2 = amv_encode_picture,
637 .priv_class = &amv_class,
static double val(void *priv, double ch)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
static av_cold int init(AVCodecContext *avctx)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define LIBAVUTIL_VERSION_INT
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
const uint8_t avpriv_mjpeg_val_dc[12]
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
const uint8_t avpriv_mjpeg_val_ac_luminance[]
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
MJPEG encoder and decoder.
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64])
static int alloc_huffman(MpegEncContext *s)
static const AVOption options[]
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256], uint8_t *uni_ac_vlc_len)
static void ff_mjpeg_encode_code(MJpegContext *s, uint8_t table_id, int code)
Add code and table_id to the JPEG buffer.
static void record_block(MpegEncContext *s, int16_t *block, int n)
Add the block's data into the JPEG buffer.
static void encode_block(MpegEncContext *s, int16_t *block, int n)
static void mjpeg_encode_picture_frame(MpegEncContext *s)
Encodes and outputs the entire frame in the JPEG format.
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
av_cold void ff_mjpeg_encode_close(MpegEncContext *s)
static void ff_mjpeg_encode_coef(MJpegContext *s, uint8_t table_id, int val, int run)
Add the coefficient's data to the JPEG buffer.
static void mjpeg_build_optimal_huffman(MJpegContext *m)
Builds all 4 optimal Huffman tables.
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
@ NB_HUFFMAN_TABLE_OPTION
@ HUFFMAN_TABLE_DEFAULT
Use the default Huffman tables.
static void put_marker(PutBitContext *p, enum JpegMarker code)
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, ScanTable *intra_scantable, int pred, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64])
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17], uint8_t val[], int max_nval)
Produces a Huffman encoding with a given input.
Huffman table generation for MJPEG encoder.
static void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s, uint8_t val)
int ff_mpv_encode_end(AVCodecContext *avctx)
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static int get_bits_diff(MpegEncContext *s)
#define UNI_AC_ENC_INDEX(run, level)
#define FF_MPV_COMMON_OPTS
int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
int ff_mpv_encode_init(AVCodecContext *avctx)
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.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
const AVProfile ff_mjpeg_profiles[]
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static int put_bits_count(PutBitContext *s)
static const float pred[4]
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
Holds JPEG frame data and Huffman table data.
uint8_t huff_size_dc_chrominance[12]
DC chrominance Huffman table size.
uint8_t huff_size_ac_chrominance[256]
AC chrominance Huffman table size.
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
uint8_t huff_size_dc_luminance[12]
DC luminance Huffman table size.
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
uint16_t huff_code_ac_luminance[256]
AC luminance Huffman table codes.
uint16_t huff_code_ac_chrominance[256]
AC chrominance Huffman table codes.
MJpegHuffmanCode * huff_buffer
Buffer for Huffman code values.
size_t huff_ncode
Number of current entries in the buffer.
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
uint16_t huff_code_dc_chrominance[12]
DC chrominance Huffman table codes.
uint8_t huff_size_ac_luminance[256]
AC luminance Huffman table size.
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
uint16_t huff_code_dc_luminance[12]
DC luminance Huffman table codes.
uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
Storage for AC chrominance VLC (in MpegEncContext)
uint8_t uni_ac_vlc_len[64 *64 *2]
Storage for AC luminance VLC (in MpegEncContext)
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
Buffer of JPEG frame data.
uint16_t mant
The mantissa.
uint8_t table_id
The Huffman table id associated with the data.
uint8_t code
The exponent.
#define av_malloc_array(a, b)