45 size_t num_mbs, num_blocks, num_codes;
61 num_blocks = num_mbs * blocks_per_mb;
62 num_codes = num_blocks * 64;
184 int component,
dc, last_index,
val,
run;
188 component = (n <= 3 ? 0 : (n&1) + 1);
189 table_id = (n <= 3 ? 0 : 1);
191 val = dc - s->
last_dc[component];
203 for(i=1;i<=last_index;i++) {
220 if (last_index < 63 || run != 0)
226 int mant, nbits, code, i, j;
227 int component,
dc,
run, last_index,
val;
230 uint16_t *huff_code_ac;
233 component = (n <= 3 ? 0 : (n&1) + 1);
235 val = dc - s->
last_dc[component];
251 for(i=1;i<=last_index;i++) {
258 put_bits(&s->
pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
268 code = (run << 4) | nbits;
270 put_bits(&s->
pb, huff_size_ac[code], huff_code_ac[code]);
278 if (last_index < 63 || run != 0)
279 put_bits(&s->
pb, huff_size_ac[0], huff_code_ac[0]);
348 #if CONFIG_AMV_ENCODER 352 const AVFrame *pic_arg,
int *got_packet)
357 int chroma_h_shift, chroma_v_shift;
363 "Heights which are not a multiple of 16 might fail with some decoders, " 364 "use vstrict=-1 / -strict -1 to use %d anyway.\n", avctx->
height);
365 av_log(avctx,
AV_LOG_WARNING,
"If you have a device that plays AMV videos, please test if videos " 366 "with such heights work with it and report your findings to ffmpeg-devel@ffmpeg.org\n");
374 for(i=0; i < 3; i++) {
375 int vsample = i ? 2 >> chroma_v_shift : 2;
385 #define OFFSET(x) offsetof(MpegEncContext, x) 386 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 399 #if CONFIG_MJPEG_ENCODER 400 static const AVClass mjpeg_class = {
420 .priv_class = &mjpeg_class,
424 #if CONFIG_AMV_ENCODER 425 static const AVClass amv_class = {
439 .encode2 = amv_encode_picture,
444 .priv_class = &amv_class,
const char const char void * val
Holds JPEG frame data and Huffman table data.
This structure describes decoded (raw) audio or video data.
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 put_sbits(PutBitContext *pb, int n, int32_t value)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
#define FF_MPV_COMMON_OPTS
const char * av_default_item_name(void *ptr)
Return the context name.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int min_qcoeff
minimum encodable coefficient
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
uint8_t * intra_ac_vlc_length
av_cold void ff_init_uni_ac_vlc(const uint8_t huff_size_ac[256], uint8_t *uni_ac_vlc_len)
MJPEG encoder and decoder.
uint16_t huff_code_dc_chrominance[12]
DC chrominance Huffman table codes.
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
uint16_t huff_code_ac_luminance[256]
AC luminance Huffman table codes.
static void encode_block(MpegEncContext *s, int16_t *block, int n)
uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
Storage for AC chrominance VLC (in MpegEncContext)
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
uint8_t huff_size_dc_chrominance[12]
DC chrominance Huffman table size.
int mb_height
number of MBs horizontally & vertically
Use the default Huffman tables.
int max_qcoeff
maximum encodable coefficient
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
uint8_t table_id
The Huffman table id associated with the data.
static int get_bits_diff(MpegEncContext *s)
uint16_t huff_code_ac_chrominance[256]
AC chrominance Huffman table codes.
int slice_context_count
number of used thread_contexts
uint8_t huff_size_ac_luminance[256]
AC luminance Huffman table size.
uint16_t mant
The mantissa.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int last_dc[3]
last DC values for MPEG-1
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void record_block(MpegEncContext *s, int16_t *block, int n)
Add the block's data into the JPEG buffer.
uint8_t * intra_chroma_ac_vlc_length
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
uint8_t huff_size_ac_chrominance[256]
AC chrominance Huffman table size.
const char * name
Name of the codec implementation.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
uint8_t * intra_ac_vlc_last_length
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
uint8_t uni_ac_vlc_len[64 *64 *2]
Storage for AC luminance VLC (in MpegEncContext)
int block_last_index[12]
last non zero coefficient in block
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
Compute and use optimal Huffman tables.
static const float pred[4]
struct MJpegContext * mjpeg_ctx
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static void ff_mjpeg_encode_code(MJpegContext *s, uint8_t table_id, int code)
Add code and table_id to the JPEG buffer.
Buffer of JPEG frame data.
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int alloc_huffman(MpegEncContext *s)
uint8_t * intra_chroma_ac_vlc_last_length
main external API structure.
ScanTable intra_scantable
int height
picture size. must be a multiple of 16
int ff_mpv_encode_init(AVCodecContext *avctx)
const uint8_t avpriv_mjpeg_val_dc[12]
Describe the class of an AVClass context structure.
av_cold void ff_mjpeg_encode_close(MpegEncContext *s)
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
static enum AVPixelFormat pix_fmts[]
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)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint16_t huff_code_dc_luminance[12]
DC luminance Huffman table codes.
PutBitContext pb
bit output
uint8_t huff_size_dc_luminance[12]
DC luminance Huffman table size.
uint8_t code
The exponent.
size_t huff_ncode
Number of current entries in the buffer.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
int ff_mpv_encode_end(AVCodecContext *avctx)
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
const uint8_t avpriv_mjpeg_val_ac_luminance[]
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64])
#define av_malloc_array(a, b)
MJpegHuffmanCode * huff_buffer
Buffer for Huffman code values.
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
AVPixelFormat
Pixel format.
This structure stores compressed data.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
static const AVOption options[]