On Sat, 2010-10-30 at 22:59 +0200, Robert Nagy wrote: > I have a decoded AVFrame which I want to copy using memcpy to user allocated > memory. However, if I don't use swscale it becomes weird, even though both > dest and src pixel formats and sizes are the same. > > What is sws_scale doing that I am not aware of? > > e.g. > double param; > if(!sws_context_) > sws_context_.reset(sws_getContext(width, height, PIX_FMT_BGRA, width, > height, PIX_FMT_BGRA, SWS_BILINEAR, nullptr, nullptr, ¶m), > sws_freeContext); > #ifdef FRAME_DIRECT_COPY > > memcpy(frame->data(), decoded_frame->data[0], width*height*4); // This > should be the same as below? but it's not.
You can't just memcpy() - you need to take the strides into account. > > #else > > // This works just fine > AVFrame av_frame; > avcodec_get_frame_defaults(&av_frame); > avpicture_fill(reinterpret_cast<AVPicture*>(&av_frame), frame->data(), > PIX_FMT_BGRA, width, height); > sws_scale(sws_context_.get(), decoded_frame->data, decoded_frame->linesize, > 0, height, av_frame.data, av_frame.linesize); Just use av_picture_copy() and change av_frame to be an AVPicture. The reason it works with avpicture_fill() is because it sets up the AVPicture in a "tightly packet" manner, meaning each stride is equal to width*bytes_per_pixel. Finally, you can also use avpicture_layout() if you just need to data packed into that flat buffer and don't need an AVPicture/AVFrame. /Tomas
signature.asc
Description: This is a digitally signed message part
_______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
