From 5455384219d873d0d2ddaeb7098da659f4207058 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 18 Feb 2012 09:08:23 +0100 Subject: mpegvideo_enc: force encoding delay of at least 1 frame when low_delay=0 This allows the following commit to extrapolate better dts for the first frame. Pts difference between the first two frames is reused as the difference between pts and dts of the first frame. --- libavcodec/mpegvideo_enc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 10323fc..d8a7c70 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -890,7 +890,8 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) AVFrame *pic = NULL; int64_t pts; int i; - const int encoding_delay = s->max_b_frames; + const int encoding_delay = s->max_b_frames ? s->max_b_frames : + (s->low_delay ? 0 : 1); int direct = 1; if (pic_arg) { -- cgit v1.1 From 445a7d48b13c8c6607b69156233fc8d5fed3b396 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 10 Feb 2012 10:30:05 +0100 Subject: mpegvideo_enc: switch to encode2(). --- libavcodec/flvenc.c | 2 +- libavcodec/h261enc.c | 2 +- libavcodec/mjpegenc.c | 2 +- libavcodec/mpeg12enc.c | 4 ++-- libavcodec/mpeg4videoenc.c | 2 +- libavcodec/mpegvideo.h | 11 ++++++++++- libavcodec/mpegvideo_enc.c | 44 ++++++++++++++++++++++++++++++++------------ libavcodec/rv10enc.c | 2 +- libavcodec/rv20enc.c | 2 +- libavcodec/wmv2enc.c | 2 +- 10 files changed, 51 insertions(+), 22 deletions(-) diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c index 822dba9..332592d 100644 --- a/libavcodec/flvenc.c +++ b/libavcodec/flvenc.c @@ -90,7 +90,7 @@ AVCodec ff_flv_encoder = { .id = CODEC_ID_FLV1, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"), diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index d33c724..0ae48ca 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -327,7 +327,7 @@ AVCodec ff_h261_encoder = { .id = CODEC_ID_H261, .priv_data_size = sizeof(H261Context), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("H.261"), diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index ef47cea..bb036ef 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -451,7 +451,7 @@ AVCodec ff_mjpeg_encoder = { .id = CODEC_ID_MJPEG, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index be2f1e9..c53d99b 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -954,7 +954,7 @@ AVCodec ff_mpeg1video_encoder = { .id = CODEC_ID_MPEG1VIDEO, .priv_data_size = sizeof(MpegEncContext), .init = encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .supported_framerates= avpriv_frame_rate_tab+1, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, @@ -969,7 +969,7 @@ AVCodec ff_mpeg2video_encoder = { .id = CODEC_ID_MPEG2VIDEO, .priv_data_size = sizeof(MpegEncContext), .init = encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .supported_framerates= avpriv_frame_rate_tab+1, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE}, diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 633c8d2..d512daa 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -1336,7 +1336,7 @@ AVCodec ff_mpeg4_encoder = { .id = CODEC_ID_MPEG4, .priv_data_size = sizeof(MpegEncContext), .init = encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index e542369..9753d10 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -261,6 +261,14 @@ typedef struct MpegEncContext { * offsets used in asm. */ int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video() + /** + * pts difference between the first and second input frame, used for + * calculating dts of the first frame when there's a delay */ + int64_t dts_delta; + /** + * reordered pts to be used as dts for the next output frame when there's + * a delay */ + int64_t reordered_pts; /** bit output */ PutBitContext pb; @@ -694,7 +702,8 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx); void ff_MPV_frame_end(MpegEncContext *s); int ff_MPV_encode_init(AVCodecContext *avctx); int ff_MPV_encode_end(AVCodecContext *avctx); -int ff_MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data); +int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *frame, int *got_packet); void ff_MPV_common_init_mmx(MpegEncContext *s); void ff_MPV_common_init_axp(MpegEncContext *s); void ff_MPV_common_init_mmi(MpegEncContext *s); diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index d8a7c70..68adef7 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -909,6 +909,9 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) "last=%"PRId64"\n", pts, s->user_specified_pts); return -1; } + + if (!s->low_delay && pic_arg->display_picture_number == 1) + s->dts_delta = time - last; } s->user_specified_pts = pts; } else { @@ -1374,20 +1377,23 @@ no_output_pic: return 0; } -int ff_MPV_encode_picture(AVCodecContext *avctx, - unsigned char *buf, int buf_size, void *data) +int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *pic_arg, int *got_packet) { MpegEncContext *s = avctx->priv_data; - AVFrame *pic_arg = data; - int i, stuffing_count; + int i, stuffing_count, ret; int context_count = s->slice_context_count; + if (!pkt->data && + (ret = ff_alloc_packet(pkt, s->mb_width*s->mb_height*MAX_MB_BYTES)) < 0) + return ret; + for (i = 0; i < context_count; i++) { int start_y = s->thread_context[i]->start_mb_y; int end_y = s->thread_context[i]-> end_mb_y; int h = s->mb_height; - uint8_t *start = buf + (size_t)(((int64_t) buf_size) * start_y / h); - uint8_t *end = buf + (size_t)(((int64_t) buf_size) * end_y / h); + uint8_t *start = pkt->data + (size_t)(((int64_t) pkt->size) * start_y / h); + uint8_t *end = pkt->data + (size_t)(((int64_t) pkt->size) * end_y / h); init_put_bits(&s->thread_context[i]->pb, start, end - start); } @@ -1547,13 +1553,27 @@ vbv_retry: } s->total_bits += s->frame_bits; avctx->frame_bits = s->frame_bits; + + pkt->pts = s->current_picture.f.pts; + if (!s->low_delay) { + if (!s->current_picture.f.coded_picture_number) + pkt->dts = pkt->pts - s->dts_delta; + else + pkt->dts = s->reordered_pts; + s->reordered_pts = s->input_picture[0]->f.pts; + } else + pkt->dts = pkt->pts; + if (s->current_picture.f.key_frame) + pkt->flags |= AV_PKT_FLAG_KEY; } else { assert((put_bits_ptr(&s->pb) == s->pb.buf)); s->frame_bits = 0; } assert((s->frame_bits & 7) == 0); - return s->frame_bits / 8; + pkt->size = s->frame_bits / 8; + *got_packet = !!pkt->size; + return 0; } static inline void dct_single_coeff_elimination(MpegEncContext *s, @@ -4042,7 +4062,7 @@ AVCodec ff_h263_encoder = { .id = CODEC_ID_H263, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"), @@ -4069,7 +4089,7 @@ AVCodec ff_h263p_encoder = { .id = CODEC_ID_H263P, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .capabilities = CODEC_CAP_SLICE_THREADS, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, @@ -4083,7 +4103,7 @@ AVCodec ff_msmpeg4v2_encoder = { .id = CODEC_ID_MSMPEG4V2, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"), @@ -4095,7 +4115,7 @@ AVCodec ff_msmpeg4v3_encoder = { .id = CODEC_ID_MSMPEG4V3, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"), @@ -4107,7 +4127,7 @@ AVCodec ff_wmv1_encoder = { .id = CODEC_ID_WMV1, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"), diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c index 0591cec..47fb222 100644 --- a/libavcodec/rv10enc.c +++ b/libavcodec/rv10enc.c @@ -62,7 +62,7 @@ AVCodec ff_rv10_encoder = { .id = CODEC_ID_RV10, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"), diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c index bd80c15..ace70d1 100644 --- a/libavcodec/rv20enc.c +++ b/libavcodec/rv20enc.c @@ -63,7 +63,7 @@ AVCodec ff_rv20_encoder = { .id = CODEC_ID_RV20, .priv_data_size = sizeof(MpegEncContext), .init = ff_MPV_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"), diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c index 5ef8d8c..4948a29 100644 --- a/libavcodec/wmv2enc.c +++ b/libavcodec/wmv2enc.c @@ -217,7 +217,7 @@ AVCodec ff_wmv2_encoder = { .id = CODEC_ID_WMV2, .priv_data_size = sizeof(Wmv2Context), .init = wmv2_encode_init, - .encode = ff_MPV_encode_picture, + .encode2 = ff_MPV_encode_picture, .close = ff_MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 8"), -- cgit v1.1 From 1a58daed0f3450656a52766bea65c82d0e855b6b Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Sat, 18 Feb 2012 01:38:01 +0530 Subject: sunrastenc: set keyframe flag for the output packet. Signed-off-by: Anton Khirnov --- libavcodec/sunrastenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/sunrastenc.c b/libavcodec/sunrastenc.c index 21d6fc4..a9b4749 100644 --- a/libavcodec/sunrastenc.c +++ b/libavcodec/sunrastenc.c @@ -199,6 +199,7 @@ static int sunrast_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, AV_WB32(&avpkt->data[16], s->length); *got_packet_ptr = 1; + avpkt->flags |= AV_PKT_FLAG_KEY; avpkt->size = bytestream2_tell_p(&s->p); return 0; } -- cgit v1.1 From 566df2eea2d8330748e770a7e2ab72df567cd487 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Sat, 18 Feb 2012 02:04:24 +0530 Subject: sunrast: use RLE trigger macro inplace of the hard coded value. Signed-off-by: Anton Khirnov --- libavcodec/sunrast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c index 8754fc5..fef17b4 100644 --- a/libavcodec/sunrast.c +++ b/libavcodec/sunrast.c @@ -148,7 +148,7 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data, if (buf_end - buf < 1) return AVERROR_INVALIDDATA; - if ((value = *buf++) == 0x80) { + if ((value = *buf++) == RLE_TRIGGER) { run = *buf++ + 1; if (run != 1) value = *buf++; -- cgit v1.1 From e04ca1d4cea98db33020784834f2473e7ac60395 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 18 Feb 2012 01:25:46 +0000 Subject: ttadec: cosmetics: reindent Signed-off-by: Paul B Mahol Signed-off-by: Justin Ruggles --- libavcodec/tta.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/tta.c b/libavcodec/tta.c index 6f4d161..269ba86 100644 --- a/libavcodec/tta.c +++ b/libavcodec/tta.c @@ -404,10 +404,10 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, // fixed order prediction #define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k) switch (s->bps) { - case 1: *p += PRED(*predictor, 4); break; - case 2: - case 3: *p += PRED(*predictor, 5); break; - case 4: *p += *predictor; break; + case 1: *p += PRED(*predictor, 4); break; + case 2: + case 3: *p += PRED(*predictor, 5); break; + case 4: *p += *predictor; break; } *predictor = *p; -- cgit v1.1 From aac63cef209877df62d3631e4d04187b94574136 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sun, 19 Feb 2012 10:34:40 +0100 Subject: examples: unbreak compilation Update api so it will compile again. --- libavcodec/api-example.c | 11 ++++------- libavformat/output-example.c | 17 +++++------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/libavcodec/api-example.c b/libavcodec/api-example.c index 970a90e..93d6c22 100644 --- a/libavcodec/api-example.c +++ b/libavcodec/api-example.c @@ -74,7 +74,7 @@ static void audio_encode_example(const char *filename) c->channels = 2; /* open it */ - if (avcodec_open(c, codec) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } @@ -139,7 +139,7 @@ static void audio_decode_example(const char *outfilename, const char *filename) c = avcodec_alloc_context3(codec); /* open it */ - if (avcodec_open(c, codec) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } @@ -242,7 +242,7 @@ static void video_encode_example(const char *filename) c->pix_fmt = PIX_FMT_YUV420P; /* open it */ - if (avcodec_open(c, codec) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } @@ -369,7 +369,7 @@ static void video_decode_example(const char *outfilename, const char *filename) available in the bitstream. */ /* open it */ - if (avcodec_open(c, codec) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } @@ -456,9 +456,6 @@ int main(int argc, char **argv) { const char *filename; - /* must be called before using avcodec lib */ - avcodec_init(); - /* register all the codecs */ avcodec_register_all(); diff --git a/libavformat/output-example.c b/libavformat/output-example.c index a1702cd..50290aa 100644 --- a/libavformat/output-example.c +++ b/libavformat/output-example.c @@ -65,7 +65,7 @@ static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id) AVCodecContext *c; AVStream *st; - st = av_new_stream(oc, 1); + st = avformat_new_stream(oc, NULL); if (!st) { fprintf(stderr, "Could not alloc stream\n"); exit(1); @@ -103,7 +103,7 @@ static void open_audio(AVFormatContext *oc, AVStream *st) } /* open it */ - if (avcodec_open(c, codec) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } @@ -164,7 +164,7 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st) get_audio_frame(samples, audio_input_frame_size, c->channels); - pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples); + pkt.size = avcodec_encode_audio2(c, audio_outbuf, audio_outbuf_size, samples); if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base); @@ -275,7 +275,7 @@ static void open_video(AVFormatContext *oc, AVStream *st) } /* open the codec */ - if (avcodec_open(c, codec) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } @@ -482,13 +482,6 @@ int main(int argc, char **argv) audio_st = add_audio_stream(oc, fmt->audio_codec); } - /* set the output parameters (must be done even if no - parameters). */ - if (av_set_parameters(oc, NULL) < 0) { - fprintf(stderr, "Invalid output format parameters\n"); - return 1; - } - av_dump_format(oc, 0, filename, 1); /* now that all the parameters are set, we can open the audio and @@ -507,7 +500,7 @@ int main(int argc, char **argv) } /* write the stream header, if any */ - av_write_header(oc); + avformat_write_header(oc, NULL); for(;;) { /* compute current audio and video time */ -- cgit v1.1 From 6b8b0fe2bc57fdd606074e52ba73cd9b3d95e644 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sun, 19 Feb 2012 10:35:45 +0100 Subject: doxy: remove reference to removed api --- libavformat/avformat.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7b67889..58565fb 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -433,15 +433,14 @@ typedef struct AVInputFormat { /** * Read the format header and initialize the AVFormatContext - * structure. Return 0 if OK. 'ap' if non-NULL contains - * additional parameters. Only used in raw format right - * now. 'av_new_stream' should be called to create new streams. + * structure. Return 0 if OK. Only used in raw format right + * now. 'avformat_new_stream' should be called to create new streams. */ int (*read_header)(struct AVFormatContext *); /** * Read one packet and put it in 'pkt'. pts and flags are also - * set. 'av_new_stream' can be called only if the flag + * set. 'avformat_new_stream' can be called only if the flag * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a * background thread). * @return 0 on success, < 0 on error. -- cgit v1.1