Skip to content

Commit

Permalink
libavcodec: Don't crash in avcodec_encode_audio if time_base isn't set
Browse files Browse the repository at this point in the history
Earlier, calling avcodec_encode_audio worked fine even if time_base
wasn't set. Now it crashes due to trying to scale the output pts to
the codec context time base. This affects e.g. VLC.

If no time_base is set for audio codecs, set it to the sample
rate.

CC: [email protected]
Signed-off-by: Martin Storsjö <[email protected]>
  • Loading branch information
mstorsjo committed Jan 27, 2012
1 parent bca77a1 commit 9a7dc61
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libavcodec/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD
}
avctx->frame_number = 0;

if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
(!avctx->time_base.num || !avctx->time_base.den)) {
avctx->time_base.num = 1;
avctx->time_base.den = avctx->sample_rate;
}

if (HAVE_THREADS && !avctx->thread_opaque) {
ret = ff_thread_init(avctx);
if (ret < 0) {
Expand Down

0 comments on commit 9a7dc61

Please sign in to comment.