[FFmpeg-devel] [PATCH] examples/demuxing_decoding: use correct size of video_dst_data[0]

wm4 nfxjfg at googlemail.com
Tue May 12 11:17:21 CEST 2015


On Mon, 11 May 2015 23:34:32 +0200
Andreas Cadhalpun <andreas.cadhalpun at googlemail.com> wrote:

> Currently video_dst_bufsize is used, which is set to the return value
> of av_image_alloc, but this is the combined size of all planes.
> Only the first plane is written in fwrite.
> 
> The size of the first plane is the product of video_dst_linesize[0] and
> height.
> 
> This fixes 'Syscall param write(buf) points to uninitialised byte(s)'
> valgrind warnings.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
> ---
>  doc/examples/demuxing_decoding.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/doc/examples/demuxing_decoding.c b/doc/examples/demuxing_decoding.c
> index feeeb96..81c8a92 100644
> --- a/doc/examples/demuxing_decoding.c
> +++ b/doc/examples/demuxing_decoding.c
> @@ -47,7 +47,6 @@ static FILE *audio_dst_file = NULL;
>  
>  static uint8_t *video_dst_data[4] = {NULL};
>  static int      video_dst_linesize[4];
> -static int video_dst_bufsize;
>  
>  static int video_stream_idx = -1, audio_stream_idx = -1;
>  static AVFrame *frame = NULL;
> @@ -109,7 +108,7 @@ static int decode_packet(int *got_frame, int cached)
>                            pix_fmt, width, height);
>  
>              /* write to rawvideo file */
> -            fwrite(video_dst_data[0], 1, video_dst_bufsize, video_dst_file);
> +            fwrite(video_dst_data[0], 1, video_dst_linesize[0] * height, video_dst_file);

This would still write the line padding to the file, wouldn't it? This
means it wouldn't write the full frame, _and_ each line would have
garbage at the end of it.

(Also I can't make sense of these examples...)

>          }
>      } else if (pkt.stream_index == audio_stream_idx) {
>          /* decode audio frame */
> @@ -290,7 +289,6 @@ int main (int argc, char **argv)
>              fprintf(stderr, "Could not allocate raw video buffer\n");
>              goto end;
>          }
> -        video_dst_bufsize = ret;
>      }
>  
>      if (open_codec_context(&audio_stream_idx, fmt_ctx, AVMEDIA_TYPE_AUDIO) >= 0) {



More information about the ffmpeg-devel mailing list