History

Merge remote-tracking branch 'qatar/master'

* qatar/master: doxy: remove reference to removed api examples: unbreak compilation ttadec: cosmetics: reindent sunrast: use RLE trigger macro inplace of the hard coded value. sunrastenc: set keyframe flag for the output packet. mpegvideo_enc: switch to encode2(). mpegvideo_enc: force encoding delay of at least 1 frame when low_delay=0 Conflicts: doc/examples/muxing.c

Michael Niedermayer committed 14 years ago

Commit be2e2112 parents f4f386d 6b8b0fe16 files · +75 −46Browse files

Unified · Split

16 files
  1. doc/examples/decoding_encoding.c +4 −4
  2. doc/examples/muxing.c +3 −3
  3. libavcodec/flvenc.c +1 −1
  4. libavcodec/h261enc.c +1 −1
  5. libavcodec/mjpegenc.c +6 −7
  6. libavcodec/mpeg12enc.c +2 −2
  7. libavcodec/mpeg4videoenc.c +1 −1
  8. libavcodec/mpegvideo.h +10 −1
  9. libavcodec/mpegvideo_enc.c +35 −14
  10. libavcodec/rv10enc.c +1 −1
  11. libavcodec/rv20enc.c +1 −1
  12. libavcodec/sunrast.c +1 −1
  13. libavcodec/sunrastenc.c +1 −0
  14. libavcodec/tta.c +4 −4
  15. libavcodec/wmv2enc.c +1 −1
  16. libavformat/avformat.h +3 −4
doc/examples/decoding_encoding.c+4−4
@@ -70,7 +70,7 @@ static void audio_encode_example(const char *filename) · 69 unmodified lines
7070 c->sample_fmt = AV_SAMPLE_FMT_S16;
7171
7272 /* open it */
73− if (avcodec_open(c, codec) < 0) {
73+ if (avcodec_open2(c, codec, NULL) < 0) {
7474 fprintf(stderr, "could not open codec\n");
7575 exit(1);
7676 }
@@ -135,7 +135,7 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 58 unmodified lines
135135 c = avcodec_alloc_context3(codec);
136136
137137 /* open it */
138− if (avcodec_open(c, codec) < 0) {
138+ if (avcodec_open2(c, codec, NULL) < 0) {
139139 fprintf(stderr, "could not open codec\n");
140140 exit(1);
141141 }
@@ -243,7 +243,7 @@ static void video_encode_example(const char *filename, int codec_id) · 101 unmodified lines
243243 av_opt_set(c->priv_data, "preset", "slow", 0);
244244
245245 /* open it */
246− if (avcodec_open(c, codec) < 0) {
246+ if (avcodec_open2(c, codec, NULL) < 0) {
247247 fprintf(stderr, "could not open codec\n");
248248 exit(1);
249249 }
@@ -366,7 +366,7 @@ static void video_decode_example(const char *outfilename, const char *filename) · 116 unmodified lines
366366 available in the bitstream. */
367367
368368 /* open it */
369− if (avcodec_open(c, codec) < 0) {
369+ if (avcodec_open2(c, codec, NULL) < 0) {
370370 fprintf(stderr, "could not open codec\n");
371371 exit(1);
372372 }
doc/examples/muxing.c+3−3
@@ -103,7 +103,7 @@ static void open_audio(AVFormatContext *oc, AVStream *st) · 102 unmodified lines
103103 }
104104
105105 /* open it */
106− if (avcodec_open(c, codec) < 0) {
106+ if (avcodec_open2(c, codec, NULL) < 0) {
107107 fprintf(stderr, "could not open codec\n");
108108 exit(1);
109109 }
@@ -164,7 +164,7 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st) · 54 unmodified lines
164164
165165 get_audio_frame(samples, audio_input_frame_size, c->channels);
166166
167− pkt.size = avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples);
167+ pkt.size = avcodec_encode_audio2(c, audio_outbuf, audio_outbuf_size, samples);
168168
169169 if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE)
170170 pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
@@ -284,7 +284,7 @@ static void open_video(AVFormatContext *oc, AVStream *st) · 113 unmodified lines
284284 }
285285
286286 /* open the codec */
287− if (avcodec_open(c, codec) < 0) {
287+ if (avcodec_open2(c, codec, NULL) < 0) {
288288 fprintf(stderr, "could not open codec\n");
289289 exit(1);
290290 }
libavcodec/flvenc.c+1−1
@@ -90,7 +90,7 @@ AVCodec ff_flv_encoder = { · 89 unmodified lines
9090 .id = CODEC_ID_FLV1,
9191 .priv_data_size = sizeof(MpegEncContext),
9292 .init = ff_MPV_encode_init,
93− .encode = ff_MPV_encode_picture,
93+ .encode2 = ff_MPV_encode_picture,
9494 .close = ff_MPV_encode_end,
9595 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
9696 .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
libavcodec/h261enc.c+1−1
@@ -327,7 +327,7 @@ AVCodec ff_h261_encoder = { · 326 unmodified lines
327327 .id = CODEC_ID_H261,
328328 .priv_data_size = sizeof(H261Context),
329329 .init = ff_MPV_encode_init,
330− .encode = ff_MPV_encode_picture,
330+ .encode2 = ff_MPV_encode_picture,
331331 .close = ff_MPV_encode_end,
332332 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
333333 .long_name= NULL_IF_CONFIG_SMALL("H.261"),
libavcodec/mjpegenc.c+6−7
@@ -452,11 +452,10 @@ void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64]) · 451 unmodified lines
452452
453453 // maximum over s->mjpeg_vsample[i]
454454 #define V_MAX 2
455−static int amv_encode_picture(AVCodecContext *avctx,
456− unsigned char *buf, int buf_size, void *data)
457−{
455+static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
456+ AVFrame *pic, int *got_packet)
458457
459− AVFrame* pic=data;
458+{
460459 MpegEncContext *s = avctx->priv_data;
461460 int i;
462461
@@ -469,7 +468,7 @@ static int amv_encode_picture(AVCodecContext *avctx, · 6 unmodified lines
469468 pic->data[i] += (pic->linesize[i] * (s->mjpeg_vsample[i] * (8 * s->mb_height -((s->height/V_MAX)&7)) - 1 ));
470469 pic->linesize[i] *= -1;
471470 }
472− return ff_MPV_encode_picture(avctx,buf, buf_size, pic);
471+ return ff_MPV_encode_picture(avctx, pkt, pic, got_packet);
473472 }
474473
475474 AVCodec ff_mjpeg_encoder = {
@@ -478,7 +477,7 @@ AVCodec ff_mjpeg_encoder = { · 2 unmodified lines
478477 .id = CODEC_ID_MJPEG,
479478 .priv_data_size = sizeof(MpegEncContext),
480479 .init = ff_MPV_encode_init,
481− .encode = ff_MPV_encode_picture,
480+ .encode2 = ff_MPV_encode_picture,
482481 .close = ff_MPV_encode_end,
483482 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE},
484483 .long_name= NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
@@ -490,7 +489,7 @@ AVCodec ff_amv_encoder = { · 5 unmodified lines
490489 .id = CODEC_ID_AMV,
491490 .priv_data_size = sizeof(MpegEncContext),
492491 .init = ff_MPV_encode_init,
493− .encode = amv_encode_picture,
492+ .encode2 = amv_encode_picture,
494493 .close = ff_MPV_encode_end,
495494 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE},
496495 .long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
libavcodec/mpeg12enc.c+2−2
@@ -966,7 +966,7 @@ AVCodec ff_mpeg1video_encoder = { · 965 unmodified lines
966966 .id = CODEC_ID_MPEG1VIDEO,
967967 .priv_data_size = sizeof(MpegEncContext),
968968 .init = encode_init,
969− .encode = ff_MPV_encode_picture,
969+ .encode2 = ff_MPV_encode_picture,
970970 .close = ff_MPV_encode_end,
971971 .supported_framerates= avpriv_frame_rate_tab+1,
972972 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
@@ -981,7 +981,7 @@ AVCodec ff_mpeg2video_encoder = { · 8 unmodified lines
981981 .id = CODEC_ID_MPEG2VIDEO,
982982 .priv_data_size = sizeof(MpegEncContext),
983983 .init = encode_init,
984− .encode = ff_MPV_encode_picture,
984+ .encode2 = ff_MPV_encode_picture,
985985 .close = ff_MPV_encode_end,
986986 .supported_framerates= avpriv_frame_rate_tab+1,
987987 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE},
libavcodec/mpeg4videoenc.c+1−1
@@ -1346,7 +1346,7 @@ AVCodec ff_mpeg4_encoder = { · 1345 unmodified lines
13461346 .id = CODEC_ID_MPEG4,
13471347 .priv_data_size = sizeof(MpegEncContext),
13481348 .init = encode_init,
1349− .encode = ff_MPV_encode_picture,
1349+ .encode2 = ff_MPV_encode_picture,
13501350 .close = ff_MPV_encode_end,
13511351 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
13521352 .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
libavcodec/mpegvideo.h+10−1
@@ -263,6 +263,14 @@ typedef struct MpegEncContext { · 262 unmodified lines
263263 * offsets used in asm. */
264264
265265 int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
266+ /**
267+ * pts difference between the first and second input frame, used for
268+ * calculating dts of the first frame when there's a delay */
269+ int64_t dts_delta;
270+ /**
271+ * reordered pts to be used as dts for the next output frame when there's
272+ * a delay */
273+ int64_t reordered_pts;
266274
267275 /** bit output */
268276 PutBitContext pb;
@@ -702,7 +710,8 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx); · 433 unmodified lines
702710 void ff_MPV_frame_end(MpegEncContext *s);
703711 int ff_MPV_encode_init(AVCodecContext *avctx);
704712 int ff_MPV_encode_end(AVCodecContext *avctx);
705−int ff_MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data);
713+int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
714+ const AVFrame *frame, int *got_packet);
706715 void ff_MPV_common_init_mmx(MpegEncContext *s);
707716 void ff_MPV_common_init_axp(MpegEncContext *s);
708717 void ff_MPV_common_init_mmi(MpegEncContext *s);
libavcodec/mpegvideo_enc.c+35−14
@@ -897,7 +897,8 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) · 896 unmodified lines
897897 AVFrame *pic = NULL;
898898 int64_t pts;
899899 int i;
900− const int encoding_delay = s->max_b_frames;
900+ const int encoding_delay = s->max_b_frames ? s->max_b_frames :
901+ (s->low_delay ? 0 : 1);
901902 int direct = 1;
902903
903904 if (pic_arg) {
@@ -915,6 +916,9 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) · 11 unmodified lines
915916 "last=%"PRId64"\n", pts, s->user_specified_pts);
916917 return -1;
917918 }
919+
920+ if (!s->low_delay && pic_arg->display_picture_number == 1)
921+ s->dts_delta = time - last;
918922 }
919923 s->user_specified_pts = pts;
920924 } else {
@@ -1384,20 +1388,23 @@ no_output_pic: · 463 unmodified lines
13841388 return 0;
13851389 }
13861390
1387−int ff_MPV_encode_picture(AVCodecContext *avctx,
1388− unsigned char *buf, int buf_size, void *data)
1391+int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
1392+ const AVFrame *pic_arg, int *got_packet)
13891393 {
13901394 MpegEncContext *s = avctx->priv_data;
1391− AVFrame *pic_arg = data;
1392− int i, stuffing_count;
1395+ int i, stuffing_count, ret;
13931396 int context_count = s->slice_context_count;
13941397
1398+ if (!pkt->data &&
1399+ (ret = ff_alloc_packet(pkt, s->mb_width*s->mb_height*(MAX_MB_BYTES+100)+10000)) < 0)
1400+ return ret;
1401+
13951402 for (i = 0; i < context_count; i++) {
13961403 int start_y = s->thread_context[i]->start_mb_y;
13971404 int end_y = s->thread_context[i]-> end_mb_y;
13981405 int h = s->mb_height;
1399− uint8_t *start = buf + (size_t)(((int64_t) buf_size) * start_y / h);
1400− uint8_t *end = buf + (size_t)(((int64_t) buf_size) * end_y / h);
1406+ uint8_t *start = pkt->data + (size_t)(((int64_t) pkt->size) * start_y / h);
1407+ uint8_t *end = pkt->data + (size_t)(((int64_t) pkt->size) * end_y / h);
14011408
14021409 init_put_bits(&s->thread_context[i]->pb, start, end - start);
14031410 }
@@ -1557,13 +1564,27 @@ vbv_retry: · 153 unmodified lines
15571564 }
15581565 s->total_bits += s->frame_bits;
15591566 avctx->frame_bits = s->frame_bits;
1567+
1568+ pkt->pts = s->current_picture.f.pts;
1569+ if (!s->low_delay) {
1570+ if (!s->current_picture.f.coded_picture_number)
1571+ pkt->dts = pkt->pts - s->dts_delta;
1572+ else
1573+ pkt->dts = s->reordered_pts;
1574+ s->reordered_pts = s->input_picture[0]->f.pts;
1575+ } else
1576+ pkt->dts = pkt->pts;
1577+ if (s->current_picture.f.key_frame)
1578+ pkt->flags |= AV_PKT_FLAG_KEY;
15601579 } else {
15611580 assert((put_bits_ptr(&s->pb) == s->pb.buf));
15621581 s->frame_bits = 0;
15631582 }
15641583 assert((s->frame_bits & 7) == 0);
15651584
1566− return s->frame_bits / 8;
1585+ pkt->size = s->frame_bits / 8;
1586+ *got_packet = !!pkt->size;
1587+ return 0;
15671588 }
15681589
15691590 static inline void dct_single_coeff_elimination(MpegEncContext *s,
@@ -2385,7 +2406,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ · 815 unmodified lines
23852406 if(s->data_partitioning){
23862407 if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES
23872408 || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){
2388− av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
2409+ av_log(s->avctx, AV_LOG_ERROR, "encoded partitioned frame too large\n");
23892410 return -1;
23902411 }
23912412 }
@@ -4084,7 +4105,7 @@ AVCodec ff_h263_encoder = { · 1692 unmodified lines
40844105 .id = CODEC_ID_H263,
40854106 .priv_data_size = sizeof(MpegEncContext),
40864107 .init = ff_MPV_encode_init,
4087− .encode = ff_MPV_encode_picture,
4108+ .encode2 = ff_MPV_encode_picture,
40884109 .close = ff_MPV_encode_end,
40894110 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
40904111 .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"),
@@ -4111,7 +4132,7 @@ AVCodec ff_h263p_encoder = { · 20 unmodified lines
41114132 .id = CODEC_ID_H263P,
41124133 .priv_data_size = sizeof(MpegEncContext),
41134134 .init = ff_MPV_encode_init,
4114− .encode = ff_MPV_encode_picture,
4135+ .encode2 = ff_MPV_encode_picture,
41154136 .close = ff_MPV_encode_end,
41164137 .capabilities = CODEC_CAP_SLICE_THREADS,
41174138 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
@@ -4125,7 +4146,7 @@ AVCodec ff_msmpeg4v2_encoder = { · 7 unmodified lines
41254146 .id = CODEC_ID_MSMPEG4V2,
41264147 .priv_data_size = sizeof(MpegEncContext),
41274148 .init = ff_MPV_encode_init,
4128− .encode = ff_MPV_encode_picture,
4149+ .encode2 = ff_MPV_encode_picture,
41294150 .close = ff_MPV_encode_end,
41304151 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
41314152 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
@@ -4137,7 +4158,7 @@ AVCodec ff_msmpeg4v3_encoder = { · 5 unmodified lines
41374158 .id = CODEC_ID_MSMPEG4V3,
41384159 .priv_data_size = sizeof(MpegEncContext),
41394160 .init = ff_MPV_encode_init,
4140− .encode = ff_MPV_encode_picture,
4161+ .encode2 = ff_MPV_encode_picture,
41414162 .close = ff_MPV_encode_end,
41424163 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
41434164 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
@@ -4149,7 +4170,7 @@ AVCodec ff_wmv1_encoder = { · 5 unmodified lines
41494170 .id = CODEC_ID_WMV1,
41504171 .priv_data_size = sizeof(MpegEncContext),
41514172 .init = ff_MPV_encode_init,
4152− .encode = ff_MPV_encode_picture,
4173+ .encode2 = ff_MPV_encode_picture,
41534174 .close = ff_MPV_encode_end,
41544175 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
41554176 .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
libavcodec/rv10enc.c+1−1
@@ -62,7 +62,7 @@ AVCodec ff_rv10_encoder = { · 61 unmodified lines
6262 .id = CODEC_ID_RV10,
6363 .priv_data_size = sizeof(MpegEncContext),
6464 .init = ff_MPV_encode_init,
65− .encode = ff_MPV_encode_picture,
65+ .encode2 = ff_MPV_encode_picture,
6666 .close = ff_MPV_encode_end,
6767 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
6868 .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
libavcodec/rv20enc.c+1−1
@@ -63,7 +63,7 @@ AVCodec ff_rv20_encoder = { · 62 unmodified lines
6363 .id = CODEC_ID_RV20,
6464 .priv_data_size = sizeof(MpegEncContext),
6565 .init = ff_MPV_encode_init,
66− .encode = ff_MPV_encode_picture,
66+ .encode2 = ff_MPV_encode_picture,
6767 .close = ff_MPV_encode_end,
6868 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
6969 .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
libavcodec/sunrast.c+1−1
@@ -165,7 +165,7 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data, · 164 unmodified lines
165165 if (buf_end - buf < 1)
166166 return AVERROR_INVALIDDATA;
167167
168− if ((value = *buf++) == 0x80) {
168+ if ((value = *buf++) == RLE_TRIGGER) {
169169 run = *buf++ + 1;
170170 if (run != 1)
171171 value = *buf++;
libavcodec/sunrastenc.c+1−0
@@ -199,6 +199,7 @@ static int sunrast_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 198 unmodified lines
199199 AV_WB32(&avpkt->data[16], s->length);
200200
201201 *got_packet_ptr = 1;
202+ avpkt->flags |= AV_PKT_FLAG_KEY;
202203 avpkt->size = bytestream2_tell_p(&s->p);
203204 return 0;
204205 }
libavcodec/tta.c+4−4
@@ -419,10 +419,10 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, · 418 unmodified lines
419419 // fixed order prediction
420420 #define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k)
421421 switch (s->bps) {
422− case 1: *p += PRED(*predictor, 4); break;
423− case 2:
424− case 3: *p += PRED(*predictor, 5); break;
425− case 4: *p += *predictor; break;
422+ case 1: *p += PRED(*predictor, 4); break;
423+ case 2:
424+ case 3: *p += PRED(*predictor, 5); break;
425+ case 4: *p += *predictor; break;
426426 }
427427 *predictor = *p;
428428
libavcodec/wmv2enc.c+1−1
@@ -217,7 +217,7 @@ AVCodec ff_wmv2_encoder = { · 216 unmodified lines
217217 .id = CODEC_ID_WMV2,
218218 .priv_data_size = sizeof(Wmv2Context),
219219 .init = wmv2_encode_init,
220− .encode = ff_MPV_encode_picture,
220+ .encode2 = ff_MPV_encode_picture,
221221 .close = ff_MPV_encode_end,
222222 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
223223 .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 8"),
libavformat/avformat.h+3−4
@@ -439,15 +439,14 @@ typedef struct AVInputFormat { · 438 unmodified lines
439439
440440 /**
441441 * Read the format header and initialize the AVFormatContext
442− * structure. Return 0 if OK. 'ap' if non-NULL contains
443− * additional parameters. Only used in raw format right
444− * now. 'av_new_stream' should be called to create new streams.
442+ * structure. Return 0 if OK. Only used in raw format right
443+ * now. 'avformat_new_stream' should be called to create new streams.
445444 */
446445 int (*read_header)(struct AVFormatContext *);
447446
448447 /**
449448 * Read one packet and put it in 'pkt'. pts and flags are also
450− * set. 'av_new_stream' can be called only if the flag
449+ * set. 'avformat_new_stream' can be called only if the flag
451450 * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
452451 * background thread).
453452 * @return 0 on success, < 0 on error.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t