arrays - 将 AVPicture 转换为数组<unsigned char>

标签 arrays ffmpeg c++-cli

我使用 ffmpeg 在 C++ 中提取视频帧。我想得到array<unsigned char> c++ 中的框架,但我得到 AVFrame从这一行代码。

avcodec_decode_video2(codecContext, DecodedFrame, &gotPicture, Packet);

所以我用sws_scale转换 AVFrameAVPicture但我也得不到array<unsigned char>从帧。
sws_scale(convertContext, DecodedFrame->data, DecodedFrame->linesize, 0, (codecContext)->height, convertedFrame->data, convertedFrame->linesize);

所以谁能帮我转换AVFrameAVPicturearray<unsigned char> ?

最佳答案

AVPicture已弃用。转换成它是没有意义的,因为 AVFrame是它的替代品。

如果我正确理解了这个问题,您正在尝试将原始图片像素值设置为 std::array .如果是这样,只需转储 data AVFrame 的字段进去。

avcodec_decode_video2(codecContext, DecodedFrame, &gotPicture, Packet);

// If you need rgb, create a swscontext to convert from video pixel format
sws_ctx = sws_getContext(DecodedFrame->width, DecodedFrame->height, codecContext->pix_fmt, DecodedFrame->width, DecodedFrame->height, AV_PIX_FMT_RGB24, 0, 0, 0, 0);

uint8_t* rgb_data[4];  int rgb_linesize[4];
av_image_alloc(rgb_data, rgb_linesize, DecodedFrame->width, DecodedFrame->height, AV_PIX_FMT_RGB24, 32); 
sws_scale(sws_ctx, DecodedFrame->data, DecodedFrame->linesize, 0, DecodedFrame->height, rgb_data, rgb_linesize);

// RGB24 is a packed format. It means there is only one plane and all data in it. 
size_t rgb_size = DecodedFrame->width * DecodedFrame->height * 3;
std::array<uint8_t, rgb_size> rgb_arr;
std::copy_n(rgb_data[0], rgb_size, rgb_arr);

关于arrays - 将 AVPicture 转换为数组<unsigned char>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40233362/

相关文章:

JAVA不进入for循环

c++ - 如何将文件中的值输入到矩阵中?

visual-c++ - 如何解码全速率 GSM 音频文件?

c# - 从 native C++ 或 C 调用 C# 函数

php - PHP 中的数组搜索问题

arrays - 如果元素包含相同的字母,ruby 创建子数组

python - 有没有办法通过ffmpeg中的启用功能在最后3秒在视频中添加drawtext过滤器

c++ - 我用 Gstreamer MSVC 1.16.1 构建 opencv 3.4,现在 imread 和 VideoCapture 不起作用

c++-cli - 将 C++/CLI 中的 int 数组返回到 c# .NET

visual-studio-2010 - 你如何将 'System::String ^' 转换为 'TCHAR' ?