69 return (aa->
len - bb->len)*256 + aa->
sym - bb->sym;
76 return aa->
sym - bb->sym;
85 for (
i = 0;
i < 4;
i++)
94 int i, subsampled_height;
95 uint32_t original_format;
97 c->frame_info_size = 4;
115 "4:2:0 video requires even width and height.\n");
126 if (avctx->
width & 1) {
128 "4:2:2 video requires even width.\n");
164 "Slice count %d is not supported in Ut Video (theoretical range is 0-256).\n",
171 if (avctx->
slices > subsampled_height) {
173 "Slice count %d is larger than the subsampling-applied height %d.\n",
174 avctx->
slices, subsampled_height);
189 for (
i = 0;
i <
c->planes;
i++) {
192 if (!
c->slice_buffer[
i]) {
221 c->slices = subsampled_height / 120;
225 else if (
c->slices > 256)
241 c->flags = (
c->slices - 1U) << 24;
243 c->flags |=
c->compression;
255 int k = 2 * dst_stride;
256 const uint8_t *sg =
src[0];
257 const uint8_t *sb =
src[1];
258 const uint8_t *sr =
src[2];
259 const uint8_t *sa =
src[3];
262 for (j = 0; j <
height; j++) {
268 dst[1][k] = sb[
i] -
g;
269 dst[2][k] = sr[
i] -
g;
277 dst[1][k] = sb[
i] -
g;
278 dst[2][k] = sr[
i] -
g;
284 k += dst_stride -
width;
321 for (j = 1; j <
height; j++) {
330 int height, uint64_t *counts)
334 for (j = 0; j <
height; j++) {
351 while (he[last].
len == 255 && last)
355 for (
i = last;
i >= 0;
i--) {
357 code += 0x80000000u >> (he[
i].
len - 1);
374 for (j = 0; j <
height; j++) {
395 uint8_t *
dst, ptrdiff_t
stride,
int plane_no,
399 uint8_t lengths[256];
400 uint64_t counts[256] = { 0 };
404 uint32_t
offset = 0, slice_len = 0;
406 int i, sstart, send = 0;
411 switch (
c->frame_pred) {
413 for (
i = 0;
i <
c->slices;
i++) {
415 send =
height * (
i + 1) /
c->slices & cmask;
418 width, send - sstart);
422 for (
i = 0;
i <
c->slices;
i++) {
424 send =
height * (
i + 1) /
c->slices & cmask;
429 for (
i = 0;
i <
c->slices;
i++) {
431 send =
height * (
i + 1) /
c->slices & cmask;
446 for (symbol = 0; symbol < 256; symbol++) {
448 if (counts[symbol]) {
455 for (
i = 0;
i < 256;
i++) {
457 bytestream2_put_byte(pb, 0);
459 bytestream2_put_byte(pb, 0xFF);
463 for (
i = 0;
i <
c->slices;
i++)
464 bytestream2_put_le32(pb, 0);
482 for (
i = 0;
i < 256;
i++) {
483 bytestream2_put_byte(pb, lengths[
i]);
485 he[
i].
len = lengths[
i];
493 for (
i = 0;
i <
c->slices;
i++) {
495 send =
height * (
i + 1) /
c->slices & cmask;
505 slice_len =
offset - slice_len;
508 c->bdsp.bswap_buf((uint32_t *)
c->slice_bits,
509 (uint32_t *)
c->slice_bits,
513 bytestream2_put_le32(pb,
offset);
517 offset - slice_len, SEEK_CUR);
536 const AVFrame *pic,
int *got_packet)
561 if (!
c->slice_bits) {
575 for (
i = 0;
i <
c->planes;
i++) {
577 c->slice_buffer[
i],
c->slice_stride,
i,
587 for (
i = 0;
i <
c->planes;
i++) {
598 for (
i = 0;
i <
c->planes;
i++) {
609 for (
i = 0;
i <
c->planes;
i++) {
642#define OFFSET(x) offsetof(UtvideoContext, x)
643#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
654 .class_name =
"utvideo",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_utvideo_encoder
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Libavcodec external API header.
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
static int FUNC frame_info(CodedBitstreamContext *ctx, RWContext *rw, APVRawFrameInfo *current)
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_OPTION_NOT_FOUND
Option not found.
#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_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
#define LIBAVUTIL_VERSION_INT
int ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats, int stats_size, int skip0)
huffman tree builder and VLC generator
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
static const struct @257111027162314367033347246032313251342043035002 planes[]
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
#define MKTAG(a, b, c, d)
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
enum AVColorSpace colorspace
YUV colorspace type.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int slices
Number of slices.
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, a positive or negative value, which is typically indicating the size in bytes of each pict...
This structure stores compressed data.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
LLVidEncDSPContext llvidencdsp
uint8_t * slice_buffer[4]
static void median_predict(UtvideoContext *c, const uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
static int encode_plane(AVCodecContext *avctx, const uint8_t *src, uint8_t *dst, ptrdiff_t stride, int plane_no, int width, int height, PutByteContext *pb)
static void calculate_codes(HuffEntry *he)
static int huff_cmp_sym(const void *a, const void *b)
static void count_usage(uint8_t *src, int width, int height, uint64_t *counts)
static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
static const AVClass utvideo_class
static av_cold int utvideo_encode_close(AVCodecContext *avctx)
static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he)
static int ut_huff_cmp_len(const void *a, const void *b)
static void mangle_rgb_planes(uint8_t *dst[4], ptrdiff_t dst_stride, uint8_t *const src[4], int planes, const int stride[4], int width, int height)
static av_cold int utvideo_encode_init(AVCodecContext *avctx)