[FFmpeg-cvslog] avformat/mxfenc: factorize timecode checking and setting
Marton Balint
git at videolan.org
Sat Mar 14 23:52:44 EET 2020
ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Tue Mar 3 23:13:07 2020 +0100| [331b96acb595631418322c78131bda358596a308] | committer: Marton Balint
avformat/mxfenc: factorize timecode checking and setting
Signed-off-by: Marton Balint <cus at passwd.hu>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=331b96acb595631418322c78131bda358596a308
---
libavformat/mxfenc.c | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index cf63e64c09..3616d47ce8 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2407,17 +2407,24 @@ static void mxf_gen_umid(AVFormatContext *s)
mxf->instance_number = seed & 0xFFFFFF;
}
-static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational rate)
+static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational tbc)
{
MXFContext *mxf = s->priv_data;
AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
+
+ if (!ff_mxf_get_content_package_rate(tbc)) {
+ av_log(s, AV_LOG_ERROR, "Unsupported frame rate %d/%d\n", tbc.den, tbc.num);
+ return AVERROR(EINVAL);
+ }
+
+ mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
if (!tcr)
tcr = av_dict_get(st->metadata, "timecode", NULL, 0);
if (tcr)
- return av_timecode_init_from_string(&mxf->tc, rate, tcr->value, s);
+ return av_timecode_init_from_string(&mxf->tc, av_inv_q(tbc), tcr->value, s);
else
- return av_timecode_init(&mxf->tc, rate, 0, 0, s);
+ return av_timecode_init(&mxf->tc, av_inv_q(tbc), 0, 0, s);
}
static int mxf_write_header(AVFormatContext *s)
@@ -2454,7 +2461,7 @@ static int mxf_write_header(AVFormatContext *s)
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
// TODO: should be avg_frame_rate
- AVRational rate, tbc = st->time_base;
+ AVRational tbc = st->time_base;
// Default component depth to 8
sc->component_depth = 8;
sc->h_chroma_sub_sample = 2;
@@ -2479,16 +2486,9 @@ static int mxf_write_header(AVFormatContext *s)
}
mxf->content_package_rate = ff_mxf_get_content_package_rate(tbc);
- if (!mxf->content_package_rate) {
- av_log(s, AV_LOG_ERROR, "Unsupported video frame rate %d/%d\n",
- tbc.den, tbc.num);
- return AVERROR(EINVAL);
- }
- mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
mxf->time_base = tbc;
- rate = av_inv_q(mxf->time_base);
avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
- if((ret = mxf_init_timecode(s, st, rate)) < 0)
+ if((ret = mxf_init_timecode(s, st, tbc)) < 0)
return ret;
if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
@@ -2564,16 +2564,10 @@ static int mxf_write_header(AVFormatContext *s)
return AVERROR(EINVAL);
}
- if (!ff_mxf_get_content_package_rate(tbc)) {
- av_log(s, AV_LOG_ERROR, "Unsupported timecode frame rate %d/%d\n", tbc.den, tbc.num);
- return AVERROR(EINVAL);
- }
-
mxf->time_base = st->time_base;
- if((ret = mxf_init_timecode(s, st, av_inv_q(tbc))) < 0)
+ if((ret = mxf_init_timecode(s, st, tbc)) < 0)
return ret;
- mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3;
sc->index = INDEX_WAV;
} else {
More information about the ffmpeg-cvslog
mailing list