avformat/movenc: Explicitly address potential division by zero.

find_fps attempts to infer framerate from AVCodec's timebase. When this
results in a frame rate that isn't explicitly marked as supported in
av_timecode_check_frame_rate, find_fps returns the AVStream's
avg_frame_rate, which, per avformat.h, _may_ be set (or not).

mov_get_mpeg2_xdcam_codec_tag, mov_get_h264_codec_tag and
find_compressor attempt to call av_q2d on the return value of find_fps,
which in the above case, may result in division by zero and therefore,
an undefined frame rate when NaN is converted to int.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Lucas Cooper 2017-04-27 15:08:29 -07:00 committed by Michael Niedermayer
parent 1bee78a019
commit 77bc507f6f
1 changed files with 12 additions and 3 deletions

View File

@ -1321,12 +1321,21 @@ static AVRational find_fps(AVFormatContext *s, AVStream *st)
return rate; return rate;
} }
static int defined_frame_rate(AVFormatContext *s, AVStream *st)
{
AVRational rational_framerate = find_fps(s, st);
int rate = 0;
if (rational_framerate.den != 0)
rate = av_q2d(rational_framerate);
return rate;
}
static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track)
{ {
int tag = track->par->codec_tag; int tag = track->par->codec_tag;
int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE;
AVStream *st = track->st; AVStream *st = track->st;
int rate = av_q2d(find_fps(s, st)); int rate = defined_frame_rate(s, st);
if (!tag) if (!tag)
tag = MKTAG('m', '2', 'v', '1'); //fallback tag tag = MKTAG('m', '2', 'v', '1'); //fallback tag
@ -1388,7 +1397,7 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track)
int tag = track->par->codec_tag; int tag = track->par->codec_tag;
int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE;
AVStream *st = track->st; AVStream *st = track->st;
int rate = av_q2d(find_fps(s, st)); int rate = defined_frame_rate(s, st);
if (!tag) if (!tag)
tag = MKTAG('a', 'v', 'c', 'i'); //fallback tag tag = MKTAG('a', 'v', 'c', 'i'); //fallback tag
@ -1850,7 +1859,7 @@ static void find_compressor(char * compressor_name, int len, MOVTrack *track)
} else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) { } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE;
AVStream *st = track->st; AVStream *st = track->st;
int rate = av_q2d(find_fps(NULL, st)); int rate = defined_frame_rate(NULL, st);
av_strlcatf(compressor_name, len, "XDCAM"); av_strlcatf(compressor_name, len, "XDCAM");
if (track->par->format == AV_PIX_FMT_YUV422P) { if (track->par->format == AV_PIX_FMT_YUV422P) {
av_strlcatf(compressor_name, len, " HD422"); av_strlcatf(compressor_name, len, " HD422");