2

I'm trying to show live feed from a webcam and, at the same time, record the video and audio to a video file. I'm not sure I'm doing things correctly. I tried to use melt code as a way to start. One of the problems is the feed is very delayed (I'd actually like that be a choice for the users, x seconds of delay or no delay). The second is when I close the consumer the program basically crashes, the webcam never closes and ffmpeg prints the following lines on the console (non-stop)

[dshow @ 16edf960] real-time buffer [Integrated Camera] [video input]
too full or near too full (121% of size: 3041280 [rtbufsize
parameter])! frame dropped!

I am using QT for my interface and rest of the program. My code is as follows:

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");
}

If I try to just show the feed (m_consumer = new Mlt::Consumer(*m_profile, "sdl_preview");) the delay is still there but I can normally close it. Same for just recording (m_consumer = new Mlt::Consumer(*m_profile, "avformat:out.mp4");). It closes normally and the file works. I also tried two consumers for one producer and, despite a lot of artifacts and missing sound, it works and I can close the file and camera. But it doesn't seem it behaves very well with two consumers for one producer.

Is this a matter of settings? Or is a limitation of the mlt?

Solidus
  • 698
  • 1
  • 9
  • 23

0 Answers0