- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的目标是将我解码的帧写入文件中。我知道我捕捉得很好,因为它显示在我的 SDL 播放中,并且我随后对其进行编码,没有任何问题。但似乎我无法将框架正确写入文件。这是代码:
#define PIXFMT AV_PIX_FMT_YUV420P
#define WIDTH 1280
#define HEIGHT 720
// initialize SWS context for software scaling
sws_ctx = sws_getContext(pCodecCtx->width,
pCodecCtx->height,
pCodecCtx->pix_fmt,
WIDTH,
HEIGHT,
PIXFMT,
SWS_LANCZOS,
NULL,
NULL,
NULL
);
FfmpegEncoder enc("rtsp://127.0.0.1:1935/live/myStream", pParser);
//SetPixelArray();
i = 0;
enc.FillYuvImage(pFrameRGB, 0, this->pCodecCtx->width, this->pCodecCtx->height);
FILE *pFile;
while (av_read_frame(pFormatCtx, &packet) >= 0 && !exit) {
if (packet.stream_index == videoindex) {
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
if (frameFinished) {
i++;
sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
if (i < 500)
{
pFile = fopen(std::string("./screenshots/screen.yuv").c_str(), "a+");
for (int y = 0; y < pCodecCtx->height; y++)
{
fwrite(pFrame->data[0] + y * pFrame->linesize[0], 1, pCodecCtx->width * pCodecCtx->height, pFile);
fwrite(pFrame->data[1] + y * pFrame->linesize[1], 1, pCodecCtx->width * pCodecCtx->height / 4, pFile);
fwrite(pFrame->data[2] + y * pFrame->linesize[2], 1, pCodecCtx->width * pCodecCtx->height / 4, pFile);
}
fclose(pFile);
}
enc.encodeFrame(pFrameRGB);
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&packet);
}
程序在尝试写入帧时崩溃。
最佳答案
正如我在评论中提到的,您需要检查 fopen 是否成功。
但我认为问题是你写的内容比缓冲区中存在的内容多。我对 yuv 的了解有限。我认为你应该做以下事情。这是基于我对this page中的单帧YUV420图片的理解。 .
abcfor (int y = 0; y < pCodecCtx->height; y++) //plane 0: same width and height
{
fwrite(pFrame->data[0] + y * pFrame->linesize[0], 1, pCodecCtx->width, pFile);
}
for (int y = 0; y < pCodecCtx->height/4; y++) //plane1: Same width and quarter height.
{
fwrite(pFrame->data[1] + y * pFrame->linesize[1], 1, pCodecCtx->width, pFile);
}
for (int y = 0; y < pCodecCtx->height/4; y++) //plane2: Same width and quarter height.
{
fwrite(pFrame->data[2] + y * pFrame->linesize[2], 1, pCodecCtx->width, pFile);
}
请注意,写入顺序取决于颜色格式。我希望您重点关注每次迭代中的循环迭代次数和 fwrite()
中的字节数。
关于无法将 ffmpeg 中的 YUV 帧写入 .yuv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40850403/
例如,我有 4*4 图像。我想分别提取 Y、U 和 V 分量。如果图像是 YUV 422 ,YUV 420 和 YUV444 怎么办。我有兴趣了解数组的结构 Y、U 和 V 如何存储在 422,420
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我无法理解两者之间的确切区别。从研究中,更多地讨论这两者是不同的,但似乎有一些人将它们归为“4 2 2”抽样方案。 YUV 422(I 和 J 版本):“具有一个亮度平面 Y 和 2 个色度平面 U、
我有 10 个 yuv 输入,每个 yuv 都是 WxH 的帧(ip0_WxH.yuv,ip1_WxH.yuv,...,ip9_WxH.yuv) 我需要连接所有 10 个以创建一个包含所有 10 个帧
我的目标是将我解码的帧写入文件中。我知道我捕捉得很好,因为它显示在我的 SDL 播放中,并且我随后对其进行编码,没有任何问题。但似乎我无法将框架正确写入文件。这是代码: #define PIXFMT
我用ffmpeg做HDR测试视频,我的做法是写一张图片,把图片转成yuv420p,然后用ffmpeg做HDR测试视频。 但我发现从 mp4 读取的 yuv 数据与原始输入不同.. 我在这里被困了一段时
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们
我一直在尝试用 C++ 将 YUYV 原始文件转换为 YUV420 原始文件。格式记录在 YUV Formats Page 中.转换后我的输出文件显示为绿色。我采用了来自 Experts Exchan
我正在尝试通过 python 使用 OpenCV 4.1.0 版将平面 YUV 4:2:0 图像转换为 RGB,并且正在努力了解如何格式化数组以传递给 cvtColor 功能。我将所有 3 个 cha
我正在编写一个医疗应用程序,其中有来自 IP 接口(interface)的数据包。其中对像素骨架解码有以下定义。我可以决定在主框架中选择什么来使用不同的像素算法。但我没有正确理解逻辑。 这三种格式是什
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 1年前关闭。 Improve thi
我得到 YUV 到 RGB 函数 1 和 2(来自堆栈溢出) 但是结果是这样的错误http://163.18.62.32/device.jpg 我不明白这一步有什么问题 我的设备是 Moto Mile
我正在使用opencv来实现对象跟踪。我读到 YUV 图像比 RGB 图像更好用。我的问题是,尽管我花了很多时间阅读笔记,但我还是无法理解 YUV 格式。 Y 是亮度,我认为它是根据 R、G、B 分量
我有高清1920x1080 YUV 格式视频。 我想将它们压缩到 640x480和其他转换为其他格式(mp4/avi..) 我使用了以下命令: ffmpeg -f rawvideo -pix_fmt
我正在使用 FFMPEG 从 MXF 视频中提取图像。我有兴趣使用 YUV(最好是 422)颜色空间提取 tiff 格式的图像。 MXF 视频属于 YUV 颜色空间。因此,为什么我想继续在那个色彩空间
我有一个 YUV 文件,我想以 BMP 文件的形式获取每一帧,该怎么做?我可以使用 FFMPEG 和 MPlayer。 最佳答案 您可以使用以下命令: ffmpeg -s widthxheight -
如何从 YUV 视频文件格式中获取信息?我需要了解有关流的信息(例如编解码器、位深度)。使用 ffplay 我可以播放 yuv 视频,但如何获取有关流的信息? 我尝试使用 ffprobe 但它不起作用
我试图将 C++ 程序中生成的数组中的原始 YUV 帧流式传输到使用 FFPEG 的视频。谁能指出我正确的方向? 最佳答案 要将管道 YUV420 平面帧流式传输到 RTMP,请尝试例如 ffmpeg
我有一个要实时流式传输到屏幕的 YUV 数据流(来自视频文件)。 (基本上,我想写一个实时播放视频的程序。) 因此,我正在寻找一种将 YUV 数据发送到屏幕的便携方式。理想情况下,我希望使用可移植的东
我已经通过用 Nvidia 的着色器语言编写的片段着色器实现了 YUV 到 RGB 的转换。 (Y、U 和 V 存储在单独的纹理中,这些纹理通过我的片段着色器中的多纹理组合而成)。它在 OpenGL
我是一名优秀的程序员,十分优秀!