[FFmpeg-devel] [PATCH] opus/matroska: Adding support for End Trimming in demuxer/decoder

Michael Niedermayer michaelni at gmx.at
Tue Sep 10 01:44:39 CEST 2013


On Fri, Aug 30, 2013 at 11:25:12AM -0700, Vignesh Venkatasubramanian wrote:
> Implementing support for end trimming Opus in Matroska by making
> use of the DiscardPadding value from the container and discarding
> the samples accordingly. With this patch and its companion muxer
> patch, we can ensure number of samples in == number of samples out
> for Opus in Matroska.
> 
> Signed-off-by: Vignesh Venkatasubramanian <vigneshv at google.com>
> ---

>  libavcodec/utils.c        | 21 +++++++++++++++++++++
>  libavformat/matroskadec.c | 30 +++++++++++++++++++++++++-----

these 2 belong in seperate patches, the utils changes make sense on
their own without the matroska changes



>  2 files changed, 46 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 0be9340..477a1a1 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2111,6 +2111,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
>      if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
>          uint8_t *side;
>          int side_size;
> +        uint32_t discard_padding = 0;
>          // copy to ensure we do not change avpkt
>          AVPacket tmp = *avpkt;
>          int did_split = av_packet_split_side_data(&tmp);
> @@ -2145,6 +2146,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
>              avctx->internal->skip_samples = AV_RL32(side);
>              av_log(avctx, AV_LOG_DEBUG, "skip %d samples due to side data\n",
>                     avctx->internal->skip_samples);
> +            discard_padding = AV_RL32(side + 4);
>          }
>          if (avctx->internal->skip_samples && *got_frame_ptr) {
>              if(frame->nb_samples <= avctx->internal->skip_samples){
> @@ -2175,6 +2177,25 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
>              }
>          }
>  
> +        if (discard_padding > 0 && *got_frame_ptr) {
> +            if (discard_padding == frame->nb_samples) {
> +                *got_frame_ptr = 0;
> +            } else {
> +                if(avctx->pkt_timebase.num && avctx->sample_rate) {
> +                    int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
> +                                                   (AVRational){1, avctx->sample_rate},
> +                                                   avctx->pkt_timebase);
> +                    if (av_frame_get_pkt_duration(frame) >= diff_ts)
> +                        av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts);
> +                } else {
> +                    av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
> +                }
> +                av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
> +                       discard_padding, frame->nb_samples);
> +                frame->nb_samples -= discard_padding;

use of untrusted and unchecked values for changing array dimensions

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130910/94b2ed3e/attachment.asc>


More information about the ffmpeg-devel mailing list