7 #include <QCoreApplication>
16 bool showProgress,
bool fullSpeed,
18 const QDateTime& startedAt_in,
19 const QDateTime& stopsAt_in,
20 const QDateTime& recordingStartedAt_in,
21 const QDateTime& recordingStopsAt_in):
23 player, startedAt_in, stopsAt_in,
24 recordingStartedAt_in, recordingStopsAt_in)
36 int requiredBuffer = 120;
37 int requiredHeadStart = requiredBuffer;
43 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
44 "Waiting to pass preroll + head start"));
50 std::this_thread::sleep_for(5s);
61 if ((wereRecording) && (!
m_stillRecording) && (secsSince < requiredHeadStart))
69 LOG(VB_GENERAL, LOG_ERR,
70 "NVP: Unable to initialize video for FlagCommercials.");
78 QElapsedTimer flagTime;
105 long long framesToProcess = 0;
107 framesToProcess += stopFrame;
113 long long framesProcessed = 0;
117 LOG(VB_COMMFLAG, LOG_INFO,
118 QString(
"Finding closest after preroll(%1-%2)")
122 framesProcessed, flagTime,
false);
124 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest after preroll: %1")
129 long long startFrame = 0;
133 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Finding before preroll (%1-%2)")
136 framesToProcess, framesProcessed,
138 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest before preroll: %1")
145 framesToProcess -= (stopFrame - framesProcessed);
156 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
157 "Waiting for recording to finish"));
158 std::this_thread::sleep_for(5s);
168 LOG(VB_COMMFLAG, LOG_INFO,
169 QString(
"Finding closest after postroll(%1-%2)")
172 framesToProcess, framesProcessed,
174 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest after postRoll: %1")
178 long long startFrame = 0;
180 startFrame = postRollStartLoc
183 LOG(VB_COMMFLAG, LOG_INFO,
184 QString(
"finding closest before preroll(%1-%2)")
185 .arg(startFrame).arg(postRollStartLoc));
187 framesToProcess, framesProcessed,
189 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Closest before postroll: %1")
202 std::cerr <<
"\b\b\b\b\b\b \b\b\b\b\b\b";
204 std::cerr <<
"\b\b\b\b\b\b\b\b\b\b\b\b\b "
205 "\b\b\b\b\b\b\b\b\b\b\b\b\b";
215 long long totalFrames,
216 long long &framesProcessed,
217 QElapsedTimer&flagTime,
bool findLast)
219 int requiredBuffer = 30;
220 int prevpercent = -1;
229 long long tmpStartFrame = startFrame;
233 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Starting with frame %1")
234 .arg(currentFrameNumber));
237 long long foundFrame = 0;
241 std::chrono::microseconds startTime {0us};
243 startTime = nowAsDuration<std::chrono::microseconds>();
248 if(currentFrameNumber % 1000 == 0)
250 LOG(VB_COMMFLAG, LOG_INFO, QString(
"Processing frame %1")
251 .arg(currentFrameNumber));
254 if(currentFrameNumber > stopFrame || (!findLast && foundFrame))
260 float newAspect = currentFrame->
m_aspect;
261 if (newAspect != aspect)
267 if (((currentFrameNumber % 500) == 0) ||
268 (((currentFrameNumber % 100) == 0) &&
282 std::this_thread::sleep_for(1s);
287 std::this_thread::sleep_for(10ms);
289 if (((currentFrameNumber % 500) == 0) ||
291 ((currentFrameNumber % 100) == 0)))
293 float elapsed = flagTime.elapsed() / 1000.0;
295 float flagFPS = 0.0F;
297 flagFPS = framesProcessed / elapsed;
301 percentage = framesProcessed * 100 / totalFrames;
302 percentage = std::min(percentage, 100);
308 QString
tmp = QString(
"\b\b\b\b\b\b\b\b\b\b\b%1%/%2fps")
309 .arg(percentage, 3).arg((
int)flagFPS, 3);
310 QByteArray ba =
tmp.toLatin1();
311 std::cerr << ba.constData() << std::flush;
315 QString
tmp = QString(
"\b\b\b\b\b\b\b\b\b\b\b\b\b%1/%2fps")
316 .arg(currentFrameNumber, 6).arg((
int)flagFPS, 3);
317 QByteArray ba =
tmp.toLatin1();
318 std::cerr << ba.constData() << std::flush;
325 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
326 "%1% Completed @ %2 fps.")
327 .arg(percentage).arg(flagFPS));
331 emit
statusUpdate(QCoreApplication::translate(
"(mythcommflag)",
332 "%1 Frames Completed @ %2 fps.")
333 .arg((
long)currentFrameNumber).arg(flagFPS));
336 if (percentage % 10 == 0 && prevpercent != percentage)
338 prevpercent = percentage;
339 LOG(VB_GENERAL, LOG_INFO, QString(
"%1%% Completed @ %2 fps.")
340 .arg(percentage) .arg(flagFPS));
349 foundFrame = currentFrameNumber;
354 int secondsRecorded =
356 int secondsFlagged = (int)(framesProcessed /
m_fps);
357 int secondsBehind = secondsRecorded - secondsFlagged;
360 auto endTime = nowAsDuration<std::chrono::microseconds>();
362 floatusecs usecSleep = usecPerFrame - (endTime - startTime);
364 if (secondsBehind > requiredBuffer)
369 usecSleep = usecSleep * 0.25;
371 else if (secondsBehind < requiredBuffer)
373 usecSleep = usecPerFrame * 1.5;
377 std::this_thread::sleep_for(usecSleep);
389 LOG(VB_COMMFLAG, LOG_INFO,
"PrePostRollFlagger::GetCommBreakMap()");