我正在尝试显示来自网络摄像头的实时信息,同时将视频和音频录制到视频文件中。我不确定我是否正确地做事。我尝试使用融化代码作为开始的一种方式。问题之一是提要非常延迟(我实际上希望这是用户的选择,延迟 x 秒或不延迟)。第二个是当我关闭消费者时,程序基本上崩溃了,网络摄像头永远不会关闭,ffmpeg 在控制台上打印以下行(不间断)
[dshow @ 16edf960] real-time buffer [Integrated Camera] [video input]
too full or near too full (121% of size: 3041280 [rtbufsize
parameter])! frame dropped!
我将 QT 用于我的界面和程序的其余部分。我的代码如下:
m_profile = new Mlt::Profile(profile);
m_producer = new Mlt::Producer(*m_profile, "dshow:video=Integrated Camera:audio=Microfone interno (Conexant 206");
if (!m_producer->is_valid()) {
// Cleanup on error
error = 1;
delete m_producer;
m_producer = 0;
delete m_profile;
m_profile = 0;
}
else {
m_consumer = new Mlt::Consumer(*m_profile, "multi");
if (m_consumer->is_valid()) {
mlt_properties properties = m_consumer->get_properties();
QWidget* widget = qobject_cast<QWidget*>(parent());
mlt_properties new_props1 = mlt_properties_new();
mlt_properties new_props2 = mlt_properties_new();
mlt_properties_set_data(properties, "0", new_props1, 0, (mlt_destructor) mlt_properties_close, NULL);
mlt_properties_set_data(properties, "1", new_props2, 0, (mlt_destructor) mlt_properties_close, NULL);
mlt_properties_set(new_props1, "mlt_service", "sdl_preview");
mlt_properties_set_int(new_props1, "window_id", (int) widget->winId());
mlt_properties_set_int(new_props1, "audio_off", 1);
mlt_properties_set_int(new_props1, "real_time", 1);
mlt_properties_set(new_props2, "mlt_service", "avformat");
mlt_properties_set(new_props2, "target", "out.mp4");
mlt_properties_set_int(new_props2, "terminate_on_pause", 0);
mlt_properties_set_int(new_props2, "real_time", 1);
m_consumer->connect(*m_producer);
//Make an event handler for when a frame's image should be displayed
m_consumer->listen("consumer-frame-show", this, (mlt_listener)on_frame_show);
m_consumer->start();
m_consumer->debug("Consumer");
m_producer->debug("Producer");
}
如果我尝试只显示提要(m_consumer = new Mlt::Consumer(*m_profile, "sdl_preview");
),延迟仍然存在,但我通常可以关闭它。仅录制 ( m_consumer = new Mlt::Consumer(*m_profile, "avformat:out.mp4");
) 也是如此。它正常关闭并且文件工作。我还为一个制作人尝试了两个消费者,尽管有很多伪像和丢失的声音,但它仍然有效,我可以关闭文件和相机。但是对于一个生产者来说,两个消费者的表现似乎不太好。
这是设置的问题吗?或者是mlt的限制?