46 size_t num_mbs, num_blocks, num_codes;
62 num_blocks = num_mbs * blocks_per_mb;
63 num_codes = num_blocks * 64;
139 int i, nbits, code, table_id;
149 size_t total_bits = 0;
159 total_bits += huff_size[table_id][code] + nbits;
162 bytes_needed = (total_bits + 7) / 8;
170 put_bits(&s->
pb, huff_size[table_id][code], huff_code[table_id][code]);
233 int component,
dc, last_index,
val,
run;
237 component = (n <= 3 ? 0 : (n&1) + 1);
238 table_id = (n <= 3 ? 0 : 1);
240 val = dc - s->
last_dc[component];
252 for(i=1;i<=last_index;i++) {
269 if (last_index < 63 || run != 0)
275 int mant, nbits, code, i, j;
276 int component,
dc,
run, last_index,
val;
279 uint16_t *huff_code_ac;
282 component = (n <= 3 ? 0 : (n&1) + 1);
284 val = dc - s->
last_dc[component];
300 for(i=1;i<=last_index;i++) {
307 put_bits(&s->
pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
317 code = (run << 4) | nbits;
319 put_bits(&s->
pb, huff_size_ac[code], huff_code_ac[code]);
327 if (last_index < 63 || run != 0)
328 put_bits(&s->
pb, huff_size_ac[0], huff_code_ac[0]);
400 const AVFrame *pic_arg,
int *got_packet)
406 int chroma_h_shift, chroma_v_shift;
418 "Heights which are not a multiple of 16 might fail with some decoders, "
419 "use vstrict=-1 / -strict -1 to use %d anyway.\n", avctx->
height);
420 av_log(avctx,
AV_LOG_WARNING,
"If you have a device that plays AMV videos, please test if videos "
421 "with such heights work with it and report your findings to ffmpeg-devel@ffmpeg.org\n");
429 for(i=0; i < 3; i++) {
430 int vsample = i ? 2 >> chroma_v_shift : 2;
439 #define OFFSET(x) offsetof(MpegEncContext, x)
440 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
453 #if CONFIG_MJPEG_ENCODER
455 static const AVClass mjpeg_class = {
475 .priv_class = &mjpeg_class,
478 #if CONFIG_AMV_ENCODER
479 static const AVClass amv_class = {
498 .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
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int min_qcoeff
minimum encodable coefficient
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
uint8_t * intra_ac_vlc_length
int av_log2_16bit(unsigned v)
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)
static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
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
int flags
AV_CODEC_FLAG_*.
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.
int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
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
void ff_mjpeg_encode_picture_frame(MpegEncContext *s)
Encodes and outputs the entire frame in the JPEG format.
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[]
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
struct AVCodecContext * avctx
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.
#define CODEC_FLAG_EMU_EDGE
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])
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){if(!*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));if(!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=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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%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
#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[]