Go to the documentation of this file.
59 #define BLOCK_WIDTH (4 * 16U)
60 #define BLOCK_HEIGHT (4 * 16U)
74 int h,
int w,
int stride,
const uint8_t *pfptr)
79 for (
i = dx +
h;
i > dx;
i--) {
80 const uint8_t *nsptr = sptr +
i *
stride + dy * 3;
81 const uint8_t *npfptr = pfptr +
i *
stride + dy * 3;
82 for (j = 0; j <
w * 3; j++) {
83 diff |= npfptr[j] ^ nsptr[j];
105 int h_blocks, v_blocks, nb_blocks;
111 "Input dimensions too large, input must be max 4095x4095 !\n");
115 s->last_key_frame = 0;
117 s->image_width = avctx->
width;
118 s->image_height = avctx->
height;
122 nb_blocks = h_blocks * v_blocks;
126 ? Z_DEFAULT_COMPRESSION
134 int buf_size,
int block_width,
int block_height,
135 const uint8_t *previous_frame,
int *I_frame)
139 int h_blocks, v_blocks, h_part, v_part,
i, j;
145 put_bits(&pb, 4, block_width / 16 - 1);
147 put_bits(&pb, 4, block_height / 16 - 1);
152 h_blocks =
s->image_width / block_width;
153 h_part =
s->image_width % block_width;
154 v_blocks =
s->image_height / block_height;
155 v_part =
s->image_height % block_height;
158 for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) {
160 int y_pos = j * block_height;
161 int cur_blk_height = (j < v_blocks) ? block_height : v_part;
164 for (
i = 0;
i < h_blocks + (h_part ? 1 : 0);
i++) {
165 int x_pos =
i * block_width;
166 int cur_blk_width = (
i < h_blocks) ? block_width : h_part;
168 uint8_t *ptr = buf + buf_pos;
173 s->image_height - (y_pos + cur_blk_height + 1),
174 x_pos, cur_blk_height, cur_blk_width,
177 if (res || *I_frame) {
178 unsigned long zsize = 3 * block_width * block_height + 12;
179 ret = compress2(ptr + 2, &zsize,
s->tmpblock,
180 3 * cur_blk_width * cur_blk_height,
181 s->compression_level);
185 "error while compressing block %dx%d\n",
i, j);
187 bytestream_put_be16(&ptr, zsize);
188 buf_pos += zsize + 2;
189 ff_dlog(
s->avctx,
"buf_pos = %d\n", buf_pos);
192 bytestream_put_be16(&ptr, 0);
208 const AVFrame *pict,
int *got_packet)
211 const uint8_t *prev_frame =
s->previous_frame;
214 int opt_w = 4, opt_h = 4;
217 if (!
s->previous_frame) {
218 prev_frame = pict->
data[0];
233 opt_w * 16, opt_h * 16,
234 prev_frame, &I_frame);
239 ff_dlog(avctx,
"Inserting keyframe at frame %"PRId64
"\n", avctx->
frame_num);
250 s->previous_frame = pict->
data[0];
AVPixelFormat
Pixel format.
const uint8_t * previous_frame
const FFCodec ff_flashsv_encoder
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int copy_region_enc(const uint8_t *sptr, uint8_t *dptr, int dx, int dy, int h, int w, int stride, const uint8_t *pfptr)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
#define FF_COMPRESSION_DEFAULT
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVCodec p
The public AVCodec.
#define FF_CODEC_ENCODE_CB(func)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int flashsv_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define CODEC_LONG_NAME(str)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
static av_cold int flashsv_encode_init(AVCodecContext *avctx)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int flags
A combination of AV_PKT_FLAG values.
#define i(width, name, range_min, range_max)
const char * name
Name of the codec implementation.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
static int encode_bitstream(FlashSVContext *s, const AVFrame *p, uint8_t *buf, int buf_size, int block_width, int block_height, const uint8_t *previous_frame, int *I_frame)
static av_cold int flashsv_encode_end(AVCodecContext *avctx)
int64_t frame_num
Frame counter, set by libavcodec.
main external API structure.
AVBufferRef * prev_frame_buf
A reference to a data buffer.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
This structure stores compressed data.
int width
picture width / height.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.