On Mon, 17 Nov 2014, Vittorio Giovara wrote:
CC: [email protected] Bug-Id: CID 1250330 / CID 1250335 --- libavcodec/libtwolame.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c index 400985a..ce7c788 100644 --- a/libavcodec/libtwolame.c +++ b/libavcodec/libtwolame.c @@ -100,7 +100,7 @@ static int twolame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { TWOLAMEContext *s = avctx->priv_data; - int ret; + int ret, samples; if ((ret = ff_alloc_packet(avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0) return ret; @@ -148,13 +148,16 @@ static int twolame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (ret < 0) // twolame error return AVERROR_UNKNOWN; - avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); if (frame) { if (frame->pts != AV_NOPTS_VALUE) avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding); + samples = frame->nb_samples; } else { avpkt->pts = s->next_pts; + samples = 0; } + avpkt->duration = ff_samples_to_time_base(avctx, samples); +
Why not just move the statement into the if(frame) branch? We don't need to set the duration otherwise, it's initialized to 0 by av_init_packet (called via av_new_packet, via ff_alloc_packet).
// Martin _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
