示例#1
0
void BinController::duplicateFilters(Mlt::Producer original, Mlt::Producer clone)
{
    Mlt::Service clipService(original.get_service());
    Mlt::Service dupService(clone.get_service());
    //delete original;
    //delete clone;
    int ct = 0;
    Mlt::Filter *filter = clipService.filter(ct);
    while (filter) {
        // Only duplicate Kdenlive filters, and skip the fade in effects
        //fprintf(stderr, "CHKNG FILTER: %s\n", filter->get("kdenlive_id"));
        if (filter->is_valid()/* && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")*/) {
            // looks like there is no easy way to duplicate a filter,
            // so we will create a new one and duplicate its properties
            Mlt::Filter *dup = new Mlt::Filter(*original.profile(), filter->get("mlt_service"));
            if (dup && dup->is_valid()) {
                Mlt::Properties entries(filter->get_properties());
                for (int i = 0; i < entries.count(); ++i) {
                    dup->set(entries.get_name(i), entries.get(i));
                }
                dupService.attach(*dup);
            }
        }
        ct++;
        filter = clipService.filter(ct);
    }
}
示例#2
0
Mlt::Producer* JackProducerWidget::newProducer(Mlt::Profile& profile)
{
    Mlt::Producer* p = new Mlt::Producer(profile, "jack:Shotcut");
    p->set(kBackgroundCaptureProperty, 1);
    p->set(kShotcutCaptionProperty, "JACK");
    return p;
}
示例#3
0
bool MltPreview::create(const QString &path, int width, int height, QImage &img)
{
    Mlt::Profile *profile = new Mlt::Profile("dv_pal");
    Mlt::Producer *producer = new Mlt::Producer(*profile, path.toUtf8().data());


    if (producer->is_blank()) {
        delete producer;
        return false;
    }
    int frame = 75;
    uint variance = 10;
    int ct = 1;

    //img = getFrame(producer, frame, width, height);

    while (variance <= 40 && ct < 4) {
        img = getFrame(producer, frame, width, height);
        variance = imageVariance(img);
        frame += 100 * ct;
        ct++;
    }

    delete producer;
    delete profile;
    return (img.isNull() == false);
}
示例#4
0
Mlt::Producer* IsingWidget::producer(Mlt::Profile& profile)
{
    Mlt::Producer* p = new Mlt::Producer(profile, "frei0r.ising0r");
    p->set(kParamTemperature, ui->tempSpinner->text().toLatin1().constData());
    p->set(kParamBorderGrowth, ui->borderGrowthSpinner->text().toLatin1().constData());
    p->set(kParamSpontaneous, ui->spontGrowthSpinner->text().toLatin1().constData());
    return p;
}
示例#5
0
Mlt::Producer* DecklinkProducerWidget::producer(Mlt::Profile& profile)
{
    Mlt::Producer* p = new Mlt::Producer(profile,
        QString("consumer:decklink:%1").arg(ui->deviceCombo->currentIndex()).toAscii().constData());
    if (p->is_valid())
        p->set("profile", ui->profileCombo->itemData(ui->profileCombo->currentIndex()).toString().toAscii().constData());
    return p;
}
示例#6
0
void TimelineDock::selectTrackHead(int trackIndex)
{
    if (trackIndex >= 0) {
        int i = m_model.trackList().at(trackIndex).mlt_index;
        Mlt::Producer* producer = m_model.tractor()->track(i);
        if (producer && producer->is_valid())
            emit trackSelected(producer);
        delete producer;
    }
}
void ImageProducerWidget::on_durationSpinBox_editingFinished()
{
    if (!m_producer)
        return;
    if (ui->durationSpinBox->value() == m_producer->get_out() + 1)
        return;
    Mlt::Producer* p = producer(MLT.profile());
    p->pass_list(*m_producer, "force_aspect_ratio, shotcut_aspect_num, shotcut_aspect_den,"
        "shotcut_resource, resource, ttl, shotcut_sequence");
    reopen(p);
}
示例#8
0
void TimelineDock::openClip(int trackIndex, int clipIndex)
{
    Q_ASSERT(trackIndex >= 0 && clipIndex >= 0);
    QScopedPointer<Mlt::ClipInfo> info(getClipInfo(trackIndex, clipIndex));
    if (info) {
        QString xml = MLT.XML(info->producer);
        Mlt::Producer* p = new Mlt::Producer(MLT.profile(), "xml-string", xml.toUtf8().constData());
        p->set_in_and_out(info->frame_in, info->frame_out);
        emit clipOpened(p);
    }
}
示例#9
0
void ClearCommand::undo()
{
    m_model.close();
    Mlt::Producer* producer = new Mlt::Producer(MLT.profile(), "xml-string", m_xml.toUtf8().constData());
    if (producer->is_valid()) {
        producer->set("resource", "<playlist>");
        MAIN.open(producer);
        MLT.pause();
        MAIN.seekPlaylist(0);
    }
}
示例#10
0
Mlt::Producer* PlasmaWidget::producer(Mlt::Profile& profile)
{
    Mlt::Producer* p = new Mlt::Producer(profile, "frei0r.plasma");
    p->set(kParamSpeed1, ui->speed1Spinner->text().toAscii().constData());
    p->set(kParamSpeed2, ui->speed2Spinner->text().toAscii().constData());
    p->set(kParamSpeed3, ui->speed3Spinner->text().toAscii().constData());
    p->set(kParamSpeed4, ui->speed4Spinner->text().toAscii().constData());
    p->set(kParamMove1, ui->move1Spinner->text().toAscii().constData());
    p->set(kParamMove2, ui->move2Spinner->text().toAscii().constData());
    return p;
}
示例#11
0
QMimeData *PlaylistModel::mimeData(const QModelIndexList &indexes) const
{
    QMimeData *mimeData = new QMimeData;
    Mlt::ClipInfo* info = m_playlist->clip_info(indexes.first().row());
    if (info) {
        Mlt::Producer* producer = info->producer;
        producer->set_in_and_out(info->frame_in, info->frame_out);
        mimeData->setData(Mlt::XmlMimeType, MLT.saveXML("string", producer).toUtf8());
        producer->set_in_and_out(0, -1);
        delete info;
    }
    return mimeData;
}
示例#12
0
QString ThumbnailProvider::cacheKey(Mlt::Producer& producer, int frameNumber)
{
    QString time = producer.frames_to_time(frameNumber, mlt_time_clock);
    // Reduce the precision to centiseconds to increase chance for cache hit
    // without much loss of accuracy.
    time = time.left(time.size() - 1);
    QString key = QString("%1 %2")
            .arg(producer.get("resource"))
            .arg(time);
    QCryptographicHash hash(QCryptographicHash::Sha1);
    hash.addData(key.toUtf8());
    return hash.result().toHex();
}
void ImageProducerWidget::on_sequenceCheckBox_clicked(bool checked)
{
    QString resource = m_producer->get("resource");
    ui->repeatSpinBox->setEnabled(checked);
    if (checked && !m_producer->get(kShotcutResourceProperty))
        m_producer->set(kShotcutResourceProperty, resource.toUtf8().constData());
    m_producer->set(kShotcutSequenceProperty, checked);
    m_producer->set("ttl", ui->repeatSpinBox->value());
    if (checked) {
        QFileInfo info(resource);
        QString name(info.fileName());
        QString begin = "";
        int i = name.length();
        int count = 0;

        // find the last numeric digit
        for (; i && !name[i - 1].isDigit(); i--) {};
        // count the digits and build the begin value
        for (; i && name[i - 1].isDigit(); i--, count++)
            begin.prepend(name[i - 1]);
        if (count) {
            m_producer->set("begin", begin.toLatin1().constData());
            int j = begin.toInt();
            name.replace(i, count, begin.prepend('%').append('d'));
            resource = info.path() + "/" + name;
            m_producer->set("resource", resource.toUtf8().constData());

            // Count the number of consecutive files.
            MAIN.showStatusMessage(tr("Getting length of image sequence..."));
            name = info.fileName();
            name.replace(i, count, "%1");
            resource = info.path().append('/').append(name);
            for (i = j; QFile::exists(resource.arg(i, count, 10, QChar('0'))); ++i);
            i -= j;
            m_producer->set("length", i);
            ui->durationSpinBox->setValue(i);
            MAIN.showStatusMessage(tr("Reloading image sequence..."));
        }
    }
    else {
        m_producer->set("resource", m_producer->get(kShotcutResourceProperty));
        m_producer->set("length", qRound(MLT.profile().fps() * 600));
        ui->durationSpinBox->setValue(qRound(MLT.profile().fps() * Settings.imageDuration()));
    }
    Mlt::Producer* p = producer(MLT.profile());
    p->pass_list(*m_producer, "force_aspect_ratio,"
        kAspectRatioNumerator "," kAspectRatioDenominator ","
        kShotcutResourceProperty ", resource, ttl, length," kShotcutSequenceProperty);
    reopen(p);
}
示例#14
0
Mlt::Producer* AlsaWidget::newProducer(Mlt::Profile& profile)
{
    QString s("alsa:%1");
    if (ui->lineEdit->text().isEmpty())
        s = s.arg("default");
    else
        s = s.arg(ui->lineEdit->text());
    if (ui->alsaChannelsSpinBox->value() > 0)
        s += QString("?channels=%1").arg(ui->alsaChannelsSpinBox->value());
    Mlt::Producer* p = new Mlt::Producer(profile, s.toUtf8().constData());
    p->set(kBackgroundCaptureProperty, 1);
    p->set(kShotcutCaptionProperty, "ALSA");
    return p;
}
示例#15
0
Mlt::Producer *BinController::getBinVideoProducer(const QString &id)
{
    QString videoId = id + "_video";
    if (!m_extraClipList.contains(videoId)) {
        // create clone
        QString originalId = id.section(QStringLiteral("_"), 0, 0);
        Mlt::Producer *original = getBinProducer(originalId);
        Mlt::Producer *videoOnly = cloneProducer(*original);
        videoOnly->set("audio_index", -1);
        videoOnly->set("id", videoId.toUtf8().constData());
        m_extraClipList.insert(videoId, videoOnly);
        return videoOnly;
    }
    return m_extraClipList.value(videoId);
}
示例#16
0
ClipController::ClipController(BinController *bincontroller, Mlt::Producer& producer) : QObject()
    , selectedEffectIndex(1)
    , audioThumbCreated(false)
    , m_properties(new Mlt::Properties(producer.get_properties()))
    , m_usesProxy(false)
    , m_audioInfo(NULL)
    , m_audioIndex(0)
    , m_videoIndex(0)
    , m_clipType(Unknown)
    , m_hasLimitedDuration(true)
    , m_binController(bincontroller)
    , m_snapMarkers(QList < CommentedTime >())
{
    m_masterProducer = &producer;
    if (!m_masterProducer->is_valid()) {
        qDebug()<<"// WARNING, USING INVALID PRODUCER";
        return;
    }
    else {
        QString proxy = m_properties->get("kdenlive:proxy");
        if (proxy.length() > 2) {
            // This is a proxy producer, read original url from kdenlive property
            QString path = m_properties->get("kdenlive:originalurl");
            if (!path.startsWith(QLatin1String("/"))) {
                path.prepend(bincontroller->documentRoot());
            }
            m_url = QUrl::fromLocalFile(path);
            m_usesProxy = true;
        }
        else m_url = QUrl::fromLocalFile(m_properties->get("resource"));
        m_service = m_properties->get("mlt_service");
        getInfoForProducer();
    }
}
示例#17
0
QImage ThumbnailProvider::makeThumbnail(Mlt::Producer &producer, int frameNumber, const QSize& requestedSize)
{
    Mlt::Filter scaler(MLT.profile(), "swscale");
    Mlt::Filter converter(MLT.profile(), "avcolor_space");
    int height = PlaylistModel::THUMBNAIL_HEIGHT * 2;
    int width = height * MLT.profile().dar();

    if (!requestedSize.isEmpty()) {
        width = requestedSize.width();
        height = requestedSize.height();
    }

    producer.attach(scaler);
    producer.attach(converter);
    return MLT.image(producer, frameNumber, width, height);
}
示例#18
0
QString Controller::resource() const
{
    QString resource;
    if (!m_producer)
        return resource;
    resource = QString(m_producer->get("resource"));
    if (m_producer->type() == tractor_type) {
        Mlt::Tractor tractor((mlt_tractor) m_producer->get_service());
        Mlt::Multitrack* multitrack = tractor.multitrack();
        if (multitrack->is_valid()) {
            Mlt::Producer* producer = multitrack->track(0);
            if (producer->is_valid())
                resource = QString(producer->get("resource"));
            delete producer;
        }
        delete multitrack;
    }
    return resource;
}
示例#19
0
Mlt::Producer* ColorBarsWidget::producer(Mlt::Profile& profile)
{
    Mlt::Producer* p = new Mlt::Producer(profile, "frei0r.test_pat_B");
    p->set(kParamType, ui->comboBox->currentIndex());
    if (profile.sample_aspect_num() == 16 && profile.sample_aspect_den() == 15)
        p->set(kParamAspect, map_value_backward(ASPECT_PAL, 0, 6.9999));
    else if (profile.sample_aspect_num() == 64 && profile.sample_aspect_den() == 45)
        p->set(kParamAspect, map_value_backward(ASPECT_PAL_WIDE, 0, 6.9999));
    else if (profile.sample_aspect_num() == 8 && profile.sample_aspect_den() == 9)
        p->set(kParamAspect, map_value_backward(ASPECT_NTSC, 0, 6.9999));
    else if (profile.sample_aspect_num() == 32 && profile.sample_aspect_den() == 27)
        p->set(kParamAspect, map_value_backward(ASPECT_NTSC_WIDE, 0, 6.9999));
    else if (profile.sample_aspect_num() == 4 && profile.sample_aspect_den() == 3)
        p->set(kParamAspect, map_value_backward(ASPECT_HDV, 0, 6.9999));
    p->set(kShotcutCaptionProperty, ui->comboBox->currentText().toUtf8().constData());
    p->set(kShotcutDetailProperty, ui->comboBox->currentText().toUtf8().constData());
    return p;
}
示例#20
0
QString BinController::getProducerXML(Mlt::Producer &producer)
{
    QString filename = QStringLiteral("string");
    Mlt::Consumer c(*producer.profile(), "xml", filename.toUtf8().constData());
    Mlt::Service s(producer.get_service());
    if (!s.is_valid())
        return QLatin1String("");
    int ignore = s.get_int("ignore_points");
    if (ignore)
        s.set("ignore_points", 0);
    c.set("time_format", "frames");
    c.set("no_meta", 1);
    c.set("store", "kdenlive");
    if (filename != QLatin1String("string")) {
        c.set("no_root", 1);
        c.set("root", QFileInfo(filename).absolutePath().toUtf8().constData());
    }
    c.connect(s);
    c.start();
    if (ignore)
        s.set("ignore_points", ignore);
    return QString::fromUtf8(c.get(filename.toUtf8().constData()));
}
示例#21
0
Mlt::Producer* CountProducerWidget::newProducer(Mlt::Profile& profile)
{
    Mlt::Producer* p = new Mlt::Producer(profile, "count:");
    p->set("direction", currentDirection().toLatin1().constData());
    p->set("style", currentStyle().toLatin1().constData());
    p->set("sound", currentSound().toLatin1().constData());
    p->set("background", currentBackground().toLatin1().constData());
    p->set("drop", ui->dropCheckBox->isChecked());
    setLength(p, ui->durationSpinBox->value());
    p->set(kShotcutCaptionProperty, ui->nameLabel->text().toUtf8().constData());
    p->set(kShotcutDetailProperty, detail().toUtf8().constData());
    return p;
}
示例#22
0
void BinController::replaceProducer(const QString &id, Mlt::Producer &producer)
{
    ClipController *ctrl = m_clipList.value(id);
    if (!ctrl) {
        qDebug()<<" / // error controller not found, crashing";
        return;
    }
    pasteEffects(id, producer);
    ctrl->updateProducer(id, &producer);
    replaceBinPlaylistClip(id, producer);
    emit prepareTimelineReplacement(id);
    producer.set("id", id.toUtf8().constData());
    // Remove video only producer
    QString videoId = id + "_video";
    if (m_extraClipList.contains(videoId)) {
        m_extraClipList.remove(videoId);
    }
    removeBinPlaylistClip("#" + id);
    emit replaceTimelineProducer(id);
}
示例#23
0
void ClipController::addMasterProducer(Mlt::Producer &producer)
{
    m_properties = new Mlt::Properties(producer.get_properties());
    m_masterProducer = &producer;
    if (!m_masterProducer->is_valid()) qDebug()<<"// WARNING, USING INVALID PRODUCER";
    else {
        QString proxy = m_properties->get("kdenlive:proxy");
        if (proxy.length() > 2) {
            // This is a proxy producer, read original url from kdenlive property
            m_url = QUrl::fromLocalFile(m_properties->get("kdenlive:originalurl"));
            m_usesProxy = true;
        }
        else {
            m_url = QUrl::fromLocalFile(m_properties->get("resource"));
            m_usesProxy = false;
        }
        m_service = m_properties->get("mlt_service");
        getInfoForProducer();
    }
}
示例#24
0
void BinController::initializeBin(Mlt::Playlist playlist)
{
    // Load folders
    Mlt::Properties folderProperties;
    Mlt::Properties playlistProps(playlist.get_properties());
    folderProperties.pass_values(playlistProps, "kdenlive:folder.");
    QMap <QString,QString> foldersData;
    for (int i = 0; i < folderProperties.count(); i++) {
        foldersData.insert(folderProperties.get_name(i), folderProperties.get(i));
    }
    emit loadFolders(foldersData);

    // Read notes
    QString notes = playlistProps.get("kdenlive:documentnotes");
    emit setDocumentNotes(notes);

    // Fill Controller's list
    m_binPlaylist = new Mlt::Playlist(playlist);
    m_binPlaylist->set("id", kPlaylistTrackId);
    int max = m_binPlaylist->count();
    for (int i = 0; i < max; i++) {
        Mlt::Producer *producer = m_binPlaylist->get_clip(i);
        if (producer->is_blank() || !producer->is_valid()) continue;
        QString id = producer->parent().get("id");
        if (id.contains(QStringLiteral("_"))) {
            // This is a track producer
            QString mainId = id.section(QStringLiteral("_"), 0, 0);
            QString track = id.section(QStringLiteral("_"), 1, 1);
            if (m_clipList.contains(mainId)) {
                // The controller for this track producer already exists
            }
            else {
                // Create empty controller for this track
                ClipController *controller = new ClipController(this);
                m_clipList.insert(mainId, controller);
            }
            delete producer;
        }
        else {
            if (m_clipList.contains(id) && m_clipList.value(id)) {
                //Controller was already added by a track producer, add master now
                m_clipList.value(id)->addMasterProducer(producer->parent());
            }
            else {
                // Controller has not been created yet
                ClipController *controller = new ClipController(this, producer->parent());
                // fix MLT somehow adding root to color producer's resource (report upstream)
                if (strcmp(producer->parent().get("mlt_service"), "color") == 0) {
                    QString color = producer->parent().get("resource");
                    if (color.contains(QStringLiteral("/"))) {
                        color = color.section(QStringLiteral("/"), -1, -1);
                        producer->parent().set("resource", color.toUtf8().constData());
                    }
                }
                m_clipList.insert(id, controller);
            }
        }
        emit loadingBin(i + 1);
    }
    // Load markers
    Mlt::Properties markerProperties;
    markerProperties.pass_values(playlistProps, "kdenlive:marker.");
    QMap <QString,QString> markersData;
    for (int i = 0; i < markerProperties.count(); i++) {
        QString markerId = markerProperties.get_name(i);
        QString controllerId = markerId.section(QStringLiteral(":"), 0, 0);
        ClipController *ctrl = m_clipList.value(controllerId);
        if (!ctrl) continue;
        ctrl->loadSnapMarker(markerId.section(QStringLiteral(":"), 1), markerProperties.get(i));
    }
}
示例#25
0
QVariant PlaylistModel::data(const QModelIndex &index, int role) const
{
    switch (role) {
    case Qt::DisplayRole:
    case Qt::ToolTipRole: {
        const Mlt::ClipInfo* info = m_playlist->clip_info(index.row());
        switch (index.column()) {
        case COLUMN_INDEX:
            return QString::number(index.row() + 1);
        case COLUMN_RESOURCE: {
            QString result = QString::fromUtf8(info->resource);
            if (result == "<producer>" && info->producer
                    && info->producer->is_valid() && info->producer->get("mlt_service"))
                result = QString::fromUtf8(info->producer->get("mlt_service"));
            // Use basename for display
            if (role == Qt::DisplayRole && result.startsWith('/'))
                result = QFileInfo(result).fileName();
            return result;
        }
        case COLUMN_IN:
            if (info->producer && info->producer->is_valid()) {
                info->producer->set("_shotcut_time", info->frame_in);
                return info->producer->get_time("_shotcut_time");
            } else
                return "";
        case COLUMN_DURATION:
            if (info->producer && info->producer->is_valid()) {
                info->producer->set("_shotcut_time", info->frame_count);
                return info->producer->get_time("_shotcut_time");
            } else
                return "";
        case COLUMN_START:
            if (info->producer && info->producer->is_valid()) {
                info->producer->set("_shotcut_time", info->start);
                return info->producer->get_time("_shotcut_time");
            }
            else
                return "";
        default:
            break;
        }
        delete info;
        break;
    }
    case Qt::DecorationRole:
        if (index.column() == COLUMN_THUMBNAIL) {
            Mlt::Producer* producer = m_playlist->get_clip(index.row());
            Mlt::Producer parent(producer->get_parent());
            int width = THUMBNAIL_HEIGHT * MLT.profile().dar();
            QString setting = m_settings.value("playlist/thumbnails").toString();
            QImage image;

            if (setting == "wide")
                image = QImage(width * 2, THUMBNAIL_HEIGHT, QImage::Format_ARGB32_Premultiplied);
            else if (setting == "tall")
                image = QImage(width, THUMBNAIL_HEIGHT * 2, QImage::Format_ARGB32_Premultiplied);
            else if (setting == "large")
                image = QImage(width * 2, THUMBNAIL_HEIGHT * 2, QImage::Format_ARGB32_Premultiplied);
            else
                image = QImage(width, THUMBNAIL_HEIGHT, QImage::Format_ARGB32_Premultiplied);

            if (parent.is_valid() && parent.get_data(kThumbnailInProperty)) {
                QPainter painter(&image);
                image.fill(QColor(Qt::black).rgb());

                // draw the in thumbnail
                QImage* thumb = (QImage*) parent.get_data(kThumbnailInProperty);
                QRect rect = thumb->rect();
                if (setting != "large") {
                    rect.setWidth(width);
                    rect.setHeight(THUMBNAIL_HEIGHT);
                }
                painter.drawImage(rect, *thumb);

                if ((setting == "wide" || setting == "tall") && parent.get_data(kThumbnailOutProperty)) {
                    // draw the out thumbnail
                    thumb = (QImage*) parent.get_data(kThumbnailOutProperty);
                    if (setting == "wide") {
                        rect.setWidth(width * 2);
                        rect.setLeft(width);
                    }
                    else if (setting == "tall") {
                        rect.setHeight(THUMBNAIL_HEIGHT * 2);
                        rect.setTop(THUMBNAIL_HEIGHT);
                    }
                    painter.drawImage(rect, *thumb);
                }
                painter.end();
            }
            else {
                image.fill(QColor(Qt::gray).rgb());
            }
            delete producer;
            return image;
        }
        break;
    default:
        break;
    }
    return QVariant();
}
示例#26
0
void MeltJob::startJob()
{
    if (m_url.isEmpty()) {
        m_errorMessage.append(i18n("No producer for this clip."));
        setStatus(JOBCRASHED);
        return;
    }
    int in = m_params.takeFirst().toInt();
    if (in > 0 && !m_extra.contains("offset")) m_extra.insert("offset", QString::number(in));
    int out = m_params.takeFirst().toInt();
    QString producerParams =m_params.takeFirst(); 
    QString filter = m_params.takeFirst();
    QString filterParams = m_params.takeFirst();
    QString consumer = m_params.takeFirst();
    if (consumer.contains(':')) m_dest = consumer.section(':', 1);
    QString consumerParams = m_params.takeFirst();
    
    // optional params
    int startPos = -1;
    if (!m_params.isEmpty()) startPos = m_params.takeFirst().toInt();
    int track = -1;
    if (!m_params.isEmpty()) track = m_params.takeFirst().toInt();
    if (!m_extra.contains("finalfilter")) m_extra.insert("finalfilter", filter);

    if (out != -1 && out <= in) {
        m_errorMessage.append(i18n("Clip zone undefined (%1 - %2).", in, out));
        setStatus(JOBCRASHED);
        return;
    }
    if (m_extra.contains("producer_profile")) {
	m_profile = new Mlt::Profile;
	m_profile->set_explicit(false);
    }
    else {
	m_profile = new Mlt::Profile(KdenliveSettings::current_profile().toUtf8().constData());
    }
    if (m_extra.contains("resize_profile")) {	
	m_profile->set_height(m_extra.value("resize_profile").toInt());
	m_profile->set_width(m_profile->height() * m_profile->sar());
    }
    if (out == -1) {
	m_producer = new Mlt::Producer(*m_profile,  m_url.toUtf8().constData());
	if (m_producer) m_length = m_producer->get_length();
    }
    else {
	Mlt::Producer *tmp = new Mlt::Producer(*m_profile,  m_url.toUtf8().constData());
        if (tmp) m_producer = tmp->cut(in, out);
	delete tmp;
	if (m_producer) m_length = m_producer->get_playtime();
    }
    if (!m_producer || !m_producer->is_valid()) {
	// Clip was removed or something went wrong, Notify user?
	//m_errorMessage.append(i18n("Invalid clip"));
        setStatus(JOBCRASHED);
	return;
    }
    if (m_extra.contains("producer_profile")) {
	m_profile->from_producer(*m_producer);
	m_profile->set_explicit(true);
    }
    QStringList list = producerParams.split(' ', QString::SkipEmptyParts);
    foreach(const QString &data, list) {
        if (data.contains('=')) {
            m_producer->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
        }
    }
    if (consumer.contains(":")) {
        m_consumer = new Mlt::Consumer(*m_profile, consumer.section(':', 0, 0).toUtf8().constData(), consumer.section(':', 1).toUtf8().constData());
    }
    else {
        m_consumer = new Mlt::Consumer(*m_profile, consumer.toUtf8().constData());
    }
    if (!m_consumer || !m_consumer->is_valid()) {
        m_errorMessage.append(i18n("Cannot create consumer %1.", consumer));
        setStatus(JOBCRASHED);
        return;
    }

    //m_consumer->set("terminate_on_pause", 1 );
    //m_consumer->set("eof", "pause" );
    m_consumer->set("real_time", -KdenliveSettings::mltthreads() );


    list = consumerParams.split(' ', QString::SkipEmptyParts);
    foreach(const QString &data, list) {
        if (data.contains('=')) {
            kDebug()<<"// filter con: "<<data;
            m_consumer->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
        }
    }
    
    m_filter = new Mlt::Filter(*m_profile, filter.toUtf8().data());
    if (!m_filter || !m_filter->is_valid()) {
	m_errorMessage = i18n("Filter %1 crashed", filter);
        setStatus(JOBCRASHED);
	return;
    }
    list = filterParams.split(' ', QString::SkipEmptyParts);
    foreach(const QString &data, list) {
        if (data.contains('=')) {
            kDebug()<<"// filter p: "<<data;
            m_filter->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
        }
    }
    Mlt::Tractor tractor;
    Mlt::Playlist playlist;
    playlist.append(*m_producer);
    tractor.set_track(playlist, 0);
    m_consumer->connect(tractor);
    m_producer->set_speed(0);
    m_producer->seek(0);
    m_producer->attach(*m_filter);
    m_showFrameEvent = m_consumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_render);
    m_producer->set_speed(1);
    m_consumer->run();
    
    QMap <QString, QString> jobResults;
    if (m_jobStatus != JOBABORTED && m_extra.contains("key")) {
	QString result = m_filter->get(m_extra.value("key").toUtf8().constData());
	jobResults.insert(m_extra.value("key"), result);
    }
    if (!jobResults.isEmpty() && m_jobStatus != JOBABORTED) {
	emit gotFilterJobResults(m_clipId, startPos, track, jobResults, m_extra);
    }
    if (m_jobStatus == JOBABORTED || m_jobStatus == JOBWORKING) m_jobStatus = JOBDONE;
}
Mlt::Producer *DirectShowVideoWidget::producer(Mlt::Profile& profile)
{
#if 0
    if (!profile.is_explicit()) {
        Mlt::Profile ntscProfile("dv_ntsc");
        Mlt::Profile palProfile("dv_pal");
        if (ui->v4lWidthSpinBox->value() == ntscProfile.width() && ui->v4lHeightSpinBox->value() == ntscProfile.height()) {
            profile.set_sample_aspect(ntscProfile.sample_aspect_num(), ntscProfile.sample_aspect_den());
            profile.set_progressive(ntscProfile.progressive());
            profile.set_colorspace(ntscProfile.colorspace());
            profile.set_frame_rate(ntscProfile.frame_rate_num(), ntscProfile.frame_rate_den());
        } else if (ui->v4lWidthSpinBox->value() == palProfile.width() && ui->v4lHeightSpinBox->value() == palProfile.height()) {
            profile.set_sample_aspect(palProfile.sample_aspect_num(), palProfile.sample_aspect_den());
            profile.set_progressive(palProfile.progressive());
            profile.set_colorspace(palProfile.colorspace());
            profile.set_frame_rate(palProfile.frame_rate_num(), palProfile.frame_rate_den());
        } else {
            profile.set_width(ui->v4lWidthSpinBox->value());
            profile.set_height(ui->v4lHeightSpinBox->value());
            profile.set_sample_aspect(1, 1);
            profile.set_progressive(1);
            profile.set_colorspace(601);
            profile.set_frame_rate(ui->v4lFramerateSpinBox->value() * 10000, 10000);
        }
    }
#endif
    Mlt::Producer* p = 0;
    if (ui->videoCombo->currentIndex() > 0) {
        p = new Mlt::Producer(profile, QString("dshow:video=%1")
                          .arg(ui->videoCombo->currentText())
                          .toLatin1().constData());
    }
    if (ui->audioCombo->currentIndex() > 0) {
        Mlt::Producer* audio = new Mlt::Producer(profile,
            QString("dshow:audio=%1").arg(ui->audioCombo->currentText())
                                     .toLatin1().constData());
        if (p && p->is_valid() && audio->is_valid()) {
            Mlt::Tractor* tractor = new Mlt::Tractor;
            tractor->set("_profile", profile.get_profile(), 0);
            tractor->set("resource", p->get("resource"));
            tractor->set("resource2", audio->get("resource"));
            tractor->set_track(*p, 0);
            delete p;
            tractor->set_track(*audio, 1);
            delete audio;
            p = tractor;
        } else {
            p = audio;
        }
    }
    if (!p || !p->is_valid()) {
        delete p;
        p = new Mlt::Producer(profile, "color:");
        if (ui->videoCombo->currentIndex() > 0) {
            p->set("resource", QString("dshow:video=%1")
                   .arg(ui->videoCombo->currentText())
                   .toLatin1().constData());
        }
        if (ui->audioCombo->currentIndex() > 0) {
            QString resource = QString("dshow:audio=%1").arg(ui->audioCombo->currentText());
            if (ui->videoCombo->currentIndex() > 0) {
                p->set("resource2", resource.toLatin1().constData());
            } else {
                p->set("resource", resource.toLatin1().constData());
            }
        }
        p->set("error", 1);
    }
    p->set("force_seekable", 0);
    return p;
}
示例#28
0
Mlt::Producer* Video4LinuxWidget::newProducer(Mlt::Profile& profile)
{
    if (!profile.is_explicit()) {
        Mlt::Profile ntscProfile("dv_ntsc");
        Mlt::Profile palProfile("dv_pal");
        if (ui->v4lWidthSpinBox->value() == ntscProfile.width() && ui->v4lHeightSpinBox->value() == ntscProfile.height()) {
            profile.set_sample_aspect(ntscProfile.sample_aspect_num(), ntscProfile.sample_aspect_den());
            profile.set_progressive(ntscProfile.progressive());
            profile.set_colorspace(ntscProfile.colorspace());
            profile.set_frame_rate(ntscProfile.frame_rate_num(), ntscProfile.frame_rate_den());
        } else if (ui->v4lWidthSpinBox->value() == palProfile.width() && ui->v4lHeightSpinBox->value() == palProfile.height()) {
            profile.set_sample_aspect(palProfile.sample_aspect_num(), palProfile.sample_aspect_den());
            profile.set_progressive(palProfile.progressive());
            profile.set_colorspace(palProfile.colorspace());
            profile.set_frame_rate(palProfile.frame_rate_num(), palProfile.frame_rate_den());
        } else {
            profile.set_width(ui->v4lWidthSpinBox->value());
            profile.set_height(ui->v4lHeightSpinBox->value());
            profile.set_sample_aspect(1, 1);
            profile.set_progressive(1);
            profile.set_colorspace(601);
            profile.set_frame_rate(ui->v4lFramerateSpinBox->value() * 10000, 10000);
        }
    }
    Mlt::Producer* p = new Mlt::Producer(profile, URL().toLatin1().constData());
    if (!p->is_valid()) {
        delete p;
        p = new Mlt::Producer(profile, "color:");
        p->set("resource1", QString("video4linux2:%1")
               .arg(ui->v4lLineEdit->text()).toLatin1().constData());
        p->set("error", 1);
    }
    else if (m_audioWidget) {
        Mlt::Producer* audio = dynamic_cast<AbstractProducerWidget*>(m_audioWidget)->newProducer(profile);
        Mlt::Tractor* tractor = new Mlt::Tractor;
        tractor->set("_profile", profile.get_profile(), 0);
        tractor->set_track(*p, 0);
        delete p;
        tractor->set_track(*audio, 1);
        delete audio;
        p = new Mlt::Producer(tractor->get_producer());
        delete tractor;
        p->set("resource1", QString("video4linux2:%1")
               .arg(ui->v4lLineEdit->text()).toLatin1().constData());
    }
    p->set("device", ui->v4lLineEdit->text().toLatin1().constData());
    p->set("width", ui->v4lWidthSpinBox->value());
    p->set("height", ui->v4lHeightSpinBox->value());
    if (ui->v4lFramerateSpinBox->value() > 0)
        p->set("framerate", ui->v4lFramerateSpinBox->value());
    p->set("standard", ui->v4lStandardCombo->currentText().toLatin1().constData());
    p->set("channel", ui->v4lChannelSpinBox->value());
    p->set("audio_ix", ui->v4lAudioComboBox->currentIndex());
    p->set("force_seekable", 0);
    p->set(kBackgroundCaptureProperty, 1);
    p->set(kShotcutCaptionProperty, "Video4Linux");
    return p;
}