38 #include <libdirac_encoder/dirac_encoder.h>
82 for (idx = 0; idx < num_formats; ++idx)
94 VIDEO_FORMAT_QSIF525 ,
98 VIDEO_FORMAT_4SIF525 ,
100 VIDEO_FORMAT_SD_480I60 ,
101 VIDEO_FORMAT_SD_576I50 ,
102 VIDEO_FORMAT_HD_720P60 ,
103 VIDEO_FORMAT_HD_720P50 ,
104 VIDEO_FORMAT_HD_1080I60 ,
105 VIDEO_FORMAT_HD_1080I50 ,
106 VIDEO_FORMAT_HD_1080P60 ,
107 VIDEO_FORMAT_HD_1080P50 ,
108 VIDEO_FORMAT_DIGI_CINEMA_2K24 ,
109 VIDEO_FORMAT_DIGI_CINEMA_4K24 ,
123 return (idx < num_formats) ?
139 dirac_encoder_context_init(&p_dirac_params->
enc_ctx, preset);
143 if (p_dirac_params->
enc_ctx.src_params.chroma == formatNK) {
145 "Unsupported pixel format %d. This codec supports only "
146 "Planar YUV formats (yuv420p, yuv422p, yuv444p\n",
154 p_dirac_params->
enc_ctx.src_params.width = avccontext->
width;
155 p_dirac_params->
enc_ctx.src_params.height = avccontext->
height;
164 p_dirac_params->
enc_ctx.decode_flag = 0;
165 p_dirac_params->
enc_ctx.instr_flag = 0;
167 p_dirac_params->
enc_ctx.decode_flag = 1;
168 p_dirac_params->
enc_ctx.instr_flag = 1;
173 p_dirac_params->
enc_ctx.enc_params.num_L1 = 0;
175 p_dirac_params->
enc_ctx.enc_params.using_ac = 0;
189 p_dirac_params->
enc_ctx.enc_params.lossless = 1;
190 }
else if (avccontext->
bit_rate >= 1000)
191 p_dirac_params->
enc_ctx.enc_params.trate = avccontext->
bit_rate / 1000;
193 if ((preset > VIDEO_FORMAT_QCIF || preset < VIDEO_FORMAT_QSIF525) &&
195 p_dirac_params->
enc_ctx.enc_params.trate = 0;
200 p_dirac_params->
enc_ctx.enc_params.picture_coding_mode = 1;
207 "Unrecoverable Error: dirac_encoder_init failed. ");
229 unsigned char *frame,
230 int buf_size,
void *
data)
233 dirac_encoder_state_t
state;
238 int last_frame_in_sequence = 0;
243 dirac_encoder_end_sequence(p_dirac_params->
p_encoder);
258 if (dirac_encoder_load(p_dirac_params->
p_encoder,
262 " dirac_encoder_load failed...\n");
271 p_dirac_params->
p_encoder->enc_buf.buffer = frame;
272 p_dirac_params->
p_encoder->enc_buf.size = buf_size;
274 state = dirac_encoder_output(p_dirac_params->
p_encoder);
277 case ENC_STATE_AVAIL:
279 assert(p_dirac_params->
p_encoder->enc_buf.size > 0);
288 p_dirac_params->
p_encoder->enc_buf.size);
290 p_dirac_params->
p_encoder->enc_buf.buffer,
291 p_dirac_params->
p_encoder->enc_buf.size);
295 if (state == ENC_STATE_EOS) {
302 if (p_dirac_params->
p_encoder->enc_pparams.pnum == -1)
312 if (p_dirac_params->
p_encoder->enc_pparams.ptype == INTRA_PICTURE &&
313 p_dirac_params->
p_encoder->enc_pparams.rtype == REFERENCE_PICTURE)
323 case ENC_STATE_BUFFER:
327 case ENC_STATE_INVALID:
329 "Unrecoverable Dirac Encoder Error. Quitting...\n");
341 last_frame_in_sequence = 1;
345 if (!p_next_output_frame)
348 memcpy(frame, p_next_output_frame->
p_encbuf, p_next_output_frame->
size);
354 enc_size = p_next_output_frame->
size;
358 if (last_frame_in_sequence && p_dirac_params->
enc_buf_size > 0) {
359 memcpy(frame + enc_size, p_dirac_params->
enc_buf,
377 dirac_encoder_close(p_dirac_params->
p_encoder);
uint32_t size
encoded frame size
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
AVFrame * coded_frame
the picture in the bitstream
struct DiracEncoderParams DiracEncoderParams
Dirac encoder private data.
int eos_signalled
end of sequence signalled by user, 0 - false, 1 - true
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
uint8_t * p_encbuf
encoded frame data
four components are given, that's all.
static dirac_chroma_t GetDiracChromaFormat(enum PixelFormat ff_pix_fmt)
Works out Dirac-compatible chroma format.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
uint32_t frame_num
encoded frame number.
uint16_t key_frame
key frame flag.
static const VideoFormat ff_dirac_video_formats[]
Dirac video preset table.
unsigned char * p_in_frame_buf
input frame buffer
DiracSchroQueue enc_frame_queue
queue storing encoded frames
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
contains a single encoded frame returned from Dirac or Schroedinger
int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
int eos_pulled
end of sequence returned by encoder, 0 - false, 1 - true
static int init(AVCodecParserContext *s)
int enc_buf_size
size of encoder buffer
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static void DiracFreeFrame(void *data)
data structures common to libdirac encoder and decoder
void * ff_dirac_schro_queue_pop(DiracSchroQueue *queue)
Return the first element in the queue.
A simple queue implementation used in libdirac and libschroedinger.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const struct @27 dirac_pixel_format_map[]
Table providing a Dirac chroma format to Libav pixel format mapping.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Dirac encoder private data.
AVFrame picture
frame being encoded
int bit_rate
the average bitrate
unsigned char * enc_buf
buffer to store encoder output before writing it to the frame queue
enum PixelFormat ff_pix_fmt
int width
picture width / height.
dirac_encoder_t * p_encoder
Dirac encoder handle.
static av_cold int libdirac_encode_close(AVCodecContext *avccontext)
static VideoFormat GetDiracVideoFormatPreset(AVCodecContext *avccontext)
Returns the video format preset matching the input video dimensions and time base.
int ff_dirac_schro_queue_push_back(DiracSchroQueue *queue, void *p_data)
Add an element to the end of the queue.
main external API structure.
static void close(AVCodecParserContext *s)
#define CODEC_FLAG_QSCALE
Use fixed qscale.
static av_cold int libdirac_encode_init(AVCodecContext *avccontext)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
dirac_encoder_context_t enc_ctx
Dirac encoder context.
#define FF_CODER_TYPE_VLC
int global_quality
Global quality for codecs which cannot change it per frame.
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
static int libdirac_encode_frame(AVCodecContext *avccontext, unsigned char *frame, int buf_size, void *data)
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
AVCodec ff_libdirac_encoder
data structures common to libdirac and libschroedinger
int key_frame
1 -> keyframe, 0-> not
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
void ff_dirac_schro_queue_init(DiracSchroQueue *queue)
Initialise the queue.
int avpicture_layout(const AVPicture *src, enum PixelFormat pix_fmt, int width, int height, unsigned char *dest, int dest_size)
Copy pixel data from an AVPicture into a buffer.
unsigned int ff_dirac_schro_get_video_format_idx(AVCodecContext *avccontext)
Returns the index into the Dirac Schro common video format info table.
void ff_dirac_schro_queue_free(DiracSchroQueue *queue, void(*free_func)(void *))
Free the queue resources.