我想使用c ++代码从位图图像制作.avi视频文件.我写了以下代码:
//Get RGB array data from bmp file
uint8_t* rgb24Data = new uint8_t[3*imgWidth*imgHeight];
hBitmap = (HBITMAP) LoadImage( NULL, _T("myfile.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
GetDIBits(hdc, hBitmap, 0, imgHeight, rgb24Data , (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
/* Allocate the encoded raw picture. */
AVPicture dst_picture;
avpicture_alloc(&dst_picture, AV_PIX_FMT_YUV420P, imgWidth, imgHeight);
/* Convert rgb24Data to YUV420p and stored into array dst_picture.data */
RGB24toYUV420P(imgWidth, imgHeight, rgb24Data, dst_picture.data); //How to implement this function?
//code for encode frame dst_picture here
Run Code Online (Sandbox Code Playgroud)
我的问题是如何实现RGB24toYUV420P()函数,这个函数会将RGB24数据从数组rgb24Data 转换为YUV420p存储到dst_picture.data …
我正在尝试使用C++在虚幻引擎4中编码视频.我可以访问单独的框架.下面是读取viewport's显示像素并存储在缓冲区中的代码.
//Safely get render target resource.
FRenderTarget* RenderTarget = TextureRenderTarget->GameThread_GetRenderTargetResource();
FIntPoint Size = RenderTarget->GetSizeXY();
auto ImageBytes = Size.X* Size.Y * static_cast<int32>(sizeof(FColor));
TArray<uint8> RawData;
RawData.AddUninitialized(ImageBytes);
//Get image raw data.
if (!RenderTarget->ReadPixelsPtr((FColor*)RawData.GetData()))
{
RawData.Empty();
UE_LOG(ExportRenderTargetBPFLibrary, Error, TEXT("ExportRenderTargetAsImage: Failed to get raw data."));
return false;
}
Buffer::getInstance().add(RawData);
Run Code Online (Sandbox Code Playgroud)
虚幻引擎IImageWrapperModule可以从帧中获取图像,但注意到视频编码.我想要的是实时编码帧以用于直播服务.
我发现这篇文章使用FFMPEG将屏幕截图编码到一个视频中,这是我想要的,但我在为我的情况调整此解决方案时遇到了问题.代码已过时(例如,avcodec_encode_video更改为avcodec_encode_video2使用不同的参数).
贝娄是编码器的代码.
void Compressor::DoWork()
{
AVCodec* codec;
AVCodecContext* c = NULL;
//uint8_t* outbuf;
//int /*i, out_size,*/ outbuf_size;
UE_LOG(LogTemp, Warning, TEXT("encoding"));
codec = avcodec_find_encoder(AV_CODEC_ID_MPEG1VIDEO); …Run Code Online (Sandbox Code Playgroud)