示例#1
0
void MythCCExtractorPlayer::ProcessDVBSubtitles(uint flags)
{
    // Process (DVB) subtitle streams.
    DVBSubInfo::iterator subit = m_dvbsub_info.begin();
    for (; subit != m_dvbsub_info.end(); ++subit)
    {
        QString dir_name = QString(m_baseName + ".dvb-%1").arg(subit.key());
        if (!m_workingDir.exists(dir_name) && !m_workingDir.mkdir(dir_name))
        {
            LOG(VB_GENERAL, LOG_ERR, QString("Can't create directory '%1'")
                .arg(dir_name));
            (*subit).subs.clear();
            continue;
        }

        DVBStreamType &subs = (*subit).subs;
        if (subs.empty())
            continue; // Skip empty subtitle streams.
        if (((kProcessFinalize & flags) == 0) && (subs.size() <= 1))
            continue; // Leave one caption behind so it can be amended

        QDir stream_dir(m_workingDir.filePath(dir_name));
        while (subs.size() > ((kProcessFinalize & flags) ? 0 : 1))
        {
            if (subs.front().length <= 0)
                subs.front().length = OneSubtitle::kDefaultLength;

            const OneSubtitle &sub = subs.front();
            int64_t end_time = sub.start_time + sub.length;
            const QString file_name =
                stream_dir.filePath(
                    QString("%1_%2-to-%3.png")
                    .arg((*subit).subs_num)
                    .arg(sub.start_time).arg(end_time));

            if (end_time > sub.start_time)
            {
                //check is there exist file with same start_time
                QStringList filter;
                filter << QString("*_%1*.png").arg(sub.start_time);
                QFileInfoList found = stream_dir.entryInfoList(filter);
                if (found.isEmpty())
                {
                    //no same start_time founded
                    if (!sub.img.save(file_name))
                    {
                        LOG(VB_GENERAL, LOG_ERR,
                            QString("Can't write file '%1'")
                            .arg(file_name));
                    }
                    (*subit).subs_num++;
                }
            }
            subs.pop_front();
        }
    }
}
void MythCCExtractorPlayer::ProcessDVBSubtitles(uint flags)
{
    // Process (DVB) subtitle streams.
    DVBSubInfo::iterator subit = m_dvbsub_info.begin();
    int subtitleStreamCount = 0;
    for (; subit != m_dvbsub_info.end(); ++subit)
    {
        int langCode = 0;
        AvFormatDecoder *avd = dynamic_cast<AvFormatDecoder *>(decoder);
        int idx = subit.key();
        if (avd)
            langCode = avd->GetSubtitleLanguage(subtitleStreamCount, idx);
        subtitleStreamCount++;

        QString lang = iso639_key_to_str3(langCode);
        lang = iso639_is_key_undefined(langCode) ? "und" : lang;
        QString dir_name = m_baseName + QString("-%1.dvb-%2").arg(lang).arg(subit.key());
        if (!m_workingDir.exists(dir_name) && !m_workingDir.mkdir(dir_name))
        {
            LOG(VB_GENERAL, LOG_ERR, QString("Can't create directory '%1'")
                .arg(dir_name));
            (*subit).subs.clear();
            continue;
        }

        DVBStreamType &subs = (*subit).subs;
        if (subs.empty())
            continue; // Skip empty subtitle streams.
        if (((kProcessFinalize & flags) == 0) && (subs.size() <= 1))
            continue; // Leave one caption behind so it can be amended

        QDir stream_dir(m_workingDir.filePath(dir_name));
        while (subs.size() > ((kProcessFinalize & flags) ? 0 : 1))
        {
            if (subs.front().length <= 0)
                subs.front().length = OneSubtitle::kDefaultLength;

            const OneSubtitle &sub = subs.front();
            int64_t end_time = sub.start_time + sub.length;
            const QString file_name =
                stream_dir.filePath(
                    QString("%1_%2-to-%3.png")
                    .arg((*subit).subs_num)
                    .arg(sub.start_time).arg(end_time));

            if (end_time > sub.start_time)
            {
                //check is there exist file with same start_time
                QStringList filter;
                filter << QString("*_%1*.png").arg(sub.start_time);
                QFileInfoList found = stream_dir.entryInfoList(filter);
                if (found.isEmpty())
                {
                    //no same start_time founded
                    if (!sub.img.save(file_name))
                    {
                        LOG(VB_GENERAL, LOG_ERR,
                            QString("Can't write file '%1'")
                            .arg(file_name));
                    }
                    (*subit).subs_num++;
                }
            }
            subs.pop_front();
        }
    }
}