283
279
MPV_encode_defaults(s);
285
281
switch (avctx->codec_id) {
286
case CODEC_ID_MPEG2VIDEO:
287
if (avctx->pix_fmt != PIX_FMT_YUV420P &&
288
avctx->pix_fmt != PIX_FMT_YUV422P) {
282
case AV_CODEC_ID_MPEG2VIDEO:
283
if (avctx->pix_fmt != AV_PIX_FMT_YUV420P &&
284
avctx->pix_fmt != AV_PIX_FMT_YUV422P) {
289
285
av_log(avctx, AV_LOG_ERROR,
290
286
"only YUV420 and YUV422 are supported\n");
295
if (avctx->pix_fmt != PIX_FMT_YUVJ420P &&
296
avctx->pix_fmt != PIX_FMT_YUVJ422P &&
297
avctx->pix_fmt != PIX_FMT_YUVJ444P &&
298
avctx->pix_fmt != PIX_FMT_BGRA &&
299
((avctx->pix_fmt != PIX_FMT_YUV420P &&
300
avctx->pix_fmt != PIX_FMT_YUV422P &&
301
avctx->pix_fmt != PIX_FMT_YUV444P) ||
290
case AV_CODEC_ID_LJPEG:
291
if (avctx->pix_fmt != AV_PIX_FMT_YUVJ420P &&
292
avctx->pix_fmt != AV_PIX_FMT_YUVJ422P &&
293
avctx->pix_fmt != AV_PIX_FMT_YUVJ444P &&
294
avctx->pix_fmt != AV_PIX_FMT_BGRA &&
295
((avctx->pix_fmt != AV_PIX_FMT_YUV420P &&
296
avctx->pix_fmt != AV_PIX_FMT_YUV422P &&
297
avctx->pix_fmt != AV_PIX_FMT_YUV444P) ||
302
298
avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) {
303
299
av_log(avctx, AV_LOG_ERROR, "colorspace not supported in LJPEG\n");
308
if (avctx->pix_fmt != PIX_FMT_YUVJ420P &&
309
avctx->pix_fmt != PIX_FMT_YUVJ422P &&
310
((avctx->pix_fmt != PIX_FMT_YUV420P &&
311
avctx->pix_fmt != PIX_FMT_YUV422P) ||
303
case AV_CODEC_ID_MJPEG:
304
if (avctx->pix_fmt != AV_PIX_FMT_YUVJ420P &&
305
avctx->pix_fmt != AV_PIX_FMT_YUVJ422P &&
306
((avctx->pix_fmt != AV_PIX_FMT_YUV420P &&
307
avctx->pix_fmt != AV_PIX_FMT_YUV422P) ||
312
308
avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) {
313
309
av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
318
if (avctx->pix_fmt != PIX_FMT_YUV420P) {
314
if (avctx->pix_fmt != AV_PIX_FMT_YUV420P) {
319
315
av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
324
320
switch (avctx->pix_fmt) {
325
case PIX_FMT_YUVJ422P:
326
case PIX_FMT_YUV422P:
321
case AV_PIX_FMT_YUVJ422P:
322
case AV_PIX_FMT_YUV422P:
327
323
s->chroma_format = CHROMA_422;
329
case PIX_FMT_YUVJ420P:
330
case PIX_FMT_YUV420P:
325
case AV_PIX_FMT_YUVJ420P:
326
case AV_PIX_FMT_YUV420P:
332
328
s->chroma_format = CHROMA_420;
348
344
s->flags2 = avctx->flags2;
349
345
s->max_b_frames = avctx->max_b_frames;
350
346
s->codec_id = avctx->codec->id;
351
s->luma_elim_threshold = avctx->luma_elim_threshold;
352
s->chroma_elim_threshold = avctx->chroma_elim_threshold;
347
#if FF_API_MPV_GLOBAL_OPTS
348
if (avctx->luma_elim_threshold)
349
s->luma_elim_threshold = avctx->luma_elim_threshold;
350
if (avctx->chroma_elim_threshold)
351
s->chroma_elim_threshold = avctx->chroma_elim_threshold;
353
353
s->strict_std_compliance = avctx->strict_std_compliance;
354
#if FF_API_MPEGVIDEO_GLOBAL_OPTS
355
if (avctx->flags & CODEC_FLAG_PART)
356
s->data_partitioning = 1;
358
354
s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0;
359
355
s->mpeg_quant = avctx->mpeg_quant;
360
356
s->rtp_mode = !!avctx->rtp_payload_size;
373
369
/* Fixed QSCALE */
374
370
s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
372
#if FF_API_MPV_GLOBAL_OPTS
373
if (s->flags & CODEC_FLAG_QP_RD)
374
s->mpv_flags |= FF_MPV_FLAG_QP_RD;
376
377
s->adaptive_quant = (s->avctx->lumi_masking ||
377
378
s->avctx->dark_masking ||
378
379
s->avctx->temporal_cplx_masking ||
379
380
s->avctx->spatial_cplx_masking ||
380
381
s->avctx->p_masking ||
381
382
s->avctx->border_masking ||
382
(s->flags & CODEC_FLAG_QP_RD)) &&
383
(s->mpv_flags & FF_MPV_FLAG_QP_RD)) &&
383
384
!s->fixed_qscale;
385
386
s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER);
386
#if FF_API_MPEGVIDEO_GLOBAL_OPTS
387
s->alternate_scan = !!(s->flags & CODEC_FLAG_ALT_SCAN);
388
s->intra_vlc_format = !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
389
s->q_scale_type = !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT);
390
s->obmc = !!(s->flags & CODEC_FLAG_OBMC);
393
388
if (avctx->rc_max_rate && !avctx->rc_buffer_size) {
394
389
av_log(avctx, AV_LOG_ERROR,
461
#if FF_API_MPEGVIDEO_GLOBAL_OPTS
462
if (s->obmc && s->codec_id != CODEC_ID_H263 &&
463
s->codec_id != CODEC_ID_H263P) {
464
av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n");
469
if (s->quarter_sample && s->codec_id != CODEC_ID_MPEG4) {
456
if (s->quarter_sample && s->codec_id != AV_CODEC_ID_MPEG4) {
470
457
av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
474
#if FF_API_MPEGVIDEO_GLOBAL_OPTS
475
if (s->data_partitioning && s->codec_id != CODEC_ID_MPEG4) {
476
av_log(avctx, AV_LOG_ERROR,
477
"data partitioning not supported by codec\n");
482
461
if (s->max_b_frames &&
483
s->codec_id != CODEC_ID_MPEG4 &&
484
s->codec_id != CODEC_ID_MPEG1VIDEO &&
485
s->codec_id != CODEC_ID_MPEG2VIDEO) {
462
s->codec_id != AV_CODEC_ID_MPEG4 &&
463
s->codec_id != AV_CODEC_ID_MPEG1VIDEO &&
464
s->codec_id != AV_CODEC_ID_MPEG2VIDEO) {
486
465
av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
490
if ((s->codec_id == CODEC_ID_MPEG4 ||
491
s->codec_id == CODEC_ID_H263 ||
492
s->codec_id == CODEC_ID_H263P) &&
469
if ((s->codec_id == AV_CODEC_ID_MPEG4 ||
470
s->codec_id == AV_CODEC_ID_H263 ||
471
s->codec_id == AV_CODEC_ID_H263P) &&
493
472
(avctx->sample_aspect_ratio.num > 255 ||
494
473
avctx->sample_aspect_ratio.den > 255)) {
495
474
av_log(avctx, AV_LOG_ERROR,
501
if ((s->flags & (CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME
502
#if FF_API_MPEGVIDEO_GLOBAL_OPTS
503
| CODEC_FLAG_ALT_SCAN
506
s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO) {
480
if ((s->flags & (CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME)) &&
481
s->codec_id != AV_CODEC_ID_MPEG4 && s->codec_id != AV_CODEC_ID_MPEG2VIDEO) {
507
482
av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n");
511
486
// FIXME mpeg2 uses that too
512
if (s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4) {
487
if (s->mpeg_quant && s->codec_id != AV_CODEC_ID_MPEG4) {
513
488
av_log(avctx, AV_LOG_ERROR,
514
489
"mpeg2 style quantization not supported by codec\n");
518
if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) {
493
#if FF_API_MPV_GLOBAL_OPTS
494
if (s->flags & CODEC_FLAG_CBP_RD)
495
s->mpv_flags |= FF_MPV_FLAG_CBP_RD;
498
if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) {
519
499
av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
523
if ((s->flags & CODEC_FLAG_QP_RD) &&
503
if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) &&
524
504
s->avctx->mb_decision != FF_MB_DECISION_RD) {
525
505
av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
574
538
if (s->avctx->thread_count > 1 &&
575
s->codec_id != CODEC_ID_MPEG4 &&
576
s->codec_id != CODEC_ID_MPEG1VIDEO &&
577
s->codec_id != CODEC_ID_MPEG2VIDEO &&
578
(s->codec_id != CODEC_ID_H263P
579
#if FF_API_MPEGVIDEO_GLOBAL_OPTS
580
|| !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT)
539
s->codec_id != AV_CODEC_ID_MPEG4 &&
540
s->codec_id != AV_CODEC_ID_MPEG1VIDEO &&
541
s->codec_id != AV_CODEC_ID_MPEG2VIDEO &&
542
(s->codec_id != AV_CODEC_ID_H263P)) {
583
543
av_log(avctx, AV_LOG_ERROR,
584
544
"multi threaded encoding not supported by codec\n");
657
617
s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
619
#if FF_API_MPV_GLOBAL_OPTS
620
if (avctx->flags2 & CODEC_FLAG2_SKIP_RD)
621
s->mpv_flags |= FF_MPV_FLAG_SKIP_RD;
622
if (avctx->flags2 & CODEC_FLAG2_STRICT_GOP)
623
s->mpv_flags |= FF_MPV_FLAG_STRICT_GOP;
624
if (avctx->quantizer_noise_shaping)
625
s->quantizer_noise_shaping = avctx->quantizer_noise_shaping;
659
628
switch (avctx->codec->id) {
660
case CODEC_ID_MPEG1VIDEO:
629
case AV_CODEC_ID_MPEG1VIDEO:
661
630
s->out_format = FMT_MPEG1;
662
631
s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY);
663
632
avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
665
case CODEC_ID_MPEG2VIDEO:
634
case AV_CODEC_ID_MPEG2VIDEO:
666
635
s->out_format = FMT_MPEG1;
667
636
s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY);
668
637
avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
640
case AV_CODEC_ID_LJPEG:
641
case AV_CODEC_ID_MJPEG:
673
642
s->out_format = FMT_MJPEG;
674
643
s->intra_only = 1; /* force intra only for jpeg */
675
if (avctx->codec->id == CODEC_ID_LJPEG &&
676
avctx->pix_fmt == PIX_FMT_BGRA) {
644
if (avctx->codec->id == AV_CODEC_ID_LJPEG &&
645
avctx->pix_fmt == AV_PIX_FMT_BGRA) {
677
646
s->mjpeg_vsample[0] = s->mjpeg_hsample[0] =
678
647
s->mjpeg_vsample[1] = s->mjpeg_hsample[1] =
679
648
s->mjpeg_vsample[2] = s->mjpeg_hsample[2] = 1;
1200
1183
input[i + 1].pict_type = is_p ?
1201
1184
AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B;
1202
1185
input[i + 1].quality = is_p ? p_lambda : b_lambda;
1203
out_size = avcodec_encode_video(c, outbuf, outbuf_size,
1187
out_size = encode_frame(c, &input[i + 1]);
1205
1189
rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
1208
1192
/* get the delayed frames */
1209
1193
while (out_size) {
1210
out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
1194
out_size = encode_frame(c, NULL);
1211
1195
rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
1399
1375
/* mark us unused / free shared pic */
1400
1376
if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL)
1401
1377
s->avctx->release_buffer(s->avctx,
1402
(AVFrame *) s->reordered_input_picture[0]);
1378
&s->reordered_input_picture[0]->f);
1403
1379
for (i = 0; i < 4; i++)
1404
1380
s->reordered_input_picture[0]->f.data[i] = NULL;
1405
1381
s->reordered_input_picture[0]->f.type = 0;
1407
copy_picture_attributes(s, (AVFrame *) pic,
1408
(AVFrame *) s->reordered_input_picture[0]);
1383
copy_picture_attributes(s, &pic->f,
1384
&s->reordered_input_picture[0]->f);
1410
1386
s->current_picture_ptr = pic;
1424
1400
ff_copy_picture(&s->current_picture, s->current_picture_ptr);
1426
1402
s->picture_number = s->new_picture.f.display_picture_number;
1427
//printf("dpn:%d\n", s->picture_number);
1429
1404
memset(&s->new_picture, 0, sizeof(Picture));
1434
int MPV_encode_picture(AVCodecContext *avctx,
1435
unsigned char *buf, int buf_size, void *data)
1409
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
1410
const AVFrame *pic_arg, int *got_packet)
1437
1412
MpegEncContext *s = avctx->priv_data;
1438
AVFrame *pic_arg = data;
1439
int i, stuffing_count;
1413
int i, stuffing_count, ret;
1440
1414
int context_count = s->slice_context_count;
1442
for (i = 0; i < context_count; i++) {
1443
int start_y = s->thread_context[i]->start_mb_y;
1444
int end_y = s->thread_context[i]-> end_mb_y;
1445
int h = s->mb_height;
1446
uint8_t *start = buf + (size_t)(((int64_t) buf_size) * start_y / h);
1447
uint8_t *end = buf + (size_t)(((int64_t) buf_size) * end_y / h);
1449
init_put_bits(&s->thread_context[i]->pb, start, end - start);
1452
1416
s->picture_in_gop_number++;
1454
1418
if (load_input_picture(s, pic_arg) < 0)
1462
1426
if (s->new_picture.f.data[0]) {
1428
(ret = ff_alloc_packet(pkt, s->mb_width*s->mb_height*MAX_MB_BYTES)) < 0)
1431
s->mb_info_ptr = av_packet_new_side_data(pkt,
1432
AV_PKT_DATA_H263_MB_INFO,
1433
s->mb_width*s->mb_height*12);
1434
s->prev_mb_info = s->last_mb_info = s->mb_info_size = 0;
1437
for (i = 0; i < context_count; i++) {
1438
int start_y = s->thread_context[i]->start_mb_y;
1439
int end_y = s->thread_context[i]-> end_mb_y;
1440
int h = s->mb_height;
1441
uint8_t *start = pkt->data + (size_t)(((int64_t) pkt->size) * start_y / h);
1442
uint8_t *end = pkt->data + (size_t)(((int64_t) pkt->size) * end_y / h);
1444
init_put_bits(&s->thread_context[i]->pb, start, end - start);
1463
1447
s->pict_type = s->new_picture.f.pict_type;
1465
//printf("qs:%f %f %d\n", s->new_picture.quality,
1466
// s->current_picture.quality, s->qscale);
1467
MPV_frame_start(s, avctx);
1449
ff_MPV_frame_start(s, avctx);
1469
1451
if (encode_picture(s, s->picture_number) < 0)
1504
1486
// done in encode_picture() so we must undo it
1505
1487
if (s->pict_type == AV_PICTURE_TYPE_P) {
1506
1488
if (s->flipflop_rounding ||
1507
s->codec_id == CODEC_ID_H263P ||
1508
s->codec_id == CODEC_ID_MPEG4)
1489
s->codec_id == AV_CODEC_ID_H263P ||
1490
s->codec_id == AV_CODEC_ID_MPEG4)
1509
1491
s->no_rounding ^= 1;
1511
1493
if (s->pict_type != AV_PICTURE_TYPE_B) {
1512
1494
s->time_base = s->last_time_base;
1513
1495
s->last_non_b_time = s->time - s->pp_time;
1515
//av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda);
1516
1497
for (i = 0; i < context_count; i++) {
1517
1498
PutBitContext *pb = &s->thread_context[i]->pb;
1518
1499
init_put_bits(pb, pb->buf, pb->buf_end - pb->buf);
1605
1586
s->total_bits += s->frame_bits;
1606
1587
avctx->frame_bits = s->frame_bits;
1589
pkt->pts = s->current_picture.f.pts;
1590
if (!s->low_delay) {
1591
if (!s->current_picture.f.coded_picture_number)
1592
pkt->dts = pkt->pts - s->dts_delta;
1594
pkt->dts = s->reordered_pts;
1595
s->reordered_pts = s->input_picture[0]->f.pts;
1597
pkt->dts = pkt->pts;
1598
if (s->current_picture.f.key_frame)
1599
pkt->flags |= AV_PKT_FLAG_KEY;
1601
av_packet_shrink_side_data(pkt, AV_PKT_DATA_H263_MB_INFO, s->mb_info_size);
1608
assert((put_bits_ptr(&s->pb) == s->pb.buf));
1609
1603
s->frame_bits = 0;
1611
1605
assert((s->frame_bits & 7) == 0);
1613
return s->frame_bits / 8;
1607
pkt->size = s->frame_bits / 8;
1608
*got_packet = !!pkt->size;
1616
1612
static inline void dct_single_coeff_elimination(MpegEncContext *s,
1787
1783
if (mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) {
1788
1784
uint8_t *ebuf = s->edge_emu_buffer + 32;
1789
s->dsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16,
1790
mb_y * 16, s->width, s->height);
1785
s->vdsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16,
1786
mb_y * 16, s->width, s->height);
1792
s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8,
1793
mb_block_height, mb_x * 8, mb_y * 8,
1794
s->width >> 1, s->height >> 1);
1788
s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8,
1789
mb_block_height, mb_x * 8, mb_y * 8,
1790
s->width >> 1, s->height >> 1);
1795
1791
ptr_cb = ebuf + 18 * wrap_y;
1796
s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8,
1797
mb_block_height, mb_x * 8, mb_y * 8,
1798
s->width >> 1, s->height >> 1);
1792
s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8,
1793
mb_block_height, mb_x * 8, mb_y * 8,
1794
s->width >> 1, s->height >> 1);
1799
1795
ptr_cr = ebuf + 18 * wrap_y + 8;
1863
1859
if (s->mv_dir & MV_DIR_FORWARD) {
1864
MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data,
1860
ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0,
1861
s->last_picture.f.data,
1866
1863
op_pix = s->dsp.avg_pixels_tab;
1867
1864
op_qpix = s->dsp.avg_qpel_pixels_tab;
1869
1866
if (s->mv_dir & MV_DIR_BACKWARD) {
1870
MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data,
1867
ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1,
1868
s->next_picture.f.data,
1874
1872
if (s->flags & CODEC_FLAG_INTERLACED_DCT) {
2050
2048
/* huffman encode */
2051
2049
switch(s->codec_id){ //FIXME funct ptr could be slightly faster
2052
case CODEC_ID_MPEG1VIDEO:
2053
case CODEC_ID_MPEG2VIDEO:
2050
case AV_CODEC_ID_MPEG1VIDEO:
2051
case AV_CODEC_ID_MPEG2VIDEO:
2054
2052
if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
2055
mpeg1_encode_mb(s, s->block, motion_x, motion_y);
2053
ff_mpeg1_encode_mb(s, s->block, motion_x, motion_y);
2057
case CODEC_ID_MPEG4:
2055
case AV_CODEC_ID_MPEG4:
2058
2056
if (CONFIG_MPEG4_ENCODER)
2059
mpeg4_encode_mb(s, s->block, motion_x, motion_y);
2057
ff_mpeg4_encode_mb(s, s->block, motion_x, motion_y);
2061
case CODEC_ID_MSMPEG4V2:
2062
case CODEC_ID_MSMPEG4V3:
2059
case AV_CODEC_ID_MSMPEG4V2:
2060
case AV_CODEC_ID_MSMPEG4V3:
2061
case AV_CODEC_ID_WMV1:
2064
2062
if (CONFIG_MSMPEG4_ENCODER)
2065
msmpeg4_encode_mb(s, s->block, motion_x, motion_y);
2063
ff_msmpeg4_encode_mb(s, s->block, motion_x, motion_y);
2065
case AV_CODEC_ID_WMV2:
2068
2066
if (CONFIG_WMV2_ENCODER)
2069
2067
ff_wmv2_encode_mb(s, s->block, motion_x, motion_y);
2069
case AV_CODEC_ID_H261:
2072
2070
if (CONFIG_H261_ENCODER)
2073
2071
ff_h261_encode_mb(s, s->block, motion_x, motion_y);
2076
case CODEC_ID_H263P:
2073
case AV_CODEC_ID_H263:
2074
case AV_CODEC_ID_H263P:
2075
case AV_CODEC_ID_FLV1:
2076
case AV_CODEC_ID_RV10:
2077
case AV_CODEC_ID_RV20:
2080
2078
if (CONFIG_H263_ENCODER)
2081
2079
ff_h263_encode_mb(s, s->block, motion_x, motion_y);
2083
case CODEC_ID_MJPEG:
2081
case AV_CODEC_ID_MJPEG:
2084
2082
if (CONFIG_MJPEG_ENCODER)
2085
2083
ff_mjpeg_encode_mb(s, s->block);
2345
2343
s->misc_bits+= get_bits_diff(s);
2346
static void write_mb_info(MpegEncContext *s)
2348
uint8_t *ptr = s->mb_info_ptr + s->mb_info_size - 12;
2349
int offset = put_bits_count(&s->pb);
2350
int mba = s->mb_x + s->mb_width * (s->mb_y % s->gob_index);
2351
int gobn = s->mb_y / s->gob_index;
2353
if (CONFIG_H263_ENCODER)
2354
ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
2355
bytestream_put_le32(&ptr, offset);
2356
bytestream_put_byte(&ptr, s->qscale);
2357
bytestream_put_byte(&ptr, gobn);
2358
bytestream_put_le16(&ptr, mba);
2359
bytestream_put_byte(&ptr, pred_x); /* hmv1 */
2360
bytestream_put_byte(&ptr, pred_y); /* vmv1 */
2361
/* 4MV not implemented */
2362
bytestream_put_byte(&ptr, 0); /* hmv2 */
2363
bytestream_put_byte(&ptr, 0); /* vmv2 */
2366
static void update_mb_info(MpegEncContext *s, int startcode)
2370
if (put_bits_count(&s->pb) - s->prev_mb_info*8 >= s->mb_info*8) {
2371
s->mb_info_size += 12;
2372
s->prev_mb_info = s->last_mb_info;
2375
s->prev_mb_info = put_bits_count(&s->pb)/8;
2376
/* This might have incremented mb_info_size above, and we return without
2377
* actually writing any info into that slot yet. But in that case,
2378
* this will be called again at the start of the after writing the
2379
* start code, actually writing the mb info. */
2383
s->last_mb_info = put_bits_count(&s->pb)/8;
2384
if (!s->mb_info_size)
2385
s->mb_info_size += 12;
2348
2389
static int encode_thread(AVCodecContext *c, void *arg){
2349
2390
MpegEncContext *s= *(void**)arg;
2350
2391
int mb_x, mb_y, pdif = 0;
2490
2529
int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x;
2491
2530
s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb);
2532
update_mb_info(s, 1);
2494
2534
switch(s->codec_id){
2495
case CODEC_ID_MPEG4:
2535
case AV_CODEC_ID_MPEG4:
2496
2536
if (CONFIG_MPEG4_ENCODER) {
2497
2537
ff_mpeg4_encode_video_packet_header(s);
2498
2538
ff_mpeg4_clean_buffers(s);
2501
case CODEC_ID_MPEG1VIDEO:
2502
case CODEC_ID_MPEG2VIDEO:
2541
case AV_CODEC_ID_MPEG1VIDEO:
2542
case AV_CODEC_ID_MPEG2VIDEO:
2503
2543
if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) {
2504
2544
ff_mpeg1_encode_slice_header(s);
2505
2545
ff_mpeg1_clean_buffers(s);
2509
case CODEC_ID_H263P:
2548
case AV_CODEC_ID_H263:
2549
case AV_CODEC_ID_H263P:
2510
2550
if (CONFIG_H263_ENCODER)
2511
2551
ff_h263_encode_gob_header(s, mb_y);
3245
3289
ff_h261_encode_picture_header(s, picture_number);
3248
if (CONFIG_WMV2_ENCODER && s->codec_id == CODEC_ID_WMV2)
3292
if (CONFIG_WMV2_ENCODER && s->codec_id == AV_CODEC_ID_WMV2)
3249
3293
ff_wmv2_encode_picture_header(s, picture_number);
3250
3294
else if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version)
3251
msmpeg4_encode_picture_header(s, picture_number);
3295
ff_msmpeg4_encode_picture_header(s, picture_number);
3252
3296
else if (CONFIG_MPEG4_ENCODER && s->h263_pred)
3253
mpeg4_encode_picture_header(s, picture_number);
3254
else if (CONFIG_RV10_ENCODER && s->codec_id == CODEC_ID_RV10)
3255
rv10_encode_picture_header(s, picture_number);
3256
else if (CONFIG_RV20_ENCODER && s->codec_id == CODEC_ID_RV20)
3257
rv20_encode_picture_header(s, picture_number);
3258
else if (CONFIG_FLV_ENCODER && s->codec_id == CODEC_ID_FLV1)
3297
ff_mpeg4_encode_picture_header(s, picture_number);
3298
else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10)
3299
ff_rv10_encode_picture_header(s, picture_number);
3300
else if (CONFIG_RV20_ENCODER && s->codec_id == AV_CODEC_ID_RV20)
3301
ff_rv20_encode_picture_header(s, picture_number);
3302
else if (CONFIG_FLV_ENCODER && s->codec_id == AV_CODEC_ID_FLV1)
3259
3303
ff_flv_encode_picture_header(s, picture_number);
3260
3304
else if (CONFIG_H263_ENCODER)
3261
3305
ff_h263_encode_picture_header(s, picture_number);
3263
3307
case FMT_MPEG1:
3264
3308
if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
3265
mpeg1_encode_picture_header(s, picture_number);
3309
ff_mpeg1_encode_picture_header(s, picture_number);
4081
4121
#define OFFSET(x) offsetof(MpegEncContext, x)
4082
4122
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
4083
4123
static const AVOption h263_options[] = {
4084
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4085
{ "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
4124
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
4125
{ "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE},
4126
{ "mb_info", "emit macroblock info for RFC 2190 packetization, the parameter value is the maximum payload size", OFFSET(mb_info), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
4096
4138
AVCodec ff_h263_encoder = {
4097
4139
.name = "h263",
4098
4140
.type = AVMEDIA_TYPE_VIDEO,
4099
.id = CODEC_ID_H263,
4141
.id = AV_CODEC_ID_H263,
4100
4142
.priv_data_size = sizeof(MpegEncContext),
4101
.init = MPV_encode_init,
4102
.encode = MPV_encode_picture,
4103
.close = MPV_encode_end,
4104
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4143
.init = ff_MPV_encode_init,
4144
.encode2 = ff_MPV_encode_picture,
4145
.close = ff_MPV_encode_end,
4146
.pix_fmts= (const enum AVPixelFormat[]){AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE},
4105
4147
.long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"),
4106
4148
.priv_class = &h263_class,
4109
4151
static const AVOption h263p_options[] = {
4110
{ "umv", "Use unlimited motion vectors.", OFFSET(umvplus), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4111
{ "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4112
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4113
{ "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
4152
{ "umv", "Use unlimited motion vectors.", OFFSET(umvplus), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
4153
{ "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
4154
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
4155
{ "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE},
4116
4159
static const AVClass h263p_class = {
4123
4166
AVCodec ff_h263p_encoder = {
4124
4167
.name = "h263p",
4125
4168
.type = AVMEDIA_TYPE_VIDEO,
4126
.id = CODEC_ID_H263P,
4169
.id = AV_CODEC_ID_H263P,
4127
4170
.priv_data_size = sizeof(MpegEncContext),
4128
.init = MPV_encode_init,
4129
.encode = MPV_encode_picture,
4130
.close = MPV_encode_end,
4131
.capabilities = CODEC_CAP_SLICE_THREADS,
4132
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4133
.long_name= NULL_IF_CONFIG_SMALL("H.263+ / H.263-1998 / H.263 version 2"),
4171
.init = ff_MPV_encode_init,
4172
.encode2 = ff_MPV_encode_picture,
4173
.close = ff_MPV_encode_end,
4174
.capabilities = CODEC_CAP_SLICE_THREADS,
4175
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
4176
.long_name = NULL_IF_CONFIG_SMALL("H.263+ / H.263-1998 / H.263 version 2"),
4134
4177
.priv_class = &h263p_class,
4180
FF_MPV_GENERIC_CLASS(msmpeg4v2)
4137
4182
AVCodec ff_msmpeg4v2_encoder = {
4138
4183
.name = "msmpeg4v2",
4139
4184
.type = AVMEDIA_TYPE_VIDEO,
4140
.id = CODEC_ID_MSMPEG4V2,
4185
.id = AV_CODEC_ID_MSMPEG4V2,
4141
4186
.priv_data_size = sizeof(MpegEncContext),
4142
.init = MPV_encode_init,
4143
.encode = MPV_encode_picture,
4144
.close = MPV_encode_end,
4145
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4146
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
4187
.init = ff_MPV_encode_init,
4188
.encode2 = ff_MPV_encode_picture,
4189
.close = ff_MPV_encode_end,
4190
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
4191
.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
4192
.priv_class = &msmpeg4v2_class,
4195
FF_MPV_GENERIC_CLASS(msmpeg4v3)
4149
4197
AVCodec ff_msmpeg4v3_encoder = {
4150
4198
.name = "msmpeg4",
4151
4199
.type = AVMEDIA_TYPE_VIDEO,
4152
.id = CODEC_ID_MSMPEG4V3,
4200
.id = AV_CODEC_ID_MSMPEG4V3,
4153
4201
.priv_data_size = sizeof(MpegEncContext),
4154
.init = MPV_encode_init,
4155
.encode = MPV_encode_picture,
4156
.close = MPV_encode_end,
4157
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4158
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
4202
.init = ff_MPV_encode_init,
4203
.encode2 = ff_MPV_encode_picture,
4204
.close = ff_MPV_encode_end,
4205
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
4206
.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
4207
.priv_class = &msmpeg4v3_class,
4210
FF_MPV_GENERIC_CLASS(wmv1)
4161
4212
AVCodec ff_wmv1_encoder = {
4162
4213
.name = "wmv1",
4163
4214
.type = AVMEDIA_TYPE_VIDEO,
4164
.id = CODEC_ID_WMV1,
4215
.id = AV_CODEC_ID_WMV1,
4165
4216
.priv_data_size = sizeof(MpegEncContext),
4166
.init = MPV_encode_init,
4167
.encode = MPV_encode_picture,
4168
.close = MPV_encode_end,
4169
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4170
.long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
4217
.init = ff_MPV_encode_init,
4218
.encode2 = ff_MPV_encode_picture,
4219
.close = ff_MPV_encode_end,
4220
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
4221
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
4222
.priv_class = &wmv1_class,