32#include "config_components.h"
56#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
57static const uint8_t svcd_scan_offset_placeholder[] = {
58 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
59 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
65static uint8_t uni_mpeg1_ac_vlc_len[64 * 64 * 2];
66static uint8_t uni_mpeg2_ac_vlc_len[64 * 64 * 2];
68static uint8_t mpeg12_max_level[
MAX_LEVEL + 1];
69static uint8_t mpeg12_index_run[
MAX_RUN + 1];
73static uint32_t mpeg1_lum_dc_uni[512];
74static uint32_t mpeg1_chr_dc_uni[512];
76typedef struct MPEG12EncContext {
77 MPVMainEncContext mpeg;
78 AVRational frame_rate_ext;
79 unsigned frame_rate_index;
81 int gop_picture_number;
86 int drop_frame_timecode;
92#define VIDEO_FORMAT_COMPONENT 0
93#define VIDEO_FORMAT_PAL 1
94#define VIDEO_FORMAT_NTSC 2
95#define VIDEO_FORMAT_SECAM 3
96#define VIDEO_FORMAT_MAC 4
97#define VIDEO_FORMAT_UNSPECIFIED 5
100#define A53_MAX_CC_COUNT 0x1f
104 const uint8_t index_run[],
105 const uint16_t table_vlc[][2],
106 uint8_t uni_ac_vlc_len[])
110 for (
i = 0;
i < 128;
i++) {
119 if (alevel > max_level[
run])
122 code = index_run[
run] + alevel - 1;
141#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
149static void mpeg1_encode_sequence_header(MPEG12EncContext *mpeg12)
152 unsigned int vbv_buffer_size, fps, v;
153 int constraint_parameter_flag;
156 int64_t best_aspect_error = INT64_MAX;
157 AVRational aspect_ratio =
s->c.avctx->sample_aspect_ratio;
158 int aspect_ratio_info;
165 if (aspect_ratio.
num == 0 || aspect_ratio.
den == 0)
174 for (
int i = 1;
i < 15;
i++) {
183 if (
error - 2 <= best_aspect_error) {
184 best_aspect_error =
error;
185 aspect_ratio_info =
i;
190 put_bits(&
s->pb, 4, mpeg12->frame_rate_index);
192 if (
s->c.avctx->rc_max_rate) {
193 v = (
s->c.avctx->rc_max_rate + 399) / 400;
200 if (
s->c.avctx->rc_buffer_size)
201 vbv_buffer_size =
s->c.avctx->rc_buffer_size;
206 vbv_buffer_size = (vbv_buffer_size + 16383) / 16384;
212 constraint_parameter_flag =
214 s->c.height <= 576 &&
215 s->c.mb_width *
s->c.mb_height <= 396 &&
218 s->c.avctx->me_range &&
219 s->c.avctx->me_range < 128 &&
220 vbv_buffer_size <= 20 &&
221 v <= 1856000 / 400 &&
224 put_bits(&
s->pb, 1, constraint_parameter_flag);
233 int use_seq_disp_ext;
243 put_bits(&
s->pb, 1,
s->c.progressive_sequence);
249 put_bits(&
s->pb, 8, vbv_buffer_size >> 10);
251 put_bits(&
s->pb, 2, mpeg12->frame_rate_ext.num-1);
252 put_bits(&
s->pb, 5, mpeg12->frame_rate_ext.den-1);
257 if (pan_scan->width && pan_scan->height) {
258 width = pan_scan->width >> 4;
259 height = pan_scan->height >> 4;
263 use_seq_disp_ext = (
width !=
s->c.width ||
268 mpeg12->video_format != VIDEO_FORMAT_UNSPECIFIED);
270 if (mpeg12->seq_disp_ext == 1 ||
271 (mpeg12->seq_disp_ext == -1 && use_seq_disp_ext)) {
274 put_bits(&
s->pb, 3, mpeg12->video_format);
276 put_bits(&
s->pb, 8,
s->c.avctx->color_primaries);
287 put_bits(&
s->pb, 1, mpeg12->drop_frame_timecode);
291 time_code =
s->c.cur_pic.ptr->coded_picture_number +
292 mpeg12->timecode_frame_start;
294 mpeg12->gop_picture_number =
s->c.cur_pic.ptr->coded_picture_number;
297 if (mpeg12->drop_frame_timecode)
300 put_bits(&
s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
301 put_bits(&
s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
303 put_bits(&
s->pb, 6, (uint32_t)((time_code / fps) % 60));
304 put_bits(&
s->pb, 6, (uint32_t)((time_code % fps)));
306 mpeg12->mpeg.intra_only || !mpeg12->gop_picture_number);
342 MPEG12EncContext *
const mpeg12 = (MPEG12EncContext*)m;
348 mpeg1_encode_sequence_header(mpeg12);
355 (
s->picture_number - mpeg12->gop_picture_number) & 0x3ff);
382 s->c.frame_pred_frame_dct = 1;
403 if (
s->c.progressive_sequence)
408 s->c.frame_pred_frame_dct =
s->c.progressive_sequence;
410 put_bits(&
s->pb, 1,
s->c.frame_pred_frame_dct);
411 put_bits(&
s->pb, 1,
s->c.concealment_motion_vectors);
416 s->c.progressive_frame =
s->c.progressive_sequence;
423 if (mpeg12->scan_offset) {
427 for (
i = 0;
i <
sizeof(svcd_scan_offset_placeholder);
i++)
428 put_bits(&
s->pb, 8, svcd_scan_offset_placeholder[
i]);
436 switch (stereo->type) {
466 if (CONFIG_MPEG2VIDEO_ENCODER && mpeg12->a53_cc) {
479 for (
int i = 0;
i < side_data->
size;
i++)
485 "Closed Caption size (%zu) can not exceed "
486 "93 bytes and must be a multiple of 3\n", side_data->
size);
498 int has_mv,
int field_motion)
501 if (!
s->c.frame_pred_frame_dct) {
517 int bit_size = f_or_b_code - 1;
518 int range = 1 << bit_size;
549 unsigned int diff_u =
diff + 255;
572 mpeg1_lum_dc_uni[
diff + 255] & 0xFF,
573 mpeg1_lum_dc_uni[
diff + 255] >> 8);
576 mpeg1_chr_dc_uni[
diff + 255] & 0xFF,
577 mpeg1_chr_dc_uni[
diff + 255] >> 8);
583 int alevel,
level, last_non_zero, dc,
diff,
i, j,
run, last_index, sign;
587 last_index =
s->c.block_last_index[n];
591 component = (n <= 3 ? 0 : (n & 1) + 1);
593 diff = dc -
s->last_dc[component];
595 s->last_dc[component] = dc;
597 if (
s->c.intra_vlc_format)
615 last_non_zero =
i - 1;
617 for (;
i <= last_index;
i++) {
618 j =
s->c.intra_scantable.permutated[
i];
624 run =
i - last_non_zero - 1;
630 if (alevel <= mpeg12_max_level[
run]) {
631 code = mpeg12_index_run[
run] + alevel - 1;
634 (table_vlc[
code][0] << 1) + sign);
658 put_bits(&
s->pb, table_vlc[112][1], table_vlc[112][0]);
662 const int16_t
block[8][64],
663 int motion_x,
int motion_y,
668#define IS_MPEG1(s) (chroma_y_shift == 1 && (s)->c.codec_id == AV_CODEC_ID_MPEG1VIDEO)
670 const int mb_x =
s->c.mb_x;
671 const int mb_y =
s->c.mb_y;
672 const int first_mb = mb_x ==
s->c.resync_mb_x && mb_y ==
s->c.resync_mb_y;
676 for (
i = 0;
i < mb_block_count;
i++)
677 if (
s->c.block_last_index[
i] >= 0)
678 cbp |= 1 << (mb_block_count - 1 -
i);
681 (mb_x !=
s->c.mb_width - 1 ||
682 (mb_y !=
s->c.end_mb_y - 1 && IS_MPEG1(
s))) &&
686 ? ((
s->c.mv[0][0][0] -
s->c.last_mv[0][0][0]) |
687 (
s->c.mv[0][0][1] -
s->c.last_mv[0][0][1])) : 0) |
689 ? ((
s->c.mv[1][0][0] -
s->c.last_mv[1][0][0]) |
690 (
s->c.mv[1][0][1] -
s->c.last_mv[1][0][1])) : 0)) == 0))) {
692 s->c.qscale -=
s->dquant;
696 s->c.last_mv[0][0][0] =
697 s->c.last_mv[0][0][1] =
698 s->c.last_mv[0][1][0] =
699 s->c.last_mv[0][1][1] = 0;
704 encode_mb_skip_run(
s,
s->c.mb_x);
706 encode_mb_skip_run(
s,
s->mb_skip_run);
710 if (
s->dquant && cbp) {
712 put_mb_modes(
s, 2, 1, 0, 0);
716 put_mb_modes(
s, 1, 1, 0, 0);
717 s->c.qscale -=
s->dquant;
721 }
else if (
s->c.mb_intra) {
722 if (
s->dquant && cbp) {
723 put_mb_modes(
s, 6, 0x01, 0, 0);
726 put_mb_modes(
s, 5, 0x03, 0, 0);
727 s->c.qscale -=
s->dquant;
731 memset(
s->c.last_mv, 0,
sizeof(
s->c.last_mv));
735 if ((motion_x | motion_y) == 0) {
738 put_mb_modes(
s, 5, 1, 0, 0);
742 put_mb_modes(
s, 2, 1, 0, 0);
747 put_mb_modes(
s, 5, 2, 1, 0);
750 put_mb_modes(
s, 1, 1, 1, 0);
754 mpeg1_encode_motion(
s,
755 motion_x -
s->c.last_mv[0][0][0],
758 mpeg1_encode_motion(
s,
759 motion_y -
s->c.last_mv[0][0][1],
765 if (!
s->c.frame_pred_frame_dct)
769 mpeg1_encode_motion(
s,
770 motion_x -
s->c.last_mv[0][0][0],
773 mpeg1_encode_motion(
s,
774 motion_y -
s->c.last_mv[0][0][1],
776 s->c.qscale -=
s->dquant;
779 s->c.last_mv[0][1][0] =
s->c.last_mv[0][0][0] = motion_x;
780 s->c.last_mv[0][1][1] =
s->c.last_mv[0][0][1] = motion_y;
786 put_mb_modes(
s, 5, 2, 1, 1);
789 put_mb_modes(
s, 1, 1, 1, 1);
794 s->c.qscale -=
s->dquant;
797 for (
i = 0;
i < 2;
i++) {
799 mpeg1_encode_motion(
s,
800 s->c.mv[0][
i][0] -
s->c.last_mv[0][
i][0],
802 mpeg1_encode_motion(
s,
803 s->c.mv[0][
i][1] - (
s->c.last_mv[0][
i][1] >> 1),
805 s->c.last_mv[0][
i][0] =
s->c.mv[0][
i][0];
806 s->c.last_mv[0][
i][1] = 2 *
s->c.mv[0][
i][1];
811 if (chroma_y_shift) {
827 put_mb_modes(
s, 6, 3, 1, 0);
829 put_mb_modes(
s, 8 -
s->c.mv_dir, 2, 1, 0);
832 put_mb_modes(
s, 5 -
s->c.mv_dir, 3, 1, 0);
836 if (!
s->c.frame_pred_frame_dct)
838 s->c.qscale -=
s->dquant;
842 mpeg1_encode_motion(
s,
843 s->c.mv[0][0][0] -
s->c.last_mv[0][0][0],
845 mpeg1_encode_motion(
s,
846 s->c.mv[0][0][1] -
s->c.last_mv[0][0][1],
848 s->c.last_mv[0][0][0] =
849 s->c.last_mv[0][1][0] =
s->c.mv[0][0][0];
850 s->c.last_mv[0][0][1] =
851 s->c.last_mv[0][1][1] =
s->c.mv[0][0][1];
854 mpeg1_encode_motion(
s,
855 s->c.mv[1][0][0] -
s->c.last_mv[1][0][0],
857 mpeg1_encode_motion(
s,
858 s->c.mv[1][0][1] -
s->c.last_mv[1][0][1],
860 s->c.last_mv[1][0][0] =
861 s->c.last_mv[1][1][0] =
s->c.mv[1][0][0];
862 s->c.last_mv[1][0][1] =
863 s->c.last_mv[1][1][1] =
s->c.mv[1][0][1];
871 put_mb_modes(
s, 6, 3, 1, 1);
873 put_mb_modes(
s, 8 -
s->c.mv_dir, 2, 1, 1);
876 put_mb_modes(
s, 5 -
s->c.mv_dir, 3, 1, 1);
881 s->c.qscale -=
s->dquant;
885 for (
i = 0;
i < 2;
i++) {
887 mpeg1_encode_motion(
s,
888 s->c.mv[0][
i][0] -
s->c.last_mv[0][
i][0],
890 mpeg1_encode_motion(
s,
891 s->c.mv[0][
i][1] - (
s->c.last_mv[0][
i][1] >> 1),
893 s->c.last_mv[0][
i][0] =
s->c.mv[0][
i][0];
894 s->c.last_mv[0][
i][1] =
s->c.mv[0][
i][1] * 2;
898 for (
i = 0;
i < 2;
i++) {
900 mpeg1_encode_motion(
s,
901 s->c.mv[1][
i][0] -
s->c.last_mv[1][
i][0],
903 mpeg1_encode_motion(
s,
904 s->c.mv[1][
i][1] - (
s->c.last_mv[1][
i][1] >> 1),
906 s->c.last_mv[1][
i][0] =
s->c.mv[1][
i][0];
907 s->c.last_mv[1][
i][1] =
s->c.mv[1][
i][1] * 2;
913 if (chroma_y_shift) {
925 for (
i = 0;
i < mb_block_count;
i++)
926 if (cbp & (1 << (mb_block_count - 1 -
i)))
937 int motion_x,
int motion_y)
940 s->last_dc[0] =
s->last_dc[1] =
s->last_dc[2] = 128 <<
s->c.intra_dc_precision;
942 mpeg1_encode_mb_internal(
s,
block, motion_x, motion_y, 6, 1);
944 mpeg1_encode_mb_internal(
s,
block, motion_x, motion_y, 8, 0);
947static av_cold void mpeg12_encode_init_static(
void)
958 for (
int i = -255;
i < 256;
i++) {
971 mpeg1_lum_dc_uni[
i + 255] =
bits + (
code << 8);
976 mpeg1_chr_dc_uni[
i + 255] =
bits + (
code << 8);
979 for (
int f_code = 1; f_code <=
MAX_FCODE; f_code++)
988 bit_size = f_code - 1;
1007 for (
int f_code =
MAX_FCODE; f_code > 0; f_code--)
1008 for (
int mv = -(8 << f_code);
mv < (8 << f_code);
mv++)
1018 for (
int i = 1;
i < 14;
i++) {
1023 for (ext.
num = 1; ext.
num <= 4; ext.
num++) {
1024 for (ext.
den = 1; ext.
den <= 32; ext.
den++) {
1036 mpeg12->frame_rate_index =
i;
1037 mpeg12->frame_rate_ext.num = ext.
num;
1038 mpeg12->frame_rate_ext.den = ext.
den;
1053 MPEG12EncContext *
const mpeg12 = avctx->
priv_data;
1059 if (avctx->
width > max_size || avctx->
height > max_size) {
1062 max_size, max_size);
1065 if ((avctx->
width & 0xFFF) == 0 && (avctx->
height & 0xFFF) == 1) {
1071 if ((avctx->
width & 0xFFF) == 0 || (avctx->
height & 0xFFF) == 0) {
1072 av_log(avctx,
AV_LOG_ERROR,
"Width or Height are not allowed to be multiples of 4096\n"
1078 if (
s->c.q_scale_type == 1) {
1079 if (avctx->
qmax > 28) {
1081 "non linear quant only supports qmax <= 28 currently\n");
1105 "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
1110 else if (avctx->
width <= 1440)
1118 s->encode_mb = mpeg12_encode_mb;
1123 s->min_qcoeff = -255;
1124 s->max_qcoeff = 255;
1126 s->min_qcoeff = -2047;
1127 s->max_qcoeff = 2047;
1129#if FF_API_INTRA_DC_PRECISION
1130 if (
s->c.intra_dc_precision < 0) {
1132 s->c.intra_dc_precision = avctx->intra_dc_precision;
1135 if (
s->c.intra_dc_precision < 0) {
1136 s->c.intra_dc_precision += 8;
1137 }
else if (
s->c.intra_dc_precision >= 8)
1138 s->c.intra_dc_precision -= 8;
1140 if (
s->c.intra_dc_precision < 0) {
1142 "intra dc precision must be positive, note some applications use"
1143 " 0 and some 8 as base meaning 8bit, the value must not be smaller than that\n");
1147 if (
s->c.intra_dc_precision > 3) {
1154 s->c.y_dc_scale_table =
1157 if (
s->c.intra_vlc_format) {
1158 s->intra_ac_vlc_length =
1159 s->intra_ac_vlc_last_length = uni_mpeg2_ac_vlc_len;
1161 s->intra_ac_vlc_length =
1162 s->intra_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;
1164 s->inter_ac_vlc_length =
1165 s->inter_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;
1172 s->c.thread_context[
s->c.slice_context_count - 1]->start_mb_y >
1178 "With more than 175 slice contexts, we have to handle "
1179 "the case in which there is no work to do for some "
1182 const int nb_slices =
s->c.slice_context_count - 1;
1184 s->c.thread_context[nb_slices]->start_mb_y = mb_height;
1187 for (
int i = 0;
i < nb_slices;
i++) {
1188 s->c.thread_context[
i]->start_mb_y =
1189 (mb_height * (
i ) + nb_slices / 2) / nb_slices;
1190 s->c.thread_context[
i]->end_mb_y =
1191 (mb_height * (
i + 1) + nb_slices / 2) / nb_slices;
1195 if (find_frame_rate_index(avctx, mpeg12) < 0) {
1202 "MPEG-1/2 does not support %d/%d fps, there may be AV sync issues\n",
1212 "Warning vbv_delay will be set to 0xFFFF (=VBR) as the "
1213 "specified vbv buffer is too large for the given bitrate!\n");
1216 if (mpeg12->drop_frame_timecode)
1218 if (mpeg12->drop_frame_timecode && mpeg12->frame_rate_index != 4) {
1220 "Drop frame time code only allowed with 1001/30000 fps\n");
1224 if (mpeg12->tc_opt_str) {
1230 mpeg12->timecode_frame_start = mpeg12->tc.start;
1232 mpeg12->timecode_frame_start = 0;
1240#define OFFSET(x) offsetof(MPEG12EncContext, x)
1241#define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1242#define COMMON_OPTS \
1243 { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.", \
1244 OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE },\
1245 { "drop_frame_timecode", "Timecode is in drop frame format.", \
1246 OFFSET(drop_frame_timecode), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
1247 { "scan_offset", "Reserve space for SVCD scan offset user data.", \
1248 OFFSET(scan_offset), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
1249 { "timecode_frame_start", "GOP timecode frame start number, in non-drop-frame format", \
1250 OFFSET(timecode_frame_start), AV_OPT_TYPE_INT64, {.i64 = -1 }, -1, INT64_MAX, VE}, \
1251 FF_MPV_COMMON_BFRAME_OPTS
1253static const AVOption mpeg1_options[] = {
1260static const AVOption mpeg2_options[] = {
1262#if FF_API_INTRA_DC_PRECISION
1267 {
"intra_vlc",
"Use MPEG-2 intra VLC table.",
1272 {
"seq_disp_ext",
"Write sequence_display_extension blocks.",
OFFSET(seq_disp_ext),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE, .unit =
"seq_disp_ext" },
1276 {
"video_format",
"Video_format in the sequence_display_extension indicating the source of the video.",
OFFSET(video_format),
AV_OPT_TYPE_INT, { .i64 = VIDEO_FORMAT_UNSPECIFIED }, 0, 7,
VE, .unit =
"video_format" },
1277 {
"component",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_COMPONENT }, 0, 0,
VE, .unit =
"video_format" },
1282 {
"unspecified",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_UNSPECIFIED}, 0, 0,
VE, .unit =
"video_format" },
1283#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, { .i64 = value }, 0, 0, VE, .unit = "avctx.level"
1284 {
LEVEL(
"high", 4) },
1285 {
LEVEL(
"high1440", 6) },
1286 {
LEVEL(
"main", 8) },
1287 {
LEVEL(
"low", 10) },
1295#define mpeg12_class(x) \
1296static const AVClass mpeg ## x ## _class = { \
1297 .class_name = "mpeg" # x "video encoder", \
1298 .item_name = av_default_item_name, \
1299 .option = mpeg ## x ## _options, \
1300 .version = LIBAVUTIL_VERSION_INT, \
1307 .p.name =
"mpeg1video",
1311 .priv_data_size =
sizeof(MPEG12EncContext),
1322 .p.priv_class = &mpeg1_class,
1326 .p.name =
"mpeg2video",
1330 .priv_data_size =
sizeof(MPEG12EncContext),
1341 .p.priv_class = &mpeg2_class,
static double val(void *priv, double ch)
const FFCodec ff_mpeg1video_encoder
const FFCodec ff_mpeg2video_encoder
static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
static av_cold int encode_init(AVCodecContext *avctx)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define SLICE_MAX_START_CODE
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define CODEC_FRAMERATES_ARRAY(array)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_PROFILE_MPEG2_MAIN
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_MPEG2_HIGH
#define AV_PROFILE_MPEG2_422
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#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 AV_CODEC_FLAG_CLOSED_GOP
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
@ AV_FRAME_DATA_PANSCAN
The data is the AVPanScan struct defined in libavcodec.
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
Find which of the two rationals is closer to another rational.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
@ AV_ROUND_ZERO
Round toward zero.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
@ AV_STEREO3D_SIDEBYSIDE_QUINCUNX
Views are next to each other, but when upscaling apply a checkerboard pattern.
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static const int8_t mv[256][2]
Macro definitions for various function/variable attributes.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static int ff_thread_once(char *control, void(*routine)(void))
#define MKBETAG(a, b, c, d)
static av_const int sign_extend(int val, unsigned bits)
#define MASK_ABS(mask, level)
#define PICTURE_START_CODE
#define SLICE_MIN_START_CODE
const uint16_t ff_mpeg12_vlc_dc_chroma_code[12]
const uint8_t ff_mpeg12_mbPatTable[64][2]
const int8_t ff_mpeg12_level[MPEG12_RL_NB_ELEMS]
const uint8_t ff_mpeg12_mbAddrIncrTable[36][2]
const uint16_t ff_mpeg12_vlc_dc_lum_code[12]
const float ff_mpeg1_aspect[16]
const int8_t ff_mpeg12_run[MPEG12_RL_NB_ELEMS]
const uint8_t ff_mpeg12_mbMotionVectorTable[17][2]
const AVRational ff_mpeg2_aspect[16]
const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12]
const AVRational ff_mpeg2_frame_rate_tab[]
const uint16_t ff_mpeg1_vlc_table[MPEG12_RL_NB_ELEMS+2][2]
const unsigned char ff_mpeg12_vlc_dc_lum_bits[12]
const uint16_t ff_mpeg2_vlc_table[MPEG12_RL_NB_ELEMS+2][2]
const AVRational ff_mpeg12_frame_rate_tab[]
av_cold void ff_mpeg1_init_uni_ac_vlc(const int8_t max_level[], const uint8_t index_run[], const uint16_t table_vlc[][2], uint8_t uni_ac_vlc_len[])
void ff_mpeg1_encode_slice_header(MPVEncContext *s)
#define MPEG12_RL_NB_ELEMS
static uint8_t fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need.
#define MV_TYPE_FIELD
2 vectors, one per field
#define MV_TYPE_16X16
1 vector for the whole mb
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
const uint8_t ff_mpeg12_dc_scale_table[4][32]
static int get_bits_diff(MPVEncContext *s)
#define UNI_AC_ENC_INDEX(run, level)
#define FF_MPV_COMMON_OPTS
#define FF_MPV_COMMON_MOTION_EST_OPTS
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define FF_MPEG2_PROFILE_OPTS
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static int put_bytes_count(const PutBitContext *s, int round_up)
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static void put_bits_assume_flushed(const PutBitContext *s)
Inform the compiler that a PutBitContext is flushed (i.e.
av_cold void ff_rl_init_level_run(uint8_t max_level[MAX_LEVEL+1], uint8_t index_run[MAX_RUN+1], const uint8_t table_run[], const uint8_t table_level[], int n)
Initialize max_level and index_run from table_run and table_level; this is equivalent to initializing...
static const uint8_t header[24]
static void encode_dc(PutBitContext *pb, int diff, int component)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int rc_buffer_size
decoder bitstream buffer size
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
int level
Encoding level descriptor.
const struct AVCodec * codec
int64_t rc_max_rate
maximum bitrate
int qmax
maximum quantizer
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int64_t rc_min_rate
minimum bitrate
const char * long_name
Descriptive name for the codec, meant to be more human readable than name.
const char * name
Name of the codec implementation.
Structure to hold side data for an AVFrame.
Rational number (pair of numerator and denominator).
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
MPVEncContext s
The main slicecontext.
int vbv_delay_pos
offset of vbv_delay in the bitstream
const uint8_t * fcode_tab
smallest fcode needed for each MV
int(* encode_picture_header)(struct MPVMainEncContext *m)
static void error(const char *err)
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
Parse timecode representation (hh:mm:ss[:;.
int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
Adjust frame number for NTSC drop frame time code.
@ AV_TIMECODE_FLAG_DROPFRAME
timecode is drop frame
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)