diff mbox

[FFmpeg-devel] avcodec/utils: do not reallocate packet buffer for AV_CODEC_ID_WRAPPED_AVFRAME

Message ID 20170219010040.15581-1-cus@passwd.hu
State Superseded
Headers show

Commit Message

Marton Balint Feb. 19, 2017, 1 a.m. UTC
Reallocating a wrapped avframe invalidates internal pointers, such as extended
data.

FFmpeg has another way of passing AVFrames to muxers, but it seems the API
(av_write_uncoded_frame) is not implemented in the ffmpeg CLI yet.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavcodec/utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Hendrik Leppkes Feb. 19, 2017, 6:22 a.m. UTC | #1
On Sun, Feb 19, 2017 at 2:00 AM, Marton Balint <cus@passwd.hu> wrote:
> Reallocating a wrapped avframe invalidates internal pointers, such as extended
> data.
>
> FFmpeg has another way of passing AVFrames to muxers, but it seems the API
> (av_write_uncoded_frame) is not implemented in the ffmpeg CLI yet.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavcodec/utils.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index f4085bf..d09384a 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1926,7 +1926,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
>      }
>
>      if (!ret) {
> -        if (needs_realloc && avpkt->data) {
> +        if (needs_realloc && avpkt->data && avctx->codec_id != AV_CODEC_ID_WRAPPED_AVFRAME) {
>              ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
>              if (ret >= 0)
>                  avpkt->data = avpkt->buf->data;
> @@ -2027,7 +2027,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
>          else if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
>              avpkt->pts = avpkt->dts = frame->pts;
>
> -        if (needs_realloc && avpkt->data) {
> +        if (needs_realloc && avpkt->data && avctx->codec_id != AV_CODEC_ID_WRAPPED_AVFRAME) {
>              ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
>              if (ret >= 0)
>                  avpkt->data = avpkt->buf->data;
> --
> 2.10.2

Maybe this condition should be placed on the top where needs_realloc
is defined, so its never 1 in the first place?

- Hendrik
diff mbox

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index f4085bf..d09384a 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1926,7 +1926,7 @@  int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
     }
 
     if (!ret) {
-        if (needs_realloc && avpkt->data) {
+        if (needs_realloc && avpkt->data && avctx->codec_id != AV_CODEC_ID_WRAPPED_AVFRAME) {
             ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
             if (ret >= 0)
                 avpkt->data = avpkt->buf->data;
@@ -2027,7 +2027,7 @@  int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
         else if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
             avpkt->pts = avpkt->dts = frame->pts;
 
-        if (needs_realloc && avpkt->data) {
+        if (needs_realloc && avpkt->data && avctx->codec_id != AV_CODEC_ID_WRAPPED_AVFRAME) {
             ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
             if (ret >= 0)
                 avpkt->data = avpkt->buf->data;