#576: sws_scale crash with PIX_FMT_YUVJ420P -> PIX_FMT_RGB24 ------------------------------------+----------------------------------- Reporter: rich99 | Owner: michael Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | ------------------------------------+----------------------------------- Description changed by cehoyos:
Old description: > Last ffmpeg built from git, 10/20/2011 10:22:50AM. > > Win7 x64, VS2010, built using migGW and msys, gcc 4.5.2. > > Build options: > ./configure --enable-shared --disable-static --enable-memalign-hack > --target-os=mingw32 --arch=i686 --cpu=i686 --enable-avisynth --enable- > zlib --enable-bzlib --enable-pthreads --enable-runtime-cpudetect > --disable-encoders --enable-swscale --extra-cflags=-U__STRICT_ANSI__ > > Everything works fine with playback except some crashes when using > sws_scale and certain video files. Here is an example that always crashes > with a sample code provided. I have stripped all checks to simplify the > code to the maximum. The sample video is also attached. If I don't use > sws_scale, everything works fine. > > main.cpp > --------------------------------- > #define __STDC_CONSTANT_MACROS > #pragma warning(disable:4244) > > extern "C" > { > #include <stdint.h> > #include <inttypes.h> > > #include "libavformat/avformat.h" > #include "libswscale/swscale.h" > #include "libavcodec/avcodec.h" > #include <libavutil/opt.h> > } > > int main() > { > av_register_all(); > > AVFormatContext* pFormatCtx; > av_open_input_file(&pFormatCtx, "ffdmjpeg.avi", NULL, 0, NULL); > av_find_stream_info(pFormatCtx); > dump_format(pFormatCtx, 0, "test", 0); > > AVCodecContext* pCodecCtx; > > // i know first stream is at index 0, simplified here > unsigned int videoStream = 0; > pCodecCtx = pFormatCtx->streams[videoStream]->codec; > > AVCodec* pCodec = avcodec_find_decoder(pCodecCtx->codec_id); > avcodec_open(pCodecCtx, pCodec); > > AVFrame* pFrame = avcodec_alloc_frame(); > AVFrame* pFrameRGB = avcodec_alloc_frame(); > > PixelFormat destFormat = PIX_FMT_RGB24; > > // Determine required buffer size and allocate buffer > int numBytes = avpicture_get_size(destFormat, pCodecCtx->width, > pCodecCtx->height); > uint8_t* buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t)); > avpicture_fill((AVPicture *)pFrameRGB, buffer, destFormat, > pCodecCtx->width, pCodecCtx->height); > > int frameFinished; > AVPacket packet; > > SwsContext* swsContext = sws_alloc_context(); > //AVOption options; > av_opt_set_defaults(swsContext); > av_set_int(swsContext, "sws_flags", SWS_POINT); > av_set_int(swsContext, "srcw", pCodecCtx->width); > av_set_int(swsContext, "srch", pCodecCtx->height); > av_set_int(swsContext, "dstw", pCodecCtx->width); > av_set_int(swsContext, "dsth", pCodecCtx->height); > av_set_int(swsContext, "src_format", pCodecCtx->pix_fmt); > av_set_int(swsContext, "dst_format", destFormat); > av_set_int(swsContext, "src_range", 1); > av_set_int(swsContext, "dst_range", 1); > > sws_init_context(swsContext, NULL, NULL); //success > > while(av_read_frame(pFormatCtx, &packet) >= 0) > { > // Is this a packet from the video stream? > if(packet.stream_index == videoStream) > { > // Decode video frame > avcodec_decode_video2(pCodecCtx, pFrame, > &frameFinished, &packet); > > // Did we get a video frame? > if(frameFinished) > { > AVPicture &pic = > *(AVPicture*)pFrame; > AVPicture &picDst = > *(AVPicture*)pFrameRGB; > // [CRASH HERE] > sws_scale(swsContext, > &pic.data[0], &pic.linesize[0], 0, pCodecCtx->height, &picDst.data[0], > &picDst.linesize[0]); > // > printf("."); > } > } > > // Free the packet that was allocated by av_read_frame > av_free_packet(&packet); > } > > av_free(buffer); > av_free(pFrameRGB); > av_free(pFrame); > sws_freeContext(swsContext); > avcodec_close(pCodecCtx); > av_close_input_file(pFormatCtx); > > return 0; > } New description: Last ffmpeg built from git, 10/20/2011 10:22:50AM. Win7 x64, VS2010, built using migGW and msys, gcc 4.5.2. Build options: ./configure --enable-shared --disable-static --enable-memalign-hack --target-os=mingw32 --arch=i686 --cpu=i686 --enable-avisynth --enable-zlib --enable-bzlib --enable-pthreads --enable-runtime-cpudetect --disable- encoders --enable-swscale --extra-cflags=-U__STRICT_ANSI__ Everything works fine with playback except some crashes when using sws_scale and certain video files. Here is an example that always crashes with a sample code provided. I have stripped all checks to simplify the code to the maximum. The sample video is also attached. If I don't use sws_scale, everything works fine. main.cpp {{{ #define __STDC_CONSTANT_MACROS #pragma warning(disable:4244) extern "C" { #include <stdint.h> #include <inttypes.h> #include "libavformat/avformat.h" #include "libswscale/swscale.h" #include "libavcodec/avcodec.h" #include <libavutil/opt.h> } int main() { av_register_all(); AVFormatContext* pFormatCtx; av_open_input_file(&pFormatCtx, "ffdmjpeg.avi", NULL, 0, NULL); av_find_stream_info(pFormatCtx); dump_format(pFormatCtx, 0, "test", 0); AVCodecContext* pCodecCtx; // i know first stream is at index 0, simplified here unsigned int videoStream = 0; pCodecCtx = pFormatCtx->streams[videoStream]->codec; AVCodec* pCodec = avcodec_find_decoder(pCodecCtx->codec_id); avcodec_open(pCodecCtx, pCodec); AVFrame* pFrame = avcodec_alloc_frame(); AVFrame* pFrameRGB = avcodec_alloc_frame(); PixelFormat destFormat = PIX_FMT_RGB24; // Determine required buffer size and allocate buffer int numBytes = avpicture_get_size(destFormat, pCodecCtx->width, pCodecCtx->height); uint8_t* buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t)); avpicture_fill((AVPicture *)pFrameRGB, buffer, destFormat, pCodecCtx->width, pCodecCtx->height); int frameFinished; AVPacket packet; SwsContext* swsContext = sws_alloc_context(); //AVOption options; av_opt_set_defaults(swsContext); av_set_int(swsContext, "sws_flags", SWS_POINT); av_set_int(swsContext, "srcw", pCodecCtx->width); av_set_int(swsContext, "srch", pCodecCtx->height); av_set_int(swsContext, "dstw", pCodecCtx->width); av_set_int(swsContext, "dsth", pCodecCtx->height); av_set_int(swsContext, "src_format", pCodecCtx->pix_fmt); av_set_int(swsContext, "dst_format", destFormat); av_set_int(swsContext, "src_range", 1); av_set_int(swsContext, "dst_range", 1); sws_init_context(swsContext, NULL, NULL); //success while(av_read_frame(pFormatCtx, &packet) >= 0) { // Is this a packet from the video stream? if(packet.stream_index == videoStream) { // Decode video frame avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); // Did we get a video frame? if(frameFinished) { AVPicture &pic = *(AVPicture*)pFrame; AVPicture &picDst = *(AVPicture*)pFrameRGB; // [CRASH HERE] sws_scale(swsContext, &pic.data[0], &pic.linesize[0], 0, pCodecCtx->height, &picDst.data[0], &picDst.linesize[0]); // printf("."); } } // Free the packet that was allocated by av_read_frame av_free_packet(&packet); } av_free(buffer); av_free(pFrameRGB); av_free(pFrame); sws_freeContext(swsContext); avcodec_close(pCodecCtx); av_close_input_file(pFormatCtx); return 0; } }}} -- -- Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/576#comment:5> FFmpeg <http://ffmpeg.org> FFmpeg issue tracker _______________________________________________ FFmpeg-trac mailing list FFmpeg-trac@avcodec.org http://avcodec.org/mailman/listinfo/ffmpeg-trac