1 /*
2 * MPEG-1/2 encoder
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * MPEG-1/2 encoder
26 */
27
28 #include <stdint.h>
29
36
44
46 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
47 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
48 };
49
52
55
56 /* simple include everything table for dc, first byte is bits
57 * number next 3 are code */
60
63
65 {
66 int i;
67
68 for (i = 0; i < 128; i++) {
71 if (!level)
72 continue;
73 for (run = 0; run < 64; run++) {
75 int alevel =
FFABS(level);
76
78 code = 111; /* rl->n */
79 else
81
82 if (code < 111) { /* rl->n */
83 /* length of VLC and sign */
85 } else {
86 len = rl->
table_vlc[111
/* rl->n */][1] + 6;
87
88 if (alevel < 128)
89 len += 8;
90 else
91 len += 16;
92 }
93
95 }
96 }
97 }
98
100 {
101 int i;
105
106 for (i = 1; i < 14; i++) {
108 i >= 9)
109 break;
110
111 for (ext.
num=1; ext.
num <= 4; ext.
num++) {
112 for (ext.
den=1; ext.
den <= 32; ext.
den++) {
114
116 continue;
118 continue;
119
123 bestq = q;
127 }
128 }
129 }
130 }
131
133 return -1;
134 else
135 return 0;
136 }
137
139 {
141
143 return -1;
144
149 return -1;
150 } else {
152 "MPEG-1/2 does not support %d/%d fps, there may be AV sync issues\n",
154 }
155 }
156
160 return -1;
161 }
162 /* Main or 4:2:2 */
164 }
165
167 if (avctx->
profile == 0) {
/* 4:2:2 */
169 avctx->
level = 5;
/* Main */
170 else
171 avctx->
level = 2;
/* High */
172 } else {
175 "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
176 return -1;
177 }
179 avctx->
level = 8;
/* Main */
180 else if (avctx->
width <= 1440)
181 avctx->
level = 6;
/* High 1440 */
182 else
183 avctx->
level = 4;
/* High */
184 }
185 }
186
187 if ((avctx->
width & 0xFFF) == 0 && (avctx->
height & 0xFFF) == 1) {
190 }
191
193 if ((avctx->
width & 0xFFF) == 0 || (avctx->
height & 0xFFF) == 0) {
194 av_log(avctx,
AV_LOG_ERROR,
"Width or Height are not allowed to be multiples of 4096\n"
197 }
198 }
199
205 "Drop frame time code only allowed with 1001/30000 fps\n");
206 return -1;
207 }
208
209 #if FF_API_PRIVATE_OPT
214 #endif
215
219 if (ret < 0)
220 return ret;
223 } else {
225 }
226
227 return 0;
228 }
229
231 {
235 }
236
237 /* put sequence header if needed */
239 {
240 unsigned int vbv_buffer_size, fps, v;
241 int i, constraint_parameter_flag;
242 uint64_t time_code;
243 int64_t best_aspect_error = INT64_MAX;
245
246 if (aspect_ratio.
num == 0 || aspect_ratio.
den == 0)
247 aspect_ratio = (
AVRational){1,1};
// pixel aspect 1.1 (VGA)
248
251
252 /* MPEG-1 header repeated every GOP */
254
257
258 for (i = 1; i < 15; i++) {
259 int64_t
error = aspect_ratio.
num * (1LL<<32) / aspect_ratio.
den;
262 else
264
265 error =
FFABS(error);
266
267 if (error - 2 <= best_aspect_error) {
268 best_aspect_error =
error;
270 }
271 }
272
275
279 v = 0x3ffff;
280 } else {
281 v = 0x3FFFF;
282 }
283
286 else
287 /* VBV calculation: Scaled so that a VCD has the proper
288 * VBV size of 40 kilobytes */
289 vbv_buffer_size = ((20 * s->
bit_rate) / (1151929 / 2)) * 8 * 1024;
290 vbv_buffer_size = (vbv_buffer_size + 16383) / 16384;
291
295
296 constraint_parameter_flag =
301 framerate.
num <= framerate.
den * 30 &&
304 vbv_buffer_size <= 20 &&
305 v <= 1856000 / 400 &&
307
308 put_bits(&s->
pb, 1, constraint_parameter_flag);
309
312
317 int use_seq_disp_ext;
318
321
323
326
333 put_bits(&s->
pb, 8, vbv_buffer_size >> 10);
// vbv buffer ext
337
339 if (side_data) {
342 width = pan_scan->
width >> 4;
343 height = pan_scan->
height >> 4;
344 }
345 }
346
347 use_seq_disp_ext = (width != s->
width ||
353
356 put_bits(&s->
pb, 4, 2);
// sequence display extension
362 put_bits(&s->
pb, 14, width);
// display_horizontal_size
364 put_bits(&s->
pb, 14, height);
// display_vertical_size
365 put_bits(&s->
pb, 3, 0);
// remaining 3 bits are zero padding
366 }
367 }
368
371 /* time code: we must convert from the real frame rate to a
372 * fake MPEG frame rate in case of low frame rate */
373 fps = (framerate.
num + framerate.
den / 2) / framerate.
den;
376
378
382
383 put_bits(&s->
pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
384 put_bits(&s->
pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
386 put_bits(&s->
pb, 6, (uint32_t)((time_code / fps) % 60));
387 put_bits(&s->
pb, 6, (uint32_t)((time_code % fps)));
390 }
391 }
392
394 {
395 while (run >= 33) {
397 run -= 33;
398 }
401 }
402
404 {
406 }
407
409 {
412 /* slice_vertical_position_extension */
414 } else {
416 }
418 /* slice extra information */
420 }
421
423 {
426
427 /* MPEG-1 picture header */
429 /* temporal reference */
430
431 // RAL: s->picture_number instead of s->fake_picture_number
435
438
439 // RAL: Forward f_code also needed for B-frames
442 put_bits(&s->
pb, 1, 0);
/* half pel coordinates */
445 else
447 }
448
449 // RAL: Backward f_code necessary for B-frames
451 put_bits(&s->
pb, 1, 0);
/* half pel coordinates */
454 else
456 }
457
458 put_bits(&s->
pb, 1, 0);
/* extra bit picture */
459
468 } else {
470 }
474 } else {
476 }
478
483 else
485 /* XXX: optimize the generation of this flag with entropy measures */
487
495 /* chroma_420_type */
499 put_bits(&s->
pb, 1, 0);
/* composite_display_flag */
500 }
502 int i;
503
507 }
510 if (side_data) {
513
514 switch (stereo->
type) {
516 fpa_type = 0x03;
517 break;
519 fpa_type = 0x04;
520 break;
522 fpa_type = 0x08;
523 break;
525 fpa_type = 0x23;
526 break;
527 default:
528 fpa_type = 0;
529 break;
530 }
531
532 if (fpa_type != 0) {
534 put_bits(&s->
pb, 8,
'J');
// S3D_video_format_signaling_identifier
538 put_bits(&s->
pb, 8, 0x03);
// S3D_video_format_length
539
541 put_bits(&s->
pb, 7, fpa_type);
// S3D_video_format_type
542 put_bits(&s->
pb, 8, 0x04);
// reserved_data[0]
543 put_bits(&s->
pb, 8, 0xFF);
// reserved_data[1]
544 }
545 }
546
549 }
550
552 int has_mv, int field_motion)
553 {
556 if (has_mv)
557 /* motion_type: frame/field */
560 }
561 }
562
563 // RAL: Parameter added: f_or_b_code
565 {
566 if (val == 0) {
567 /* zero vector */
571 } else {
572 int code, sign, bits;
573 int bit_size = f_or_b_code - 1;
574 int range = 1 << bit_size;
575 /* modulo encoding */
577
578 if (val >= 0) {
579 val--;
580 code = (val >> bit_size) + 1;
581 bits = val & (range - 1);
582 sign = 0;
583 } else {
585 val--;
586 code = (val >> bit_size) + 1;
587 bits = val & (range - 1);
588 sign = 1;
589 }
590
592
596
598 if (bit_size > 0)
600 }
601 }
602
604 {
605 unsigned int diff_u = diff + 255;
606 if (diff_u >= 511) {
608
609 if (diff < 0) {
611 diff--;
612 } else {
614 }
615 if (component == 0)
619 av_mod_uintp2(diff, index));
620 else
624 av_mod_uintp2(diff, index));
625 } else {
626 if (component == 0)
630 else
634 }
635 }
636
638 {
639 int alevel,
level, last_non_zero,
dc,
diff, i, j,
run, last_index, sign;
640 int code, component;
642
644
645 /* DC coef */
647 component = (n <= 3 ? 0 : (n & 1) + 1);
648 dc = block[0]; /* overflow is impossible */
649 diff = dc - s->
last_dc[component];
652 i = 1;
655 } else {
656 /* encode the first coefficient: needs to be done here because
657 * it is handled slightly differently */
658 level = block[0];
659 if (abs(level) == 1) {
660 code = ((uint32_t)level >> 31); /* the sign bit */
662 i = 1;
663 } else {
664 i = 0;
665 last_non_zero = -1;
666 goto next_coef;
667 }
668 }
669
670 /* now quantify & encode AC coefs */
671 last_non_zero = i - 1;
672
673 for (; i <= last_index; i++) {
675 level = block[j];
676
677 next_coef:
678 /* encode using VLC */
679 if (level != 0) {
680 run = i - last_non_zero - 1;
681
684 sign &= 1;
685
688 /* store the VLC & sign at once */
690 (table_vlc[code][0] << 1) + sign);
691 } else {
692 /* escape seems to be pretty rare <5% so I do not optimize it */
693 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
694 /* escape: only clip in this case */
697 if (alevel < 128) {
699 } else {
700 if (level < 0)
702 else
704 }
705 } else {
707 }
708 }
709 last_non_zero = i;
710 }
711 }
712 /* end of block */
713 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
714 }
715
717 int16_t
block[8][64],
718 int motion_x, int motion_y,
719 int mb_block_count)
720 {
721 int i, cbp;
722 const int mb_x = s->
mb_x;
723 const int mb_y = s->
mb_y;
725
726 /* compute cbp */
727 cbp = 0;
728 for (i = 0; i < mb_block_count; i++)
730 cbp |= 1 << (mb_block_count - 1 - i);
731
738 ? ((s->
mv[0][0][0] - s->
last_mv[0][0][0]) |
739 (s->
mv[0][0][1] - s->
last_mv[0][0][1])) : 0) |
741 ? ((s->
mv[1][0][0] - s->
last_mv[1][0][0]) |
742 (s->
mv[1][0][1] - s->
last_mv[1][0][1])) : 0)) == 0))) {
753 }
754 } else {
755 if (first_mb) {
758 } else {
760 }
761
764 /* macroblock_type: macroblock_quant = 1 */
767 } else {
768 /* macroblock_type: macroblock_quant = 0 */
771 }
778 } else {
781 }
787 if (cbp != 0) {
788 if ((motion_x | motion_y) == 0) {
790 /* macroblock_pattern & quant */
793 } else {
794 /* macroblock_pattern only */
796 }
798 } else {
802 } else {
804 }
806 // RAL: f_code parameter added
808 motion_x - s->
last_mv[0][0][0],
810 // RAL: f_code parameter added
812 motion_y - s->
last_mv[0][0][1],
815 }
816 } else {
819 put_bits(&s->
pb, 2, 2);
/* motion_type: frame */
821 // RAL: f_code parameter added
823 motion_x - s->
last_mv[0][0][0],
825 // RAL: f_code parameter added
827 motion_y - s->
last_mv[0][0][1],
831 }
834 } else {
836
837 if (cbp) {
841 } else {
843 }
844 } else {
846 put_bits(&s->
pb, 2, 1);
/* motion_type: field */
848 }
850 for (i = 0; i < 2; i++) {
856 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
859 s->
last_mv[0][i][1] = 2 * s->
mv[0][i][1];
860 }
862 }
863 if (cbp) {
868 } else {
873 }
874 }
876 } else {
878 if (cbp) { // With coded bloc pattern
882 else
885 } else {
887 }
888 } else { // No coded bloc pattern
891 put_bits(&s->
pb, 2, 2);
/* motion_type: frame */
893 }
907 }
920 }
921 } else {
924 if (cbp) { // With coded bloc pattern
928 else
931 } else {
933 }
934 } else { // No coded bloc pattern
936 put_bits(&s->
pb, 2, 1);
/* motion_type: field */
938 }
941 for (i = 0; i < 2; i++) {
947 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
950 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
951 }
953 }
955 for (i = 0; i < 2; i++) {
961 s->
mv[1][i][1] - (s->
last_mv[1][i][1] >> 1),
964 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
965 }
967 }
968 }
970 if (cbp) {
975 } else {
980 }
981 }
982 }
983 for (i = 0; i < mb_block_count; i++)
984 if (cbp & (1 << (mb_block_count - 1 - i)))
989 else
991 }
992 }
993
995 int motion_x, int motion_y)
996 {
999 else
1001 }
1002
1004 {
1005 static int done = 0;
1006
1008
1009 if (!done) {
1010 int f_code;
1012 int i;
1013
1014 done = 1;
1017
1018 for (i = 0; i < 64; i++) {
1021 }
1022
1026
1027 /* build unified dc encoding tables */
1028 for (i = -255; i < 256; i++) {
1030 int bits, code;
1032
1033 adiff =
FFABS(diff);
1034 if (diff < 0)
1035 diff--;
1037
1040 av_mod_uintp2(diff, index);
1042
1045 av_mod_uintp2(diff, index);
1047 }
1048
1049 for (f_code = 1; f_code <=
MAX_FCODE; f_code++)
1052
1053 if (mv == 0) {
1055 } else {
1056 int val, bit_size, code;
1057
1058 bit_size = f_code - 1;
1059
1061 if (val < 0)
1063 val--;
1064 code = (val >> bit_size) + 1;
1065 if (code < 17)
1067 1 + bit_size;
1068 else
1070 2 + bit_size;
1071 }
1072
1074 }
1075
1076
1077 for (f_code =
MAX_FCODE; f_code > 0; f_code--)
1078 for (mv = -(8 << f_code); mv < (8 << f_code); mv++)
1080 }
1086 } else {
1089 }
1093 } else {
1096 }
1099 }
1100
1101 #define OFFSET(x) offsetof(MpegEncContext, x)
1102 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1103 #define COMMON_OPTS \
1104 { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.", \
1105 OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, VE },\
1106 { "intra_vlc", "Use MPEG-2 intra VLC table.", \
1107 OFFSET(intra_vlc_format), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
1108 { "drop_frame_timecode", "Timecode is in drop frame format.", \
1109 OFFSET(drop_frame_timecode), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
1110 { "scan_offset", "Reserve space for SVCD scan offset user data.", \
1111 OFFSET(scan_offset), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
1112 { "timecode_frame_start", "GOP timecode frame start number, in non-drop-frame format", \
1113 OFFSET(timecode_frame_start), AV_OPT_TYPE_INT64, {.i64 = -1 }, -1, INT64_MAX, VE}, \
1114
1119 };
1120
1123 {
"non_linear_quant",
"Use nonlinear quantizer.",
OFFSET(q_scale_type),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE },
1124 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE },
1125 {
"seq_disp_ext",
"Write sequence_display_extension blocks.",
OFFSET(seq_disp_ext),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE,
"seq_disp_ext" },
1138 };
1139
1140 #define mpeg12_class(x) \
1141 static const AVClass mpeg ## x ## _class = { \
1142 .class_name = "mpeg" # x "video encoder", \
1143 .item_name = av_default_item_name, \
1144 .option = mpeg ## x ## _options, \
1145 .version = LIBAVUTIL_VERSION_INT, \
1146 };
1147
1150
1152 .
name =
"mpeg1video",
1164 .priv_class = &mpeg1_class,
1165 };
1166
1168 .
name =
"mpeg2video",
1181 .priv_class = &mpeg2_class,
1182 };
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
static uint8_t uni_mpeg1_ac_vlc_len[64 *64 *2]
#define MASK_ABS(mask, level)
AVCodec ff_mpeg2video_encoder
const char const char void * val
int64_t timecode_frame_start
GOP timecode frame start number, in non drop frame format.
const AVRational ff_mpeg2_frame_rate_tab[]
uint8_t * fcode_tab
smallest fcode needed for each MV
#define MV_TYPE_FIELD
2 vectors, one per field
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
static int find_frame_rate_index(MpegEncContext *s)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define VIDEO_FORMAT_COMPONENT
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
static av_cold int init(AVCodecContext *avctx)
#define FF_MPV_COMMON_OPTS
const unsigned char ff_mpeg12_vlc_dc_lum_bits[12]
Views are next to each other, but when upscaling apply a checkerboard pattern.
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
int scan_offset
reserve space for SVCD scan offset user data.
int min_qcoeff
minimum encodable coefficient
const uint16_t ff_mpeg12_vlc_dc_lum_code[12]
Views are next to each other.
uint8_t * intra_ac_vlc_length
#define UNI_AC_ENC_INDEX(run, level)
#define SLICE_MIN_START_CODE
int av_log2_16bit(unsigned v)
uint8_t(* mv_penalty)[MAX_DMV *2+1]
bit amount needed to encode a MV
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...
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define VIDEO_FORMAT_NTSC
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
Parse timecode representation (hh:mm:ss[:;.
AVRational mpeg2_frame_rate_ext
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static uint32_t mpeg1_lum_dc_uni[512]
static void encode_mb_skip_run(MpegEncContext *s, int run)
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
const float ff_mpeg1_aspect[16]
int misc_bits
cbp, mb_type
static const AVOption mpeg1_options[]
static void mpeg1_encode_block(MpegEncContext *s, int16_t *block, int n)
Picture current_picture
copy of the current picture structure.
The data is the AVPanScan struct defined in libavcodec.
#define VIDEO_FORMAT_UNSPECIFIED
AVCodec ff_mpeg1video_encoder
Structure to hold side data for an AVFrame.
static int8_t mpeg1_max_level[2][64]
int start
timecode frame start (first base frame number)
int8_t * max_level[2]
encoding & decoding
#define VIDEO_FORMAT_SECAM
int mb_height
number of MBs horizontally & vertically
Video is not stereoscopic (and metadata has to be there).
static const uint8_t header[24]
int max_qcoeff
maximum encodable coefficient
int dquant
qscale difference to prev qscale
int gop_picture_number
index of the first picture of a GOP based on fake_pic_num & MPEG-1 specific
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
static int get_bits_diff(MpegEncContext *s)
int intra_only
if true, only intra pictures are generated
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int last_dc[3]
last DC values for MPEG-1
static void put_mb_modes(MpegEncContext *s, int n, int bits, int has_mv, int field_motion)
uint8_t * inter_ac_vlc_last_length
int strict_std_compliance
strictly follow the std (MPEG-4, ...)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const uint16_t ff_mpeg12_vlc_dc_chroma_code[12]
static void encode_dc(MpegEncContext *s, int diff, int component)
int flags
AV_CODEC_FLAG_*.
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
const char * name
Name of the codec implementation.
int width
width and height in 1/16 pel
int low_delay
no reordering needed / has no B-frames
attribute_deprecated int64_t timecode_frame_start
static void mpeg1_encode_sequence_header(MpegEncContext *s)
static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
static int put_bits_count(PutBitContext *s)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int resync_mb_x
x position of last resync marker
int rc_buffer_size
decoder bitstream buffer size
uint8_t * intra_ac_vlc_last_length
uint8_t * vbv_delay_ptr
pointer to vbv_delay in the bitstream
const uint16_t(* table_vlc)[2]
static uint8_t fcode_tab[MAX_MV *2+1]
int width
picture width / height.
const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12]
Picture * current_picture_ptr
pointer to the current picture
#define FF_PROFILE_UNKNOWN
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static uint8_t uni_mpeg2_ac_vlc_len[64 *64 *2]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int block_last_index[12]
last non zero coefficient in block
static av_cold void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len)
static void put_header(MpegEncContext *s, int header)
preferred ID for MPEG-1/2 video decoding
static void error(const char *err)
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
static const uint8_t svcd_scan_offset_placeholder[]
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static const int8_t mv[256][2]
#define MV_TYPE_16X16
1 vector for the whole mb
#define AV_CODEC_FLAG2_DROP_FRAME_TIMECODE
timecode is in drop frame format.
int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
Adjust frame number for NTSC drop frame time code.
int coded_picture_number
picture number in bitstream order
enum AVStereo3DType type
How views are packed within the video.
#define AV_LOG_INFO
Standard information.
int concealment_motion_vectors
Libavcodec external API header.
Views are on top of each other.
char * tc_opt_str
timecode option string
main external API structure.
ScanTable intra_scantable
int height
picture size. must be a multiple of 16
static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, int16_t block[8][64], int motion_x, int motion_y, int mb_block_count)
av_cold int ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
int ff_mpv_encode_init(AVCodecContext *avctx)
uint8_t * inter_ac_vlc_length
static uint8_t mpeg1_index_run[2][64]
uint16_t * intra_matrix
custom intra quantization matrix
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
enum AVColorSpace colorspace
YUV colorspace type.
Rational number (pair of numerator and denominator).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
uint8_t * index_run[2]
encoding only
void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
int f_code
forward MV resolution
uint16_t * inter_matrix
custom inter quantization matrix
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
static enum AVPixelFormat pix_fmts[]
av_cold void ff_mpeg12_common_init(MpegEncContext *s)
static av_const int sign_extend(int val, unsigned bits)
int last_mv_dir
last mv_dir, used for B-frame encoding
void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], int motion_x, int motion_y)
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
static av_cold int encode_init(AVCodecContext *avctx)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
struct AVCodecContext * avctx
PutBitContext pb
bit output
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
const AVRational ff_mpeg2_aspect[16]
static av_always_inline void put_qscale(MpegEncContext *s)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
static uint32_t mpeg1_chr_dc_uni[512]
static const AVOption mpeg2_options[]
uint8_t ff_mpeg12_static_rl_table_store[2][2][2 *MAX_RUN+MAX_LEVEL+3]
int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
Find which of the two rationals is closer to another rational.
const uint8_t ff_mpeg12_mbPatTable[64][2]
int ff_mpv_encode_end(AVCodecContext *avctx)
void ff_mpeg1_encode_slice_header(MpegEncContext *s)
int last_bits
temp var used for calculating the above vars
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define FF_ENABLE_DEPRECATION_WARNINGS
int top_field_first
If the content is interlaced, is top field displayed first.
int drop_frame_timecode
timecode is in drop frame format.
int resync_mb_y
y position of last resync marker
const uint8_t ff_mpeg12_mbAddrIncrTable[36][2]
int64_t bit_rate
wanted bit rate
int key_frame
1 -> keyframe, 0-> not
int flags2
AV_CODEC_FLAG2_*.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
const uint8_t ff_mpeg12_mbMotionVectorTable[17][2]
#define PICTURE_START_CODE
#define AV_CODEC_FLAG_CLOSED_GOP
int b_code
backward MV resolution for B-frames (MPEG-4)
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
AVTimecode tc
timecode context
uint32_t flags
flags such as drop frame, +24 hours support, ...
Stereoscopic 3d metadata.
AVPixelFormat
Pixel format.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
int64_t rc_max_rate
maximum bitrate
const AVRational ff_mpeg12_frame_rate_tab[]