summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/mythtv/trunk/mythtv-svn/patches/mythcommflag-avidemux.2.patch
blob: d26645fb34c4db377d6807d68a1422bfff67dbdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Index: programs/mythcommflag/main.cpp
===================================================================
--- programs/mythcommflag/main.cpp	(revision 18596)
+++ programs/mythcommflag/main.cpp	(working copy)
@@ -300,6 +300,132 @@
     return COMMFLAG_EXIT_NO_ERROR_WITH_NO_BREAKS;
 }
 
+int GetAviDemux(QString list, QString chanid, QString starttime, const QString &outputfilename)
+{
+    QMap<long long, int> cutlist;
+    QMap<long long, int>::Iterator it;
+    QString result;
+    int startValue = 0;
+    long long myTotalFrames;
+    long long myFrameRate;
+
+    ProgramInfo *pginfo =
+        ProgramInfo::GetProgramFromRecorded(chanid, starttime);
+
+    NuppelVideoPlayer* nvp = new NuppelVideoPlayer("avidemux_export", pginfo);
+
+    myFrameRate = (long long)(nvp->GetFrameRate() * 1000);
+    myTotalFrames = 1000000; //nvp->GetTotalFrameCount();
+
+    if (!pginfo)
+    {
+        VERBOSE(VB_IMPORTANT,
+                QString("No program data exists for channel %1 at %2")
+                .arg(chanid).arg(starttime));
+        return COMMFLAG_BUGGY_EXIT_NO_CHAN_DATA;
+    }
+
+    QString filename = pginfo->GetPlaybackURL(TRUE);
+
+    if (list == "cutlist")
+        pginfo->GetCutList(cutlist);
+    else
+        pginfo->GetCommBreakList(cutlist);
+
+// Formatting of output data
+
+    for (it = cutlist.begin(); it != cutlist.end(); ++it)
+    {
+        if ((it.key() == 0) && (startValue == 0)) // Cutlist starts on first frame,
+            {
+            ++it;
+            startValue = it.key();
+            }
+
+        if ((it.key() != 0) && (startValue == 0)) // Cutlist starts on non-first frame
+            {
+            result += QString("app.addSegment(0,0,%1);").arg(it.key());  
+            startValue = it.key();
+            }
+        else
+           {
+            if  ((*it == MARK_COMM_END) && (startValue != 0) ||
+                (*it == MARK_CUT_END) && (startValue != 0))
+                {
+                 if (result != "")
+                       result += "\n";
+                       startValue = it.key();
+                       result += QString("app.addSegment(0,%1,").arg(it.key()); // Value is a start value
+                }
+            else  
+                {
+                    result += QString("%1);").arg(it.key() - startValue); // Value is an end value
+                }
+           }
+   }
+
+if (it.key() != myTotalFrames)
+    {
+        result += QString("%1);").arg(myTotalFrames);
+    }
+
+// Governs the file output:
+
+    QString tmp = "";
+    ostream *out = &cout;
+
+    if (outputfilename != "-"){
+        QByteArray tmp = outputfilename.toLocal8Bit();
+        out = new fstream(tmp.constData(), ios::app | ios::out );
+        }
+
+    if (outputfilename == ""){
+        VERBOSE(VB_IMPORTANT,
+           QString("Error: AVIDemux output requires the use of the --outputfile option."));
+           return COMMFLAG_EXIT_INVALID_CMDLINE;
+        }
+
+        tmp = QString("//AD  <- Needed to identify//\n"
+                        "//--automatically built--\n"
+                        "//--Project:\n\n"
+                        "var app = new Avidemux();\n\n"
+                        "//** Video **\n"
+                        "// 01 videos source\n" 
+                        "app.load(\"%1\");\n\n"
+                        "app.clearSegments();\n\n"
+                        "%2\n"
+                        "app.markerA=0;\n"
+                        "app.markerB=%3;\n"
+                        "app.rebuildIndex();\n\n"
+                        "//** Postproc **\n"
+                        "app.video.setPostProc(3,3,0);\n\n"
+                        "app.video.setFps1000(%4);\n\n"
+                        "//** Filters **\n\n"
+                        "//** Video Codec conf **\n"
+                        "app.video.codec(\"Copy\",\"CQ=4\",\"0 \");\n\n"
+                        "//** Audio **\n"
+                        "app.audio.reset();\n"
+                        "app.audio.codec(\"copy\",128,0,\"\");\n"
+                        "app.audio.normalizeMode=0;\n"
+                        "app.audio.normalizeValue=0;\n"
+                        "app.audio.delay=0;\n"
+                        "app.audio.mixer(\"NONE\");\n"
+                        "app.setContainer(\"AVI\");\n"
+                        "setSuccess(1);\n"
+                        "//app.Exit();\n\n"
+                        "//End of script\n").arg(filename).arg(result).arg(myTotalFrames).arg(myFrameRate).toLocal8Bit().constData();
+
+        const QByteArray tmp2 = tmp.toLocal8Bit();
+        *out << tmp2.constData() << endl;
+
+        VERBOSE(VB_IMPORTANT,
+                QString("AVIDemux Project generated for %1 at %2 with filename %3.")
+                .arg(chanid).arg(starttime).arg(outputfilename));
+
+    return COMMFLAG_EXIT_NO_ERROR_WITH_NO_BREAKS;
+}
+
+
 void streamOutCommercialBreakList(
     ostream &output, const QMap<long long, int> &commercialBreakList)
 {
@@ -811,6 +937,8 @@
     bool clearCutlist = false;
     bool getCutlist = false;
     bool getSkipList = false;
+    bool getAviDemuxCutlist = false;
+    bool getAviDemuxSkiplist = false;
     QString newCutList = QString::null;
     QMap<QString, QString> settingsOverride;
 
@@ -960,6 +1088,10 @@
             getCutlist = true;
         else if (!strcmp(a.argv()[argpos], "--getskiplist"))
             getSkipList = true;
+        else if (!strcmp(a.argv()[argpos], "--getcutlist-avidemux"))
+            getAviDemuxCutlist = true;
+        else if (!strcmp(a.argv()[argpos], "--getskiplist-avidemux"))
+            getAviDemuxSkiplist = true;
         else if (!strcmp(a.argv()[argpos], "--setcutlist"))
             newCutList = (a.argv()[++argpos]);
         else if (!strcmp(a.argv()[argpos], "-j"))
@@ -1111,6 +1243,8 @@
                     "                             #-#[,#-#]...  (ie, 1-100,1520-3012,4091-5094\n"
                     "--getcutlist                 Display the current cutlist\n"
                     "--getskiplist                Display the current Commercial Skip list\n"
+                    "--getcutlist-avidemux        Export cutlist as AVIDemux Project File\n"
+                    "--getskiplist-avidemux       Export skiplist as AVIDemux Project File\n"
                     "-v or --verbose debug-level  Use '-v help' for level info\n"
                     "--queue                      Insert flagging job into the JobQueue rather than\n"
                     "                             running flagging in the foreground\n"
@@ -1223,6 +1357,12 @@
     if (!newCutList.isNull())
         return SetCutList(chanid, starttime, newCutList);
 
+    if (getAviDemuxCutlist)
+        return GetAviDemux("cutlist", chanid, starttime, outputfilename);
+
+    if (getAviDemuxSkiplist)
+        return GetAviDemux("commflag", chanid, starttime, outputfilename);
+
     if (getCutlist)
         return GetMarkupList("cutlist", chanid, starttime);