Desidero convertire l'immagine YUV420P
(ricevuta dallo streaming H.264
) a RGB
, ridimensionandola, utilizzando sws_scale
.
La dimensione dell'immagine originale è 480 × 800
. La semplice conversione con le stesse dimensioni funziona bene.
Ma quando provo a cambiare le dimensioni, ottengo un'immagine distorta, con il seguente schema:sws_scale YUV -> RGB immagine distorta
- cambiando
481 × 800
produrrà un'immagine W B & distorta che sembra è tagliato a metà 482 × 800
sarà ancora più distorta483 × 800
è distorto ma a colori484 × 800
è ok (in scala correttamente).
Ora questo modello segue - il ridimensionamento sarà solo funzionare bene se la differenza tra divide per 4.
Ecco un codice di esempio del modo in cui ho decodificare e convertire l'immagine. Tutti i metodi mostrano "successo".
int srcX = 480;
int srcY = 800;
int dstX = 481; // or 482, 483 etc
int dstY = 800;
AVFrame* avFrameYUV = avcodec_alloc_frame();
avpicture_fill((AVPicture *)avFrameYUV, decoded_yuv_frame, PIX_FMT_YUV420P, srcX , srcY);
AVFrame *avFrameRGB = avcodec_alloc_frame();
AVPacket avPacket;
av_init_packet(&avPacket);
avPacket.size = read; // size of raw data
avPacket.data = raw_data; // raw data before decoding to YUV
int frame_decoded = 0;
int decoded_length = avcodec_decode_video2(g_avCodecContext, avFrameYUV, &frame_decoded, &avPacket);
int size = dstX * dstY * 3;
struct SwsContext *img_convert_ctx = sws_getContext(srcX, srcY, SOURCE_FORMAT, dstX, dstY, PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL);
avpicture_fill((AVPicture *)avFrameRGB, rgb_frame, PIX_FMT_RGB24, dstX, dstY);
sws_scale(img_convert_ctx, avFrameYUV->data, avFrameYUV->linesize, 0, srcY, avFrameRGB->data, avFrameRGB->linesize);
// draws the resulting frame with windows BitBlt
DrawBitmap(hdc, dstX, dstY, rgb_frame, size);
sws_freeContext(img_convert_ctx);
In sws_getContext() funzione che si sta passando come parametro il formato identificatore PIX_FMT_BGR24 invece di PIX_FMT_RGB24 come si fa in avpicture_fill –
sentitevi liberi di inviare un bug a https://ffmpeg.org/trac/ffmpeg/newticket –
Hai mai farlo funzionare? – sendmoreinfo