gpt4 book ai didi

c++ - X264编码使用Opencv

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:59:24 24 4
gpt4 key购买 nike

我正在使用高分辨率相机:4008x2672。我正在编写一个简单的程序,它从相机中抓取帧并将帧发送到 avi 文件。对于如此高分辨率的工作,我发现只有 x264 编解码器可以做到这一点(欢迎提出建议)。我将 opencv 用于大多数图像处理内容。正如这篇文章中提到的 http://doom10.org/index.php?topic=1019.0 ,我根据 libx264 的 ffmpeg 预设修改了 AVCodecContext 成员(必须这样做以避免破坏 ffmpeg 默认设置错误)。这是我尝试运行程序时得到的输出

libx264 @ 0x992d040]non-strictly-monotonic PTS 
1294846981.526675 1 0 //Timestamp camera_no frame_no
1294846981.621101 1 1
1294846981.715521 1 2
1294846981.809939 1 3
1294846981.904360 1 4
1294846981.998782 1 5
1294846982.093203 1 6
Last message repeated 7 times
[avi @ 0x992beb0]st:0 error, non monotone timestamps
-614891469123651720 >= -614891469123651720

OpenCV Error: Unspecified error (Error while writing video frame) in
icv_av_write_frame_FFMPEG, file
/home/ajoshi/ext/OpenCV-2.2.0/modules/highgui/src/cap_ffmpeg.cpp, line 1034
terminate called after throwing an instance of 'cv::Exception'
what(): /home/ajoshi/ext/OpenCV-2.2.0/modules/highgui/src/cap_ffmpeg.cpp:1034:
error: (-2) Error while writing video frame in function icv_av_write_frame_FFMPEG

中止

对 AVCodecContext 的修改是:

if(codec_id == CODEC_ID_H264)
{
//fprintf(stderr, "Trying to parse a preset file for libx264\n");
//Setting Values manually from medium preset
c->me_method = 7;
c->qcompress=0.6;
c->qmin = 10;
c->qmax = 51;
c->max_qdiff = 4;
c->i_quant_factor=0.71;
c->max_b_frames=3;
c->b_frame_strategy = 1;
c->me_range = 16;<br>
c->me_subpel_quality=7;
c->coder_type = 1;
c->scenechange_threshold=40;
c->partitions = X264_PART_I8X8 | X264_PART_I4X4 | X264_PART_P8X8 | X264_PART_B8X8;
c->flags = CODEC_FLAG_LOOP_FILTER;
c->flags2 = CODEC_FLAG2_BPYRAMID | CODEC_FLAG2_MIXED_REFS | CODEC_FLAG2_WPRED | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP;
c->keyint_min = 25;
c->refs = 3;
c->trellis=1;
c->directpred = 1;
c->weighted_p_pred=2;
}

我可能没有设置我认为 ffmpeg 应该为我设置的 dts 和 pts 值。

欢迎提出任何建议。
提前致谢

最佳答案

我可能会在另一个进程中运行 x264 可执行文件,并将 rgb 或 yuv 像素通过管道传输给它。然后您可以使用所有正常的 x264(或 ffmpeg)标志,它会为您处理多线程。

而且由于 x264 是 GPL 许可的,它还让您在许可您的应用程序方面拥有更多自由。

附言。这是一些使用 ffmpeg from Qt 的示例代码您可以忽略 Qt 特定位,但它为从 C++ 应用程序使用 ffmpeg 提供了一个很好的起点。

关于c++ - X264编码使用Opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4672727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com