[FFmpeg-trac] #576(swscale:new): sws_scale crash with PIX_FMT_YUVJ420P -> PIX_FMT_RGB24
FFmpeg
trac at avcodec.org
Thu Oct 27 22:35:42 CEST 2011
#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 |
------------------------------------+-----------------------------------
Comment (by rich99):
Just to make sure, this is the final code, also attached as cpp.
{{{
#define __STDC_CONSTANT_MACROS
extern "C"
{
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
}
int main(int argc, char *argv[])
{
av_register_all();
AVFormatContext* pFormatCtx;
if (argc == 2)
{
av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL);
}
else
{
printf("need filename\n");
return -1;
}
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_YUV420P;
// 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:6>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list