Ticket #5809: mythcommflag-avidemux.diff

File mythcommflag-avidemux.diff, 6.8 KB (added by robert.mcnamara@…, 16 years ago)

Patch adds MythCommflag? AVIDemux export

  • programs/mythcommflag/main.cpp

     
    300300    return COMMFLAG_EXIT_NO_ERROR_WITH_NO_BREAKS;
    301301}
    302302
     303int GetAviDemux(QString list, QString chanid, QString starttime, const QString &outputfilename)
     304{
     305    QMap<long long, int> cutlist;
     306    QMap<long long, int>::Iterator it;
     307    QString result;
     308    int startValue = 0;
     309    long long myTotalFrames;
     310    long long myFrameRate;
     311
     312    ProgramInfo *pginfo =
     313        ProgramInfo::GetProgramFromRecorded(chanid, starttime);
     314
     315    NuppelVideoPlayer* nvp = new NuppelVideoPlayer("avidemux_export", pginfo);
     316
     317    myFrameRate = (long long)(nvp->GetFrameRate() * 1000);
     318    myTotalFrames = 1000000; //nvp->GetTotalFrameCount();
     319
     320    if (!pginfo)
     321    {
     322        VERBOSE(VB_IMPORTANT,
     323                QString("No program data exists for channel %1 at %2")
     324                .arg(chanid).arg(starttime));
     325        return COMMFLAG_BUGGY_EXIT_NO_CHAN_DATA;
     326    }
     327
     328    QString filename = pginfo->GetPlaybackURL(TRUE);
     329
     330    if (list == "cutlist")
     331        pginfo->GetCutList(cutlist);
     332    else
     333        pginfo->GetCommBreakList(cutlist);
     334
     335// Formatting of output data
     336
     337    for (it = cutlist.begin(); it != cutlist.end(); ++it)
     338    {
     339        if ((it.key() == 0) && (startValue == 0)) // Cutlist starts on first frame,
     340            {
     341            ++it;
     342            startValue = it.key();
     343            }
     344
     345        if ((it.key() != 0) && (startValue == 0)) // Cutlist starts on non-first frame
     346            {
     347            result += QString("app.addSegment(0,0,%1);").arg(it.key()); 
     348            startValue = it.key();
     349            }
     350        else
     351           {
     352            if  ((*it == MARK_COMM_END) && (startValue != 0) ||
     353                (*it == MARK_CUT_END) && (startValue != 0))
     354                {
     355                 if (result != "")
     356                       result += "\n";
     357                       startValue = it.key();
     358                       result += QString("app.addSegment(0,%1,").arg(it.key()); // Value is a start value
     359                }
     360            else 
     361                {
     362                    result += QString("%1);").arg(it.key() - startValue); // Value is an end value
     363                }
     364           }
     365   }
     366
     367if (it.key() != myTotalFrames)
     368    {
     369        result += QString("%1);").arg(myTotalFrames);
     370    }
     371
     372// Governs the file output:
     373
     374    QString tmp = "";
     375    ostream *out = &cout;
     376
     377    if (outputfilename != "-"){
     378        QByteArray tmp = outputfilename.toLocal8Bit();
     379        out = new fstream(tmp.constData(), ios::app | ios::out );
     380        }
     381
     382    if (outputfilename == ""){
     383        VERBOSE(VB_IMPORTANT,
     384           QString("Error: AVIDemux output requires the use of the --outputfile option."));
     385           return COMMFLAG_EXIT_INVALID_CMDLINE;
     386        }
     387
     388        tmp = QString("//AD  <- Needed to identify//\n"
     389                        "//--automatically built--\n"
     390                        "//--Project:\n\n"
     391                        "var app = new Avidemux();\n\n"
     392                        "//** Video **\n"
     393                        "// 01 videos source\n"
     394                        "app.load(\"%1\");\n\n"
     395                        "app.clearSegments();\n\n"
     396                        "%2\n"
     397                        "app.markerA=0;\n"
     398                        "app.markerB=%3;\n"
     399                        "app.rebuildIndex();\n\n"
     400                        "//** Postproc **\n"
     401                        "app.video.setPostProc(3,3,0);\n\n"
     402                        "app.video.setFps1000(%4);\n\n"
     403                        "//** Filters **\n\n"
     404                        "//** Video Codec conf **\n"
     405                        "app.video.codec(\"Copy\",\"CQ=4\",\"0 \");\n\n"
     406                        "//** Audio **\n"
     407                        "app.audio.reset();\n"
     408                        "app.audio.codec(\"copy\",128,0,\"\");\n"
     409                        "app.audio.normalizeMode=0;\n"
     410                        "app.audio.normalizeValue=0;\n"
     411                        "app.audio.delay=0;\n"
     412                        "app.audio.mixer(\"NONE\");\n"
     413                        "app.setContainer(\"MATROSKA\");\n"
     414                        "setSuccess(1);\n"
     415                        "//app.Exit();\n\n"
     416                        "//End of script\n").arg(filename).arg(result).arg(myTotalFrames).arg(myFrameRate).toLocal8Bit().constData();
     417
     418        const QByteArray tmp2 = tmp.toLocal8Bit();
     419        *out << tmp2.constData() << endl;
     420
     421        VERBOSE(VB_IMPORTANT,
     422                QString("AVIDemux Project generated for %1 at %2 with filename %3.")
     423                .arg(chanid).arg(starttime).arg(outputfilename));
     424
     425    return COMMFLAG_EXIT_NO_ERROR_WITH_NO_BREAKS;
     426}
     427
     428
    303429void streamOutCommercialBreakList(
    304430    ostream &output, const QMap<long long, int> &commercialBreakList)
    305431{
     
    811937    bool clearCutlist = false;
    812938    bool getCutlist = false;
    813939    bool getSkipList = false;
     940    bool getAviDemuxCutlist = false;
     941    bool getAviDemuxSkiplist = false;
    814942    QString newCutList = QString::null;
    815943    QMap<QString, QString> settingsOverride;
    816944
     
    9601088            getCutlist = true;
    9611089        else if (!strcmp(a.argv()[argpos], "--getskiplist"))
    9621090            getSkipList = true;
     1091        else if (!strcmp(a.argv()[argpos], "--getcutlist-avidemux"))
     1092            getAviDemuxCutlist = true;
     1093        else if (!strcmp(a.argv()[argpos], "--getskiplist-avidemux"))
     1094            getAviDemuxSkiplist = true;
    9631095        else if (!strcmp(a.argv()[argpos], "--setcutlist"))
    9641096            newCutList = (a.argv()[++argpos]);
    9651097        else if (!strcmp(a.argv()[argpos], "-j"))
     
    11111243                    "                             #-#[,#-#]...  (ie, 1-100,1520-3012,4091-5094\n"
    11121244                    "--getcutlist                 Display the current cutlist\n"
    11131245                    "--getskiplist                Display the current Commercial Skip list\n"
     1246                    "--getcutlist-avidemux        Export cutlist as AVIDemux Project File\n"
     1247                    "--getskiplist-avidemux       Export skiplist as AVIDemux Project File\n"
    11141248                    "-v or --verbose debug-level  Use '-v help' for level info\n"
    11151249                    "--queue                      Insert flagging job into the JobQueue rather than\n"
    11161250                    "                             running flagging in the foreground\n"
     
    12231357    if (!newCutList.isNull())
    12241358        return SetCutList(chanid, starttime, newCutList);
    12251359
     1360    if (getAviDemuxCutlist)
     1361        return GetAviDemux("cutlist", chanid, starttime, outputfilename);
     1362
     1363    if (getAviDemuxSkiplist)
     1364        return GetAviDemux("commflag", chanid, starttime, outputfilename);
     1365
    12261366    if (getCutlist)
    12271367        return GetMarkupList("cutlist", chanid, starttime);
    12281368