6 #include <QCoreApplication>
14 bool showProgress,
bool fullSpeed,
16 const QDateTime& startedAt_in,
17 const QDateTime& stopsAt_in,
18 const QDateTime& recordingStartedAt_in,
19 const QDateTime& recordingStopsAt_in):
21 player, startedAt_in, stopsAt_in,
22 recordingStartedAt_in, recordingStopsAt_in)
34 int requiredBuffer = 120;
35 int requiredHeadStart = requiredBuffer;
41 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
42 "Waiting to pass preroll + head start"));
48 std::this_thread::sleep_for(5s);
59 if ((wereRecording) && (!
m_stillRecording) && (secsSince < requiredHeadStart))
67 LOG(VB_GENERAL, LOG_ERR,
68 "NVP: Unable to initialize video for FlagCommercials.");
76 QElapsedTimer flagTime;
103 long long framesToProcess = 0;
105 framesToProcess += stopFrame;
111 long long framesProcessed = 0;
115 LOG(VB_COMMFLAG, LOG_INFO,
116 QString(
"Finding closest after preroll(%1-%2)")
120 framesProcessed, flagTime,
false);
122 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest after preroll: %1")
127 long long startFrame = 0;
131 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Finding before preroll (%1-%2)")
134 framesToProcess, framesProcessed,
136 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest before preroll: %1")
143 framesToProcess -= (stopFrame - framesProcessed);
154 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
155 "Waiting for recording to finish"));
156 std::this_thread::sleep_for(5s);
166 LOG(VB_COMMFLAG, LOG_INFO,
167 QString(
"Finding closest after postroll(%1-%2)")
170 framesToProcess, framesProcessed,
172 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest after postRoll: %1")
176 long long startFrame = 0;
178 startFrame = postRollStartLoc
181 LOG(VB_COMMFLAG, LOG_INFO,
182 QString(
"finding closest before preroll(%1-%2)")
183 .arg(startFrame).arg(postRollStartLoc));
185 framesToProcess, framesProcessed,
187 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest before postroll: %1")
200 std::cerr <<
"\b\b\b\b\b\b \b\b\b\b\b\b";
202 std::cerr <<
"\b\b\b\b\b\b\b\b\b\b\b\b\b "
203 "\b\b\b\b\b\b\b\b\b\b\b\b\b";
213 long long totalFrames,
214 long long &framesProcessed,
215 QElapsedTimer&flagTime,
bool findLast)
217 int requiredBuffer = 30;
218 int prevpercent = -1;
227 long long tmpStartFrame = startFrame;
231 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Starting with frame %1")
232 .arg(currentFrameNumber));
235 long long foundFrame = 0;
239 std::chrono::microseconds startTime {0us};
241 startTime = nowAsDuration<std::chrono::microseconds>();
246 if(currentFrameNumber % 1000 == 0)
248 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Processing frame %1")
249 .arg(currentFrameNumber));
252 if(currentFrameNumber > stopFrame || (!findLast && foundFrame))
258 float newAspect = currentFrame->
m_aspect;
259 if (newAspect != aspect)
265 if (((currentFrameNumber % 500) == 0) ||
266 (((currentFrameNumber % 100) == 0) &&
280 std::this_thread::sleep_for(1s);
285 std::this_thread::sleep_for(10ms);
287 if (((currentFrameNumber % 500) == 0) ||
289 ((currentFrameNumber % 100) == 0)))
291 float elapsed = flagTime.elapsed() / 1000.0;
293 float flagFPS = 0.0F;
295 flagFPS = framesProcessed / elapsed;
299 percentage = framesProcessed * 100 / totalFrames;
300 if (percentage > 100)
307 QString
tmp = QString(
"\b\b\b\b\b\b\b\b\b\b\b%1%/%2fps")
308 .arg(percentage, 3).arg((
int)flagFPS, 3);
309 QByteArray ba =
tmp.toLatin1();
310 std::cerr << ba.constData() << std::flush;
314 QString
tmp = QString(
"\b\b\b\b\b\b\b\b\b\b\b\b\b%1/%2fps")
315 .arg(currentFrameNumber, 6).arg((
int)flagFPS, 3);
316 QByteArray ba =
tmp.toLatin1();
317 std::cerr << ba.constData() << std::flush;
324 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
325 "%1% Completed @ %2 fps.")
326 .arg(percentage).arg(flagFPS));
330 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
331 "%1 Frames Completed @ %2 fps.")
332 .arg((
long)currentFrameNumber).arg(flagFPS));
335 if (percentage % 10 == 0 && prevpercent != percentage)
337 prevpercent = percentage;
338 LOG(VB_GENERAL, LOG_INFO, QString(
"%1%% Completed @ %2 fps.")
339 .arg(percentage) .arg(flagFPS));
348 foundFrame = currentFrameNumber;
353 int secondsRecorded =
355 int secondsFlagged = (int)(framesProcessed /
m_fps);
356 int secondsBehind = secondsRecorded - secondsFlagged;
359 auto endTime = nowAsDuration<std::chrono::microseconds>();
361 floatusecs usecSleep = usecPerFrame - (endTime - startTime);
363 if (secondsBehind > requiredBuffer)
368 usecSleep = usecSleep * 0.25;
370 else if (secondsBehind < requiredBuffer)
371 usecSleep = usecPerFrame * 1.5;
374 std::this_thread::sleep_for(usecSleep);
386 LOG(VB_COMMFLAG, LOG_INFO,
"PrePostRollFlagger::GetCommBreakMap()");