From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 19/30] avcodec/mpeg12enc: Move options-related fields to MPEG12EncContext Date: Thu, 23 Dec 2021 10:13:29 +0100 Message-ID: <AM7PR03MB666050FBEF475F950C6FB51A8F7E9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw) In-Reply-To: <AM7PR03MB66606013F665BF849CE7CAD68F7D9@AM7PR03MB6660.eurprd03.prod.outlook.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mpeg12dec.c | 1 + libavcodec/mpeg12enc.c | 58 +++++++++++++++++++++++++----------------- libavcodec/mpegvideo.h | 9 ------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 672031b6db..b75b2c9ea2 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -33,6 +33,7 @@ #include "libavutil/internal.h" #include "libavutil/mem_internal.h" #include "libavutil/stereo3d.h" +#include "libavutil/timecode.h" #include "libavutil/video_enc_params.h" #include "avcodec.h" diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 97df5523cc..3692494713 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -65,6 +65,16 @@ static uint32_t mpeg1_chr_dc_uni[512]; typedef struct MPEG12EncContext { MpegEncContext mpeg; AVRational frame_rate_ext; + + int64_t timecode_frame_start; ///< GOP timecode frame start number, in non drop frame format + AVTimecode tc; ///< timecode context + char *tc_opt_str; ///< timecode option string + int drop_frame_timecode; ///< timecode is in drop frame format. + int scan_offset; ///< reserve space for SVCD scan offset user data. + + int a53_cc; + int seq_disp_ext; + int video_format; } MPEG12EncContext; #define A53_MAX_CC_COUNT 0x1f @@ -218,24 +228,24 @@ static av_cold int encode_init(AVCodecContext *avctx) } } - s->drop_frame_timecode = s->drop_frame_timecode || !!(avctx->flags2 & AV_CODEC_FLAG2_DROP_FRAME_TIMECODE); - if (s->drop_frame_timecode) - s->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME; - if (s->drop_frame_timecode && s->frame_rate_index != 4) { + mpeg12->drop_frame_timecode = mpeg12->drop_frame_timecode || !!(avctx->flags2 & AV_CODEC_FLAG2_DROP_FRAME_TIMECODE); + if (mpeg12->drop_frame_timecode) + mpeg12->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME; + if (mpeg12->drop_frame_timecode && s->frame_rate_index != 4) { av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); return AVERROR(EINVAL); } - if (s->tc_opt_str) { + if (mpeg12->tc_opt_str) { AVRational rate = ff_mpeg12_frame_rate_tab[s->frame_rate_index]; - int ret = av_timecode_init_from_string(&s->tc, rate, s->tc_opt_str, s); + int ret = av_timecode_init_from_string(&mpeg12->tc, rate, mpeg12->tc_opt_str, s); if (ret < 0) return ret; - s->drop_frame_timecode = !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME); - s->timecode_frame_start = s->tc.start; + mpeg12->drop_frame_timecode = !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME); + mpeg12->timecode_frame_start = mpeg12->tc.start; } else { - s->timecode_frame_start = 0; // default is -1 + mpeg12->timecode_frame_start = 0; // default is -1 } return 0; @@ -364,12 +374,13 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) s->avctx->color_primaries != AVCOL_PRI_UNSPECIFIED || s->avctx->color_trc != AVCOL_TRC_UNSPECIFIED || s->avctx->colorspace != AVCOL_SPC_UNSPECIFIED || - s->video_format != VIDEO_FORMAT_UNSPECIFIED); + mpeg12->video_format != VIDEO_FORMAT_UNSPECIFIED); - if (s->seq_disp_ext == 1 || (s->seq_disp_ext == -1 && use_seq_disp_ext)) { + if (mpeg12->seq_disp_ext == 1 || + (mpeg12->seq_disp_ext == -1 && use_seq_disp_ext)) { put_header(s, EXT_START_CODE); put_bits(&s->pb, 4, 2); // sequence display extension - put_bits(&s->pb, 3, s->video_format); // video_format + put_bits(&s->pb, 3, mpeg12->video_format); // video_format put_bits(&s->pb, 1, 1); // colour_description put_bits(&s->pb, 8, s->avctx->color_primaries); // colour_primaries put_bits(&s->pb, 8, s->avctx->color_trc); // transfer_characteristics @@ -382,17 +393,17 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) } put_header(s, GOP_START_CODE); - put_bits(&s->pb, 1, s->drop_frame_timecode); // drop frame flag + put_bits(&s->pb, 1, mpeg12->drop_frame_timecode); // drop frame flag /* time code: we must convert from the real frame rate to a * fake MPEG frame rate in case of low frame rate */ fps = (framerate.num + framerate.den / 2) / framerate.den; time_code = s->current_picture_ptr->f->coded_picture_number + - s->timecode_frame_start; + mpeg12->timecode_frame_start; s->gop_picture_number = s->current_picture_ptr->f->coded_picture_number; - av_assert0(s->drop_frame_timecode == !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME)); - if (s->drop_frame_timecode) + av_assert0(mpeg12->drop_frame_timecode == !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME)); + if (mpeg12->drop_frame_timecode) time_code = av_timecode_adjust_ntsc_framenum2(time_code, fps); put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); @@ -436,6 +447,7 @@ void ff_mpeg1_encode_slice_header(MpegEncContext *s) void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) { + MPEG12EncContext *const mpeg12 = (MPEG12EncContext*)s; AVFrameSideData *side_data; mpeg1_encode_sequence_header(s); @@ -513,7 +525,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) put_bits(&s->pb, 1, s->progressive_frame); put_bits(&s->pb, 1, 0); /* composite_display_flag */ } - if (s->scan_offset) { + if (mpeg12->scan_offset) { int i; put_header(s, USER_START_CODE); @@ -559,7 +571,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) } } - if (CONFIG_MPEG2VIDEO_ENCODER && s->a53_cc) { + if (CONFIG_MPEG2VIDEO_ENCODER && mpeg12->a53_cc) { side_data = av_frame_get_side_data(s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC); if (side_data) { @@ -1138,7 +1150,7 @@ av_cold void ff_mpeg1_encode_init(MpegEncContext *s) ff_thread_once(&init_static_once, mpeg12_encode_init_static); } -#define OFFSET(x) offsetof(MpegEncContext, x) +#define OFFSET(x) offsetof(MPEG12EncContext, x) #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM #define COMMON_OPTS \ { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.", \ @@ -1165,9 +1177,9 @@ static const AVOption mpeg1_options[] = { static const AVOption mpeg2_options[] = { COMMON_OPTS { "intra_vlc", "Use MPEG-2 intra VLC table.", - OFFSET(intra_vlc_format), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, - { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, - { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, + FF_MPV_OFFSET(intra_vlc_format), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, + { "non_linear_quant", "Use nonlinear quantizer.", FF_MPV_OFFSET(q_scale_type), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, + { "alternate_scan", "Enable alternate scantable.", FF_MPV_OFFSET(alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE }, { "seq_disp_ext", "Write sequence_display_extension blocks.", OFFSET(seq_disp_ext), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, "seq_disp_ext" }, { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, VE, "seq_disp_ext" }, @@ -1188,7 +1200,7 @@ static const AVOption mpeg2_options[] = { #undef LEVEL FF_MPV_COMMON_OPTS #if FF_API_MPEGVIDEO_OPTS - { "mpeg_quant", "Deprecated, does nothing", OFFSET(mpeg_quant), + { "mpeg_quant", "Deprecated, does nothing", FF_MPV_OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, 1, VE | AV_OPT_FLAG_DEPRECATED }, FF_MPV_DEPRECATED_MATRIX_OPT #endif diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 2611e7c667..fabcce2436 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -58,7 +58,6 @@ #include "videodsp.h" #include "libavutil/opt.h" -#include "libavutil/timecode.h" #define MAX_THREADS 32 @@ -443,7 +442,6 @@ typedef struct MpegEncContext { /* MPEG-2-specific - I wished not to have to support this mess. */ int progressive_sequence; int mpeg_f_code[2][2]; - int a53_cc; // picture structure defines are loaded from mpegutils.h int picture_structure; @@ -457,8 +455,6 @@ typedef struct MpegEncContext { int brd_scale; int intra_vlc_format; int alternate_scan; - int seq_disp_ext; - int video_format; #define VIDEO_FORMAT_COMPONENT 0 #define VIDEO_FORMAT_PAL 1 #define VIDEO_FORMAT_NTSC 2 @@ -478,16 +474,11 @@ typedef struct MpegEncContext { int full_pel[2]; int interlaced_dct; int first_field; ///< is 1 for the first field of a field picture 0 otherwise - int drop_frame_timecode; ///< timecode is in drop frame format. - int scan_offset; ///< reserve space for SVCD scan offset user data. /* RTP specific */ int rtp_mode; int rtp_payload_size; - char *tc_opt_str; ///< timecode option string - AVTimecode tc; ///< timecode context - uint8_t *ptr_lastgob; int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped int pack_pblocks; //xvmc needs to keep blocks without gaps. -- 2.32.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2021-12-23 9:14 UTC|newest] Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 02/14] avcodec/mjpegenc: Avoid allocation of MJpegContext Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 03/14] avcodec/mpegvideo_enc: Move MJPEG init checks to mjpegenc.c Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 04/14] avcodec/mpegvideo_enc: Remove redundant checks for multithreading Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 05/14] avcodec/mjpegenc: Add wrapper for ff_mjpeg_encode_picture_header() Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 06/14] avcodec/mjpegenc_common: Move code for MJPEG/AMV to mjpegenc Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 07/14] avcodec/mjpegenc_common: Fix intendation Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 08/14] avcodec/mpegvideo: Move MJPEG/AMV-only fields to MJpegContext Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 09/14] avcodec/mjpegenc: Deprecate unused prediction type Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 10/14] avcodec/mjpegenc_common: Pass MJpegContext for writing picture header Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 11/14] avcodec/mjpegenc_common: Don't call function unnecessarily Andreas Rheinhardt 2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 12/14] avcodec/mjpegenc_common: Use AVCodecContext.codec_id directly Andreas Rheinhardt 2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 13/14] avcodec/mpegvideo: Remove unnecessary headers Andreas Rheinhardt 2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 14/14] avcodec/mpegvideo_enc: Remove impossible branch Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 15/30] avcodec/speedhqenc: Inline constants Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 16/30] avcodec/mpegvideo_enc: Move updating mb_info to its only user Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 17/30] avcodec/mpeg12enc: Simplify check for A53 closed captions Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 18/30] avcodec/mpeg12enc: Add custom context, move mpeg2_frame_rate_ext to it Andreas Rheinhardt 2021-12-23 9:13 ` Andreas Rheinhardt [this message] 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 20/30] avcodec/mpegvideo_enc: Don't merge decoder-only fields Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 21/30] avcodec/mpeg12dec: Use %c to write single char Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 22/30] avcodec/mpegvideo: Don't duplicate identical code Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 23/30] avcodec/mpegvideo: Avoid needlessly calling function Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 24/30] avcodec/wmv2: Move ff_wmv2_add_mb() to the wmv2dec Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 25/30] avcodec/mpegvideo_motion: Don't duplicate identical code Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 26/30] avcodec/mpegvideo: Don't check for > 8 bit MPEG-1/2 Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 27/30] avcodec/mpegvideo: Partially check for being encoder at compile-time Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 28/30] avcodec/mpegvideo: Try to perform check for MPEG-1/2 " Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 29/30] avcodec/mpegvideo: Remove always-true branch Andreas Rheinhardt 2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 30/30] avcodec/mpegvideo: Check for no_rounding at compile-time if possible Andreas Rheinhardt 2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 31/36] avcodec/mpegvideo: Don't initialize error resilience context for encoder Andreas Rheinhardt 2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 32/36] avcodec/mpegvideo: Remove always-false check Andreas Rheinhardt 2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 33/36] avcodec/mpegvideo: Move decoding-only code into a new file Andreas Rheinhardt 2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA Andreas Rheinhardt 2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 34/35] " Andreas Rheinhardt 2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 35/35] configure: Remove mpegvideo dependency on me_cmp Andreas Rheinhardt 2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 35/36] avcodec/mpegvideo_enc: Improve inlining of chroma_format Andreas Rheinhardt 2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time Andreas Rheinhardt 2021-12-24 17:17 ` Michael Niedermayer 2021-12-24 18:30 ` Andreas Rheinhardt 2021-12-24 18:36 ` Michael Niedermayer 2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 37/39] avcodec/mpeg12enc: Also inline chroma subsampling Andreas Rheinhardt 2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 38/39] avcodec/mpeg12enc: Partially inline whether codec is MPEG-1 Andreas Rheinhardt 2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 39/39] avcodec/mpeg12enc: Inline constants Andreas Rheinhardt 2021-12-31 10:03 ` [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AM7PR03MB666050FBEF475F950C6FB51A8F7E9@AM7PR03MB6660.eurprd03.prod.outlook.com \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git