在Qt5中显示FFmpeg帧的最佳/最简单的方法
Best / simplest way to display FFmpeg frames in Qt5
我需要在Qt小部件上显示ffmpeg帧。我知道QtFFmpegWrapper,但它似乎已经过时了。我尝试使用memcpy()
将数据从RGB ffmpeg帧复制到QImage,并在其中遇到未经处理的异常。
QImage lastFrame;
lastFrame = QImage( screen_w, screen_h, QImage::Format_RGB888 );
for( int y = 0; y < screen_h; ++y )
memcpy( lastFrame.scanLine(y),
frameRGB -> data[0] + y * frameRGB -> linesize[0],
screen_w * 3 );
我尝试了sws_getContext()
和sws_getCachedContext()
,AV_PIX_FMT_BGR24
和AV_PIX_FMT_RGB24
ffmpeg处理的所有部分。所有 ffmpeg 代码都来自流行的教程,并且可以很好地与 SDL
和 PIX_FMT_YUV420P
一起使用。
有什么想法吗?也许这不是在Qt小部件上显示ffmpeg帧的最佳/最简单的方法?
编辑。
好的,我将 Murat Şeker 的解决方案与QImage::copy()
一起使用,但现在QImage::isNull()
返回true
。
我的一些 ffmpeg 代码:
out_buffer = (uint8_t*)av_malloc( avpicture_get_size( AV_PIX_FMT_RGB32,
codecCtx -> width, codecCtx -> height ));
avpicture_fill((AVPicture *)frameRGB, out_buffer, AV_PIX_FMT_RGB32,
codecCtx -> width, codecCtx -> height);
img_convert_ctx = sws_getContext( codecCtx -> width, codecCtx -> height,
codecCtx -> pix_fmt, codecCtx -> width,
codecCtx -> height, AV_PIX_FMT_RGB32,
SWS_BICUBIC, NULL, NULL, NULL );
/* ... */
if( got_picture ){
sws_scale( img_convert_ctx, (const uint8_t* const*)frame -> data,
frame -> linesize, 0, codecCtx -> height, frameRGB -> data,
frameRGB -> linesize );
QImage imgFrame = QImage( frameRGB -> data[0], frameRGB -> width,
frameRGB -> height, frameRGB -> linesize[0],
QImage::Format_RGB32 ).copy();
if( imgFrame.isNull()){} // true
// But I can write this frame to hard disk using BITMAPFILEHEADER
SaveBMP( frameRGB, codecCtx -> width, codecCtx -> height ); // it works
}
以下内容对我有用:
QImage frame = QImage(avFrame->data[0], avFrame->width, avFrame->height,
avFrame->linesize[0], QImage::Format_RGB32)
.copy();
相关文章:
- 当无法使用模板和宏时,生成类型变体C++代码的最简单方法是什么?
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 通过比较C++中的行在 txt 文件中搜索的最简单方法是什么?
- 请求最简单的 OpenMP 目标 GPU 示例
- 将时间戳打印到流的最简单方法
- 在C++中创建文件夹选取器对话框的最简单方法是什么?
- C++20 个模块在 clang (Windows):在最简单的示例中键入信息错误
- 对多个(可能)重叠范围进行分区的最简单算法
- 在 cpp 中最简单的图形实现
- boost::variant - 对变体应用算术的最简单方法
- 多线程 gtkmm 应用程序最简单的示例
- 创建可以遍历 std::map 值的通用模板迭代器的最简单方法是什么?
- 在C++中将算术类型转换为 std::array 的最简单方法<uint8_t>
- 标准库容器最简单、性能差的哈希类是什么?
- C++-将ASCII字符数组中可能的数值转换为字符的最简单方法
- 无法获得最简单的JNI足以在Windows 10上运行
- 从 txt 文件中读取数据的最简单方法
- 创建 1 个元素集的最佳最简单最快方法是什么?(C++)
- 如何以最佳、最简单的方式在文件中搜索
- 在Qt5中显示FFmpeg帧的最佳/最简单的方法