This is more robust.
And only check if there is actually a frame returned.
Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
This is necessary, because avcodec_decode_video2 can change
width, height and/or pixel format of the AVCodecContext. Since
video_dst_data and video_dst_linesize are not updated by calling
av_image_alloc again, av_image_copy[_plane] asserts, because the
destination buffer is too small.
In this case, creating a useable rawvideo is not possible anyway, since
it has fixed width/height/pix_fmt.
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
The open_codec_context function, when it fails to find a codec, now
return AVERROR(EINVAL) to signal an error.
Before it would return the stream index, which was always >= 0, and
continue as if a codec was found. This change make it fail faster,
instead of repeated failed tries to decode frames with no codec.
Signed-off-by: Even Wiik Thomassen <e.thomassen@sportradar.com>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
There is no reason why this should copy the audio data in a very
complicated way. Also, strictly write the first plane, instead of
writing the whole buffer. This is more helpful in context of the
example. This way a user can clearly confirm that it works by playing
the written data as raw audio.
This assumes one audio packet is decoded one time. This is not true:
packets can be partially decoded. Then you have to "adjust" the packet
and pass the undecoded part of the packet to the decode function again.