49 for (i = 0; i < 128; i++) {
54 for (run = 0; run < 64; run++) {
56 int alevel =
FFABS(level);
58 len = (run >> 4) * huff_size_ac[0xf0];
61 code = ((15&
run) << 4) | nbits;
63 len += huff_size_ac[code] + nbits;
123 int mant, nbits, code, i, j;
124 int component,
dc,
run, last_index,
val;
127 uint16_t *huff_code_ac;
130 component = (n <= 3 ? 0 : (n&1) + 1);
132 val = dc - s->
last_dc[component];
148 for(i=1;i<=last_index;i++) {
155 put_bits(&s->
pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
165 code = (run << 4) | nbits;
167 put_bits(&s->
pb, huff_size_ac[code], huff_code_ac[code]);
175 if (last_index < 63 || run != 0)
176 put_bits(&s->
pb, huff_size_ac[0], huff_code_ac[0]);
217 const AVFrame *pic_arg,
int *got_packet)
223 int chroma_h_shift, chroma_v_shift;
235 "Heights which are not a multiple of 16 might fail with some decoders, "
236 "use vstrict=-1 / -strict -1 to use %d anyway.\n", avctx->
height);
237 av_log(avctx,
AV_LOG_WARNING,
"If you have a device that plays AMV videos, please test if videos "
238 "with such heights work with it and report your findings to ffmpeg-devel@ffmpeg.org\n");
246 for(i=0; i < 3; i++) {
247 int vsample = i ? 2 >> chroma_v_shift : 2;
256 #if CONFIG_MJPEG_ENCODER
258 static const AVClass mjpeg_class = {
278 .priv_class = &mjpeg_class,
281 #if CONFIG_AMV_ENCODER
282 static const AVClass amv_class = {
301 .priv_class = &amv_class,
const char const char void * val
This structure describes decoded (raw) audio or video data.
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)
static uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
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
#define UNI_AC_ENC_INDEX(run, level)
int av_log2_16bit(unsigned v)
MJPEG encoder and decoder.
uint16_t huff_code_dc_chrominance[12]
#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...
const AVOption ff_mpv_generic_options[]
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]
static uint8_t uni_ac_vlc_len[64 *64 *2]
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)
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]
int max_qcoeff
maximum encodable coefficient
static int get_bits_diff(MpegEncContext *s)
uint16_t huff_code_ac_chrominance[256]
uint8_t huff_size_ac_luminance[256]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int last_dc[3]
last DC values for MPEG1
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. ...
uint8_t * intra_chroma_ac_vlc_length
int flags
AV_CODEC_FLAG_*.
uint8_t huff_size_ac_chrominance[256]
const char * name
Name of the codec implementation.
Libavcodec external API header.
#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...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
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...
struct MJpegContext * mjpeg_ctx
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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]
PutBitContext pb
bit output
uint8_t huff_size_dc_luminance[12]
#define CODEC_FLAG_EMU_EDGE
static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256], uint8_t *uni_ac_vlc_len)
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
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 (MPEG4, ...).