[FFmpeg-devel] i am going to resize one frame with sws_scale() function.
KyungJoon
withhoin
Wed Apr 15 09:52:47 CEST 2009
Hello...
I hope to resize the frame with sws_scale() function.
but i did get green pixel data. i hope to show example source.
my written by belong source...
int nConvertWidth = 320;
int nConvertHeight = 240;
pInFileCtx = av_alloc_format_context();
set_context_opts(pInFileCtx, avformat_opts, AV_OPT_FLAG_DECODING_PARAM);
if (av_open_input_file(&pInFileCtx, pszFilePath, NULL, 0, NULL) < 0) return
-1;
if( av_find_stream_info(pInFileCtx)<0 ) return -1;
for (nLoopOne = 0; nLoopOne<pInFileCtx->nb_streams; nLoopOne++){
if (pInFileCtx->streams[nLoopOne]->codec->codec_type == CODEC_TYPE_VIDEO){
nVideoStreamIdx = nLoopOne;
break;
}
}
pVidCodecCtx = pInFileCtx->streams[nVideoStreamIdx]->codec;
pVidCodec =
avcodec_find_decoder(pInFileCtx->streams[nVideoStreamIdx]->codec->codec_id);
avcodec_open(pVidCodecCtx, pVidCodec);
pFrameBuf = avcodec_alloc_frame();
pRGBFrameBuf = avcodec_alloc_frame();
nRGBFrameSize = avpicture_get_size(PIX_FMT_RGB24, pVidCodecCtx->width,
pVidCodecCtx->height);
pRGBDataBuf = (uint8_t*)malloc(nRGBFrameSize);
avpicture_fill((AVPicture *)pRGBFrameBuf, pRGBDataBuf, PIX_FMT_RGB24,
nConvertWidth, nConvertHeight);
int nCntTemp = 0;
int nRet;
while (av_read_frame(pInFileCtx, &stPkt)>=0)
{
if (stPkt.stream_index == nVideoStreamIdx)
{
avcodec_decode_video(pVidCodecCtx, pFrameBuf, &nGotPicture, stPkt.data,
stPkt.size);
if (nGotPicture)
{
static int sws_flags = SWS_BICUBIC;
struct SwsContext *img_convert_ctx;
img_convert_ctx = sws_getContext(pVidCodecCtx->width,
pVidCodecCtx->height, pVidCodecCtx->pix_fmt, nConvertWidth, nConvertHeight,
PIX_FMT_RGB24, sws_flags, NULL, NULL, NULL);
nRet = sws_scale(img_convert_ctx, pFrameBuf->data, pFrameBuf->linesize,
0, pVidCodecCtx->height, pRGBFrameBuf->data, pRGBFrameBuf->linesize);
//sws_freeContext(img_convert_ctx);
////img_convert((AVPicture*)pRGBFrameBuf, PIX_FMT_RGB24,
(AVPicture*)pYUVFrameBuf, PIX_FMT_YUV420P, nConvertWidth, nConvertHeight);
if (nCntTemp++<5){
ffmpeg_Util_SaveFrame(pRGBFrameBuf, nConvertWidth, nConvertHeight);
}
else
{
break;
}
}
}
}
More information about the ffmpeg-devel
mailing list