30 #include <schroedinger/schro.h>
31 #include <schroedinger/schrodebug.h>
32 #include <schroedinger/schrovideoformat.h>
94 for (idx = 0; idx < num_formats; ++idx) {
96 p_schro_params->
format->chroma_format =
103 "This codec currently only supports planar YUV 4:2:0, 4:2:2"
104 " and 4:4:4 formats.\n");
112 SchroVideoFormatEnum
preset;
118 p_schro_params->
encoder = schro_encoder_new();
120 if (!p_schro_params->
encoder) {
122 "Unrecoverable Error: schro_encoder_new failed. ");
129 schro_encoder_get_video_format(p_schro_params->
encoder);
130 schro_video_format_set_std_video_format(p_schro_params->
format, preset);
138 p_schro_params->
format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV;
140 p_schro_params->
format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625;
142 p_schro_params->
format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525;
146 p_schro_params->
format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV;
148 p_schro_params->
format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV;
152 p_schro_params->
format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA;
158 "This codec currently supports only planar YUV 4:2:0, 4:2:2"
159 " and 4:4:4 formats.\n");
171 schro_encoder_setting_set_double(p_schro_params->
encoder,
173 SCHRO_ENCODER_GOP_INTRA_ONLY);
175 #if FF_API_CODER_TYPE
181 schro_encoder_setting_set_double(p_schro_params->
encoder,
185 schro_encoder_setting_set_double(p_schro_params->
encoder,
188 p_schro_params->
dts = -1;
195 schro_encoder_setting_set_double(p_schro_params->
encoder,
197 SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
200 schro_encoder_setting_set_double(p_schro_params->
encoder,
202 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY);
207 schro_encoder_setting_set_double(p_schro_params->
encoder,
211 schro_encoder_setting_set_double(p_schro_params->
encoder,
213 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);
215 schro_encoder_setting_set_double(p_schro_params->
encoder,
222 schro_encoder_setting_set_double(p_schro_params->
encoder,
223 "interlaced_coding", 1);
225 schro_encoder_setting_set_double(p_schro_params->
encoder,
"open_gop",
230 schro_video_format_set_std_signal_range(p_schro_params->
format,
231 SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
234 schro_encoder_set_video_format(p_schro_params->
encoder,
238 schro_debug_set_level(avctx->
debug);
240 schro_encoder_start(p_schro_params->
encoder);
279 SchroEncoder *encoder = p_schro_params->
encoder;
282 SchroBuffer *enc_buf;
283 int presentation_frame;
285 int last_frame_in_sequence = 0;
291 schro_encoder_end_of_stream(encoder);
300 schro_encoder_push_frame(encoder, in_frame);
309 SchroStateEnum
state;
310 state = schro_encoder_wait(encoder);
312 case SCHRO_STATE_HAVE_BUFFER:
313 case SCHRO_STATE_END_OF_STREAM:
314 enc_buf = schro_encoder_pull(encoder, &presentation_frame);
315 if (enc_buf->length <= 0)
317 parse_code = enc_buf->data[4];
325 enc_buf->length)) < 0) {
331 enc_buf->data, enc_buf->length);
335 if (state == SCHRO_STATE_END_OF_STREAM) {
340 if (!SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) {
341 schro_buffer_unref(enc_buf);
352 if (SCHRO_PARSE_CODE_IS_INTRA(parse_code) &&
353 SCHRO_PARSE_CODE_IS_REFERENCE(parse_code))
365 schro_buffer_unref(enc_buf);
369 case SCHRO_STATE_NEED_FRAME:
373 case SCHRO_STATE_AGAIN:
386 last_frame_in_sequence = 1;
393 pkt_size = p_frame_output->
size;
394 if (last_frame_in_sequence && p_schro_params->
enc_buf_size > 0)
400 #if FF_API_CODED_FRAME
410 pkt->
dts = p_schro_params->
dts++;
411 enc_size = p_frame_output->
size;
415 if (last_frame_in_sequence && p_schro_params->
enc_buf_size > 0) {
416 memcpy(pkt->
data + enc_size, p_schro_params->
enc_buf,
439 schro_encoder_free(p_schro_params->
encoder);
456 #define OFFSET(x) offsetof(SchroEncoderParams, x)
457 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
472 .
name =
"libschroedinger",
477 .priv_class = &libschroedinger_class,
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
uint16_t key_frame
key frame flag.
SchroFrame * ff_create_schro_frame(AVCodecContext *avctx, SchroFrameFormat schro_frame_fmt)
Create a Schro frame based on the dimensions and frame format passed.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
libschroedinger encoder private data
data structures common to libschroedinger decoder and encoder
enum AVPixelFormat ff_pix_fmt
Macro definitions for various function/variable attributes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static void libschroedinger_free_frame(void *data)
uint32_t frame_num
encoded frame number.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
contains a single encoded frame returned from Dirac or Schroedinger
static const struct @84 schro_pixel_format_map[]
uint8_t * p_encbuf
encoded frame data
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int set_chroma_format(AVCodecContext *avctx)
Works out Schro-compatible chroma format.
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
int noarith
enable noarith
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
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. ...
int flags
AV_CODEC_FLAG_*.
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
FFSchroQueue enc_frame_queue
queue storing encoded frames
SchroVideoFormat * format
Schroedinger video format.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
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.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
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.
av_cold void ff_schro_queue_init(FFSchroQueue *queue)
Initialise the queue.
A simple queue implementation used in libschroedinger.
int width
picture width / height.
static av_cold int libschroedinger_encode_init(AVCodecContext *avctx)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static int libschroedinger_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
int eos_signalled
end of sequence signalled
attribute_deprecated int coder_type
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Libavcodec external API header.
main external API structure.
static const AVOption options[]
unsigned char * enc_buf
buffer to store encoder output before writing it to the frame queue
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Describe the class of an AVClass context structure.
#define FF_CODER_TYPE_VLC
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avctx)
Returns the video format preset matching the input video dimensions and time base.
int eos_pulled
end of sequence pulled
static enum AVPixelFormat pix_fmts[]
int global_quality
Global quality for codecs which cannot change it per frame.
static SchroFrame * libschroedinger_frame_from_data(AVCodecContext *avctx, const AVFrame *frame)
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)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
AVCodec ff_libschroedinger_encoder
static int libschroedinger_encode_close(AVCodecContext *avctx)
static const AVClass libschroedinger_class
#define FF_ENABLE_DEPRECATION_WARNINGS
uint32_t size
encoded frame size
int key_frame
1 -> keyframe, 0-> not
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
#define AV_CODEC_FLAG_CLOSED_GOP
AVPixelFormat
Pixel format.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...