33 #include <schroedinger/schro.h>
34 #include <schroedinger/schrodebug.h>
35 #include <schroedinger/schrovideoformat.h>
90 for (idx = 0; idx < num_formats; ++idx) {
93 p_schro_params->
format->chroma_format =
100 "This codec currently only supports planar YUV 4:2:0, 4:2:2"
101 " and 4:4:4 formats.\n");
109 SchroVideoFormatEnum preset;
115 p_schro_params->
encoder = schro_encoder_new();
117 if (!p_schro_params->
encoder) {
119 "Unrecoverable Error: schro_encoder_new failed. ");
126 schro_encoder_get_video_format(p_schro_params->
encoder);
127 schro_video_format_set_std_video_format(p_schro_params->
format, preset);
135 p_schro_params->
format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV;
137 p_schro_params->
format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625;
139 p_schro_params->
format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525;
143 p_schro_params->
format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV;
145 p_schro_params->
format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV;
149 p_schro_params->
format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA;
155 "This codec currently supports only planar YUV 4:2:0, 4:2:2"
156 " and 4:4:4 formats.\n");
170 schro_encoder_setting_set_double(p_schro_params->
encoder,
172 SCHRO_ENCODER_GOP_INTRA_ONLY);
175 schro_encoder_setting_set_double(p_schro_params->
encoder,
176 "enable_noarith", 1);
178 schro_encoder_setting_set_double(p_schro_params->
encoder,
179 "au_distance", avccontext->
gop_size);
181 p_schro_params->
dts = -1;
188 schro_encoder_setting_set_double(p_schro_params->
encoder,
190 SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
193 schro_encoder_setting_set_double(p_schro_params->
encoder,
195 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY);
200 schro_encoder_setting_set_double(p_schro_params->
encoder,
204 schro_encoder_setting_set_double(p_schro_params->
encoder,
206 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);
208 schro_encoder_setting_set_double(p_schro_params->
encoder,
217 schro_encoder_setting_set_double(p_schro_params->
encoder,
218 "interlaced_coding", 1);
220 schro_encoder_setting_set_double(p_schro_params->
encoder,
"open_gop",
225 schro_video_format_set_std_signal_range(p_schro_params->
format,
226 SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
229 schro_encoder_set_video_format(p_schro_params->
encoder,
233 schro_debug_set_level(avccontext->
debug);
235 schro_encoder_start(p_schro_params->
encoder);
246 SchroFrame *in_frame;
255 in_frame->components[0].data,
270 const AVFrame *frame,
int *got_packet)
274 SchroEncoder *encoder = p_schro_params->
encoder;
277 SchroBuffer *enc_buf;
278 int presentation_frame;
280 int last_frame_in_sequence = 0;
286 schro_encoder_end_of_stream(encoder);
294 schro_encoder_push_frame(encoder, in_frame);
302 SchroStateEnum
state;
303 state = schro_encoder_wait(encoder);
305 case SCHRO_STATE_HAVE_BUFFER:
306 case SCHRO_STATE_END_OF_STREAM:
307 enc_buf = schro_encoder_pull(encoder, &presentation_frame);
308 assert(enc_buf->length > 0);
309 assert(enc_buf->length <= buf_size);
310 parse_code = enc_buf->data[4];
320 enc_buf->data, enc_buf->length);
324 if (state == SCHRO_STATE_END_OF_STREAM) {
329 if (!SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) {
330 schro_buffer_unref(enc_buf);
339 if (SCHRO_PARSE_CODE_IS_INTRA(parse_code) &&
340 SCHRO_PARSE_CODE_IS_REFERENCE(parse_code))
352 schro_buffer_unref(enc_buf);
356 case SCHRO_STATE_NEED_FRAME:
360 case SCHRO_STATE_AGAIN:
373 last_frame_in_sequence = 1;
380 pkt_size = p_frame_output->
size;
381 if (last_frame_in_sequence && p_schro_params->
enc_buf_size > 0)
384 av_log(avccontext,
AV_LOG_ERROR,
"Error getting output packet of size %d.\n", pkt_size);
395 pkt->
dts = p_schro_params->
dts++;
396 enc_size = p_frame_output->
size;
400 if (last_frame_in_sequence && p_schro_params->
enc_buf_size > 0) {
401 memcpy(pkt->
data + enc_size, p_schro_params->
enc_buf,
424 schro_encoder_free(p_schro_params->
encoder);
443 .
name =
"libschroedinger",
AVFrame picture
frame being encoded
static int libschroedinger_encode_init(AVCodecContext *avccontext)
#define CODEC_FLAG_CLOSED_GOP
This structure describes decoded (raw) audio or video data.
#define CODEC_FLAG_INTERLACED_ME
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
AVFrame * coded_frame
the picture in the bitstream
uint16_t key_frame
key frame flag.
static const struct @34 schro_pixel_format_map[]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int avpicture_layout(const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height, unsigned char *dest, int dest_size)
Copy pixel data from an AVPicture into a buffer.
libschroedinger encoder private data
four components are given, that's all.
data structures common to libschroedinger decoder and encoder
enum AVPixelFormat ff_pix_fmt
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 ...
#define FF_CODER_TYPE_VLC
static void libschroedinger_free_frame(void *data)
SchroFrame * ff_create_schro_frame(AVCodecContext *avccontext, SchroFrameFormat schro_frame_fmt)
Create a Schro frame based on the dimensions and frame format passed.
uint32_t frame_num
encoded frame number.
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
#define CODEC_FLAG_QSCALE
contains a single encoded frame returned from Dirac or Schroedinger
uint8_t * p_encbuf
encoded frame data
static int init(AVCodecParserContext *s)
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(). ...
SchroEncoder * encoder
Schroedinger encoder handle.
SchroFrameFormat frame_format
Schroedinger frame format.
void * ff_schro_queue_pop(FFSchroQueue *queue)
Return the first element in the queue.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void ff_schro_queue_init(FFSchroQueue *queue)
Initialise the queue.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
FFSchroQueue enc_frame_queue
queue storing encoded frames
static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pkt, const AVFrame *frame, int *got_packet)
SchroVideoFormat * format
Schroedinger video format.
static int libschroedinger_encode_close(AVCodecContext *avccontext)
static SchroFrame * libschroedinger_frame_from_data(AVCodecContext *avccontext, const AVFrame *frame)
int flags
A combination of AV_PKT_FLAG values.
int ff_get_schro_frame_format(SchroChromaFormat schro_pix_fmt, SchroFrameFormat *schro_frame_fmt)
Sets the Schroedinger frame format corresponding to the Schro chroma format passed.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int enc_buf_size
Size of encoder buffer.
int bit_rate
the average bitrate
int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data)
Add an element to the end of the queue.
void ff_schro_queue_free(FFSchroQueue *queue, void(*free_func)(void *))
Free the queue resources.
A simple queue implementation used in libschroedinger.
int width
picture width / height.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avccontext)
Returns the video format preset matching the input video dimensions and time base.
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
int eos_signalled
end of sequence signalled
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
static int set_chroma_format(AVCodecContext *avccontext)
Works out Schro-compatible chroma format.
main external API structure.
static void close(AVCodecParserContext *s)
unsigned char * enc_buf
buffer to store encoder output before writing it to the frame queue
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int eos_pulled
end of sequence pulled
int global_quality
Global quality for codecs which cannot change it per frame.
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
AVCodec ff_libschroedinger_encoder
uint32_t size
encoded frame size
int avpicture_get_size(enum AVPixelFormat 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 key_frame
1 -> keyframe, 0-> not
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
struct SchroEncoderParams SchroEncoderParams
libschroedinger encoder private data
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
AVPixelFormat
Pixel format.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...