MythTV  master
mythtranscode.cpp
Go to the documentation of this file.
1 // C++ headers
2 #include <cerrno>
3 #include <fcntl.h> // for open flags
4 #include <fstream>
5 #include <iostream>
6 
7 // Qt headers
8 #include <QtGlobal>
9 #include <QCoreApplication>
10 #include <QDir>
11 #include <utility>
12 
13 // MythTV headers
14 #include "libmyth/mythcontext.h"
16 #include "libmythbase/exitcodes.h"
17 #include "libmythbase/mythdate.h"
18 #include "libmythbase/mythdb.h"
22 #include "libmythbase/mythversion.h"
24 #include "libmythbase/remotefile.h"
27 #include "libmythtv/jobqueue.h"
29 
30 // MythTranscode
31 #include "mpeg2fix.h"
33 #include "transcode.h"
34 
35 static void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist,
36  frm_dir_map_t *deleteMap, int &exitCode,
37  int resultCode, bool forceDelete);
38 
39 static int glbl_jobID = -1;
40 static QString recorderOptions = "";
41 
42 static void UpdatePositionMap(frm_pos_map_t &posMap, frm_pos_map_t &durMap, const QString& mapfile,
43  ProgramInfo *pginfo)
44 {
45  if (pginfo && mapfile.isEmpty())
46  {
49  pginfo->SavePositionMap(posMap, MARK_GOP_BYFRAME);
50  pginfo->SavePositionMap(durMap, MARK_DURATION_MS);
51  }
52  else if (!mapfile.isEmpty())
53  {
54  MarkTypes keyType = MARK_GOP_BYFRAME;
55  FILE *mapfh = fopen(mapfile.toLocal8Bit().constData(), "w");
56  if (!mapfh)
57  {
58  LOG(VB_GENERAL, LOG_ERR, QString("Could not open map file '%1'")
59  .arg(mapfile) + ENO);
60  return;
61  }
62  frm_pos_map_t::const_iterator it;
63  fprintf (mapfh, "Type: %d\n", keyType);
64  for (it = posMap.cbegin(); it != posMap.cend(); ++it)
65  {
66  QString str = QString("%1 %2\n").arg(it.key()).arg(*it);
67  fprintf(mapfh, "%s", qPrintable(str));
68  }
69  fclose(mapfh);
70  }
71 }
72 
73 static int BuildKeyframeIndex(MPEG2fixup *m2f, const QString &infile,
74  frm_pos_map_t &posMap, frm_pos_map_t &durMap, int jobID)
75 {
76  if (!m2f)
77  return 0;
78 
79  if (jobID < 0 || JobQueue::GetJobCmd(jobID) != JOB_STOP)
80  {
81  if (jobID >= 0)
83  QObject::tr("Generating Keyframe Index"));
84  int err = m2f->BuildKeyframeIndex(infile, posMap, durMap);
85  if (err)
86  return err;
87  if (jobID >= 0)
89  QObject::tr("Transcode Completed"));
90  }
91  return 0;
92 }
93 
94 static void UpdateJobQueue(float percent_done)
95 {
97  QString("%1% ").arg(percent_done, 0, 'f', 1) +
98  QObject::tr("Completed"));
99 }
100 
101 static int CheckJobQueue()
102 {
104  {
105  LOG(VB_GENERAL, LOG_NOTICE, "Transcoding stopped by JobQueue");
106  return 1;
107  }
108  return 0;
109 }
110 
111 static int QueueTranscodeJob(ProgramInfo *pginfo, const QString& profile,
112  const QString& hostname, bool usecutlist)
113 {
114  if (!profile.isEmpty())
115  {
116  RecordingInfo recinfo(*pginfo);
118  }
119 
121  pginfo->GetRecordingStartTime(),
122  hostname, "", "",
123  usecutlist ? JOB_USE_CUTLIST : 0))
124  {
125  LOG(VB_GENERAL, LOG_NOTICE,
126  QString("Queued transcode job for chanid %1 @ %2")
127  .arg(pginfo->GetChanID())
129  return GENERIC_EXIT_OK;
130  }
131 
132  LOG(VB_GENERAL, LOG_ERR, QString("Error queuing job for chanid %1 @ %2")
133  .arg(pginfo->GetChanID())
135  return GENERIC_EXIT_DB_ERROR;
136 }
137 
138 namespace
139 {
140  void cleanup()
141  {
142  delete gContext;
143  gContext = nullptr;
145  }
146 }
147 
148 int main(int argc, char *argv[])
149 {
150  uint chanid = 0;
151  QDateTime starttime;
152  QString infile;
153  QString outfile;
154  QString profilename = QString("autodetect");
155  QString fifodir = nullptr;
156  int jobID = -1;
157  int jobType = JOB_NONE;
158  int otype = REPLEX_MPEG2;
159  bool useCutlist = false;
160  bool keyframesonly = false;
161  bool build_index = false;
162  bool fifosync = false;
163  bool mpeg2 = false;
164  bool fifo_info = false;
165  bool cleanCut = false;
166  frm_dir_map_t deleteMap;
167  frm_pos_map_t posMap;
168  frm_pos_map_t durMap;
169  int AudioTrackNo = -1;
170 
171  bool found_starttime = false;
172  bool found_chanid = false;
173  bool found_infile = false;
174  int update_index = 1;
175  bool isVideo = false;
176  bool passthru = false;
177 
179  if (!cmdline.Parse(argc, argv))
180  {
181  cmdline.PrintHelp();
183  }
184 
185  if (cmdline.toBool("showhelp"))
186  {
187  cmdline.PrintHelp();
188  return GENERIC_EXIT_OK;
189  }
190 
191  if (cmdline.toBool("showversion"))
192  {
194  return GENERIC_EXIT_OK;
195  }
196 
197  QCoreApplication a(argc, argv);
198  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHTRANSCODE);
199 
200  if (cmdline.toBool("outputfile"))
201  {
202  outfile = cmdline.toString("outputfile");
203  update_index = 0;
204  }
205 
206  bool showprogress = cmdline.toBool("showprogress");
207 
208  QString mask("general");
209  bool quiet = (outfile == "-") || showprogress;
210  int retval = cmdline.ConfigureLogging(mask, quiet);
211  if (retval != GENERIC_EXIT_OK)
212  return retval;
213 
214  if (cmdline.toBool("starttime"))
215  {
216  starttime = cmdline.toDateTime("starttime");
217  found_starttime = true;
218  }
219  if (cmdline.toBool("chanid"))
220  {
221  chanid = cmdline.toUInt("chanid");
222  found_chanid = true;
223  }
224  if (cmdline.toBool("jobid"))
225  jobID = cmdline.toInt("jobid");
226  if (cmdline.toBool("inputfile"))
227  {
228  infile = cmdline.toString("inputfile");
229  found_infile = true;
230  }
231  if (cmdline.toBool("video"))
232  isVideo = true;
233  if (cmdline.toBool("profile"))
234  profilename = cmdline.toString("profile");
235 
236  if (cmdline.toBool("usecutlist"))
237  {
238  useCutlist = true;
239  if (!cmdline.toString("usecutlist").isEmpty())
240  {
241  if (!cmdline.toBool("inputfile") && !cmdline.toBool("hls"))
242  {
243  LOG(VB_GENERAL, LOG_CRIT, "External cutlists are only allowed "
244  "when using the --infile option.");
246  }
247 
248  uint64_t last = 0;
249  QStringList cutlist = cmdline.toStringList("usecutlist", " ");
250  for (const auto & cut : std::as_const(cutlist))
251  {
252  QStringList startend = cut.split("-", Qt::SkipEmptyParts);
253  if (startend.size() == 2)
254  {
255  uint64_t start = startend.first().toULongLong();
256  uint64_t end = startend.last().toULongLong();
257 
258  if (cmdline.toBool("inversecut"))
259  {
260  LOG(VB_GENERAL, LOG_DEBUG,
261  QString("Cutting section %1-%2.")
262  .arg(last).arg(start));
263  deleteMap[start] = MARK_CUT_END;
264  deleteMap[end] = MARK_CUT_START;
265  last = end;
266  }
267  else
268  {
269  LOG(VB_GENERAL, LOG_DEBUG,
270  QString("Cutting section %1-%2.")
271  .arg(start).arg(end));
272  deleteMap[start] = MARK_CUT_START;
273  deleteMap[end] = MARK_CUT_END;
274  }
275  }
276  }
277 
278  if (cmdline.toBool("inversecut"))
279  {
280  if (deleteMap.contains(0) && (deleteMap[0] == MARK_CUT_END))
281  deleteMap.remove(0);
282  else
283  deleteMap[0] = MARK_CUT_START;
284  deleteMap[999999999] = MARK_CUT_END;
285  LOG(VB_GENERAL, LOG_DEBUG,
286  QString("Cutting section %1-999999999.")
287  .arg(last));
288  }
289 
290  // sanitize cutlist
291  if (deleteMap.count() >= 2)
292  {
293  frm_dir_map_t::iterator cur = deleteMap.begin();
294  frm_dir_map_t::iterator prev;
295  prev = cur++;
296  while (cur != deleteMap.end())
297  {
298  if (prev.value() == cur.value())
299  {
300  // two of the same type next to each other
301  QString err("Cut %1points found at %3 and %4, with no "
302  "%2 point in between.");
303  if (prev.value() == MARK_CUT_END)
304  err = err.arg("end", "start");
305  else
306  err = err.arg("start", "end");
307  LOG(VB_GENERAL, LOG_CRIT, "Invalid cutlist defined!");
308  LOG(VB_GENERAL, LOG_CRIT, err.arg(prev.key())
309  .arg(cur.key()));
311  }
312  if ( (prev.value() == MARK_CUT_START) &&
313  ((cur.key() - prev.key()) < 2) )
314  {
315  LOG(VB_GENERAL, LOG_WARNING, QString("Discarding "
316  "insufficiently long cut: %1-%2")
317  .arg(prev.key()).arg(cur.key()));
318  prev = deleteMap.erase(prev);
319  cur = deleteMap.erase(cur);
320 
321  if (cur == deleteMap.end())
322  continue;
323  }
324  prev = cur++;
325  }
326  }
327  }
328  else if (cmdline.toBool("inversecut"))
329  {
330  std::cerr << "Cutlist inversion requires an external cutlist be" << std::endl
331  << "provided using the --honorcutlist option." << std::endl;
333  }
334  }
335 
336  if (cmdline.toBool("cleancut"))
337  cleanCut = true;
338 
339  if (cmdline.toBool("allkeys"))
340  keyframesonly = true;
341  if (cmdline.toBool("reindex"))
342  build_index = true;
343  if (cmdline.toBool("fifodir"))
344  fifodir = cmdline.toString("fifodir");
345  if (cmdline.toBool("fifoinfo"))
346  fifo_info = true;
347  if (cmdline.toBool("fifosync"))
348  fifosync = true;
349  if (cmdline.toBool("recopt"))
350  recorderOptions = cmdline.toString("recopt");
351  if (cmdline.toBool("mpeg2"))
352  mpeg2 = true;
353  if (cmdline.toBool("ostream"))
354  {
355  if (cmdline.toString("ostream") == "dvd")
356  otype = REPLEX_DVD;
357  else if (cmdline.toString("ostream") == "ps")
358  otype = REPLEX_MPEG2;
359  else if (cmdline.toString("ostream") == "ts")
360  otype = REPLEX_TS_SD;
361  else
362  {
363  std::cerr << "Invalid 'ostream' type: "
364  << cmdline.toString("ostream").toLocal8Bit().constData()
365  << std::endl;
367  }
368  }
369  if (cmdline.toBool("audiotrack"))
370  AudioTrackNo = cmdline.toInt("audiotrack");
371  if (cmdline.toBool("passthru"))
372  passthru = true;
373  // Set if we want to delete the original file once conversion succeeded.
374  bool deleteOriginal = cmdline.toBool("delete");
375 
376  CleanupGuard callCleanup(cleanup);
377 
378 #ifndef _WIN32
380 #endif
381 
382  // Load the context
383  gContext = new MythContext(MYTH_BINARY_VERSION);
384  if (!gContext->Init(false))
385  {
386  LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
388  }
389 
390  MythTranslation::load("mythfrontend");
391 
393 
394  if (jobID != -1)
395  {
396  if (JobQueue::GetJobInfoFromID(jobID, jobType, chanid, starttime))
397  {
398  found_starttime = true;
399  found_chanid = true;
400  }
401  else
402  {
403  std::cerr << "mythtranscode: ERROR: Unable to find DB info for "
404  << "JobQueue ID# " << jobID << std::endl;
406  }
407  }
408 
409  if (((!found_infile && !(found_chanid && found_starttime)) ||
410  (found_infile && (found_chanid || found_starttime))) &&
411  (!cmdline.toBool("hls")))
412  {
413  std::cerr << "Must specify -i OR -c AND -s options!" << std::endl;
415  }
416  if (isVideo && !found_infile && !cmdline.toBool("hls"))
417  {
418  std::cerr << "Must specify --infile to use --video" << std::endl;
420  }
421  if (jobID >= 0 && (found_infile || build_index))
422  {
423  std::cerr << "Can't specify -j with --buildindex, --video or --infile"
424  << std::endl;
426  }
427  if ((jobID >= 0) && build_index)
428  {
429  std::cerr << "Can't specify both -j and --buildindex" << std::endl;
431  }
432  if (keyframesonly && !fifodir.isEmpty())
433  {
434  std::cerr << "Cannot specify both --fifodir and --allkeys" << std::endl;
436  }
437  if (fifosync && fifodir.isEmpty())
438  {
439  std::cerr << "Must specify --fifodir to use --fifosync" << std::endl;
441  }
442  if (fifo_info && !fifodir.isEmpty())
443  {
444  std::cerr << "Cannot specify both --fifodir and --fifoinfo" << std::endl;
446  }
447  if (cleanCut && fifodir.isEmpty() && !fifo_info)
448  {
449  std::cerr << "Clean cutting works only in fifodir mode" << std::endl;
451  }
452  if (cleanCut && !useCutlist)
453  {
454  std::cerr << "--cleancut is pointless without --honorcutlist" << std::endl;
456  }
457 
458  if (fifo_info)
459  {
460  // Setup a dummy fifodir path, so that the "fifodir" code path
461  // is taken. The path wont actually be used.
462  fifodir = "DummyFifoPath";
463  }
464 
466  {
467  LOG(VB_GENERAL, LOG_ERR, "couldn't open db");
468  return GENERIC_EXIT_DB_ERROR;
469  }
470 
471  ProgramInfo *pginfo = nullptr;
472  if (cmdline.toBool("hls"))
473  {
474  if (cmdline.toBool("hlsstreamid"))
475  {
476  HTTPLiveStream hls(cmdline.toInt("hlsstreamid"));
477  pginfo = new ProgramInfo(hls.GetSourceFile());
478  }
479  if (pginfo == nullptr)
480  pginfo = new ProgramInfo();
481  }
482  else if (isVideo)
483  {
484  // We want the absolute file path for the filemarkup table
485  QFileInfo inf(infile);
486  infile = inf.absoluteFilePath();
487  pginfo = new ProgramInfo(infile);
488  }
489  else if (!found_infile)
490  {
491  pginfo = new ProgramInfo(chanid, starttime);
492 
493  if (!pginfo->GetChanID())
494  {
495  LOG(VB_GENERAL, LOG_ERR,
496  QString("Couldn't find recording for chanid %1 @ %2")
497  .arg(chanid).arg(starttime.toString(Qt::ISODate)));
498  delete pginfo;
500  }
501 
502  infile = pginfo->GetPlaybackURL(false, true);
503  }
504  else
505  {
506  pginfo = new ProgramInfo(infile);
507  if (!pginfo->GetChanID())
508  {
509  LOG(VB_GENERAL, LOG_ERR,
510  QString("Couldn't find a recording for filename '%1'")
511  .arg(infile));
512  delete pginfo;
514  }
515  }
516 
517  if (!pginfo)
518  {
519  LOG(VB_GENERAL, LOG_ERR, "No program info found!");
521  }
522 
523  if (cmdline.toBool("queue"))
524  {
525  QString hostname = cmdline.toString("queue");
526  return QueueTranscodeJob(pginfo, profilename, hostname, useCutlist);
527  }
528 
529  if (infile.startsWith("myth://") && (outfile.isEmpty() || outfile != "-") &&
530  fifodir.isEmpty() && !cmdline.toBool("hls") && !cmdline.toBool("avf"))
531  {
532  LOG(VB_GENERAL, LOG_ERR,
533  QString("Attempted to transcode %1. Mythtranscode is currently "
534  "unable to transcode remote files.") .arg(infile));
535  delete pginfo;
537  }
538 
539  if (outfile.isEmpty() && !build_index && fifodir.isEmpty())
540  outfile = infile + ".tmp";
541 
542  if (jobID >= 0)
543  JobQueue::ChangeJobStatus(jobID, JOB_RUNNING);
544 
545  auto *transcode = new Transcode(pginfo);
546 
547  if (!build_index)
548  {
549  if (cmdline.toBool("hlsstreamid"))
550  {
551  LOG(VB_GENERAL, LOG_NOTICE,
552  QString("Transcoding HTTP Live Stream ID %1")
553  .arg(cmdline.toInt("hlsstreamid")));
554  }
555  else if (fifodir.isEmpty())
556  {
557  LOG(VB_GENERAL, LOG_NOTICE, QString("Transcoding from %1 to %2")
558  .arg(infile, outfile));
559  }
560  else
561  {
562  LOG(VB_GENERAL, LOG_NOTICE, QString("Transcoding from %1 to FIFO")
563  .arg(infile));
564  }
565  }
566 
567  if (cmdline.toBool("avf"))
568  {
569  transcode->SetAVFMode();
570 
571  if (cmdline.toBool("container"))
572  transcode->SetCMDContainer(cmdline.toString("container"));
573  if (cmdline.toBool("acodec"))
574  transcode->SetCMDAudioCodec(cmdline.toString("acodec"));
575  if (cmdline.toBool("vcodec"))
576  transcode->SetCMDVideoCodec(cmdline.toString("vcodec"));
577  }
578  else if (cmdline.toBool("hls"))
579  {
580  transcode->SetHLSMode();
581 
582  if (cmdline.toBool("hlsstreamid"))
583  transcode->SetHLSStreamID(cmdline.toInt("hlsstreamid"));
584  if (cmdline.toBool("maxsegments"))
585  transcode->SetHLSMaxSegments(cmdline.toInt("maxsegments"));
586  if (cmdline.toBool("noaudioonly"))
587  transcode->DisableAudioOnlyHLS();
588  }
589 
590  if (cmdline.toBool("avf") || cmdline.toBool("hls"))
591  {
592  if (cmdline.toBool("width"))
593  transcode->SetCMDWidth(cmdline.toInt("width"));
594  if (cmdline.toBool("height"))
595  transcode->SetCMDHeight(cmdline.toInt("height"));
596  if (cmdline.toBool("bitrate"))
597  transcode->SetCMDBitrate(cmdline.toInt("bitrate") * 1000);
598  if (cmdline.toBool("audiobitrate"))
599  transcode->SetCMDAudioBitrate(cmdline.toInt("audiobitrate") * 1000);
600  }
601 
602  if (showprogress)
603  transcode->ShowProgress(true);
604  if (!recorderOptions.isEmpty())
605  transcode->SetRecorderOptions(recorderOptions);
606  int result = 0;
607  if ((!mpeg2 && !build_index) || cmdline.toBool("hls"))
608  {
609  result = transcode->TranscodeFile(infile, outfile,
610  profilename, useCutlist,
611  (fifosync || keyframesonly), jobID,
612  fifodir, fifo_info, cleanCut, deleteMap,
613  AudioTrackNo, passthru);
614 
615  if ((result == REENCODE_OK) && (jobID >= 0))
616  {
617  JobQueue::ChangeJobArgs(jobID, "RENAME_TO_NUV");
618  RecordingInfo recInfo(pginfo->GetRecordingID());
619  RecordingFile *recFile = recInfo.GetRecordingFile();
620  recFile->m_containerFormat = formatNUV;
621  recFile->Save();
622  }
623  }
624 
625  if (fifo_info)
626  {
627  delete transcode;
628  return GENERIC_EXIT_OK;
629  }
630 
631  int exitcode = GENERIC_EXIT_OK;
632  if ((result == REENCODE_MPEG2TRANS) || mpeg2 || build_index)
633  {
634  void (*update_func)(float) = nullptr;
635  int (*check_func)() = nullptr;
636  if (useCutlist)
637  {
638  LOG(VB_GENERAL, LOG_INFO, "Honoring the cutlist while transcoding");
639  if (deleteMap.isEmpty())
640  pginfo->QueryCutList(deleteMap);
641  }
642  if (jobID >= 0)
643  {
644  glbl_jobID = jobID;
645  update_func = &UpdateJobQueue;
646  check_func = &CheckJobQueue;
647  }
648 
649  auto *m2f = new MPEG2fixup(infile, outfile,
650  &deleteMap, nullptr, false, false, 20,
651  showprogress, otype, update_func,
652  check_func);
653 
654  if (cmdline.toBool("allaudio"))
655  {
656  m2f->SetAllAudio(true);
657  }
658 
659  if (build_index)
660  {
661  int err = BuildKeyframeIndex(m2f, infile, posMap, durMap, jobID);
662  if (err)
663  {
664  delete m2f;
665  m2f = nullptr;
666  return err;
667  }
668  if (update_index)
669  UpdatePositionMap(posMap, durMap, nullptr, pginfo);
670  else
671  UpdatePositionMap(posMap, durMap, outfile + QString(".map"), pginfo);
672  }
673  else
674  {
675  result = m2f->Start();
676  if (result == REENCODE_OK)
677  {
678  result = BuildKeyframeIndex(m2f, outfile, posMap, durMap, jobID);
679  if (result == REENCODE_OK)
680  {
681  if (update_index)
682  UpdatePositionMap(posMap, durMap, nullptr, pginfo);
683  else
684  UpdatePositionMap(posMap, durMap, outfile + QString(".map"),
685  pginfo);
686  }
687  RecordingInfo recInfo(*pginfo);
688  RecordingFile *recFile = recInfo.GetRecordingFile();
689  if (otype == REPLEX_DVD || otype == REPLEX_MPEG2 ||
690  otype == REPLEX_HDTV)
691  {
693  JobQueue::ChangeJobArgs(jobID, "RENAME_TO_MPG");
694  }
695  else
696  {
698  }
699  recFile->Save();
700  }
701  }
702  delete m2f;
703  m2f = nullptr;
704  }
705 
706  if (result == REENCODE_OK)
707  {
708  if (jobID >= 0)
709  JobQueue::ChangeJobStatus(jobID, JOB_STOPPING);
710  LOG(VB_GENERAL, LOG_NOTICE, QString("%1 %2 done")
711  .arg(build_index ? "Building Index for" : "Transcoding", infile));
712  }
713  else if (result == REENCODE_CUTLIST_CHANGE)
714  {
715  if (jobID >= 0)
716  JobQueue::ChangeJobStatus(jobID, JOB_RETRY);
717  LOG(VB_GENERAL, LOG_NOTICE,
718  QString("Transcoding %1 aborted because of cutlist update")
719  .arg(infile));
720  exitcode = GENERIC_EXIT_RESTART;
721  }
722  else if (result == REENCODE_STOPPED)
723  {
724  if (jobID >= 0)
725  JobQueue::ChangeJobStatus(jobID, JOB_ABORTING);
726  LOG(VB_GENERAL, LOG_NOTICE,
727  QString("Transcoding %1 stopped because of stop command")
728  .arg(infile));
729  exitcode = GENERIC_EXIT_KILLED;
730  }
731  else
732  {
733  if (jobID >= 0)
734  JobQueue::ChangeJobStatus(jobID, JOB_ERRORING);
735  LOG(VB_GENERAL, LOG_ERR, QString("Transcoding %1 failed").arg(infile));
736  exitcode = result;
737  }
738 
739  if (deleteOriginal || jobID >= 0)
740  CompleteJob(jobID, pginfo, useCutlist, &deleteMap, exitcode, result, deleteOriginal);
741 
742  transcode->deleteLater();
743 
744  return exitcode;
745 }
746 
747 static int transUnlink(const QString& filename, ProgramInfo *pginfo)
748 {
749  QString hostname = pginfo->GetHostname();
750 
751  if (!pginfo->GetStorageGroup().isEmpty() &&
752  !hostname.isEmpty())
753  {
755  QString basename = filename.section('/', -1);
756  QString uri = MythCoreContext::GenMythURL(hostname, port, basename,
757  pginfo->GetStorageGroup());
758 
759  LOG(VB_GENERAL, LOG_NOTICE, QString("Requesting delete for file '%1'.")
760  .arg(uri));
761  bool ok = RemoteFile::DeleteFile(uri);
762  if (ok)
763  return 0;
764  }
765 
766  LOG(VB_GENERAL, LOG_NOTICE, QString("Deleting file '%1'.").arg(filename));
767  return unlink(filename.toLocal8Bit().constData());
768 }
769 
770 static uint64_t ComputeNewBookmark(uint64_t oldBookmark,
771  frm_dir_map_t *deleteMap)
772 {
773  if (deleteMap == nullptr)
774  return oldBookmark;
775 
776  uint64_t subtraction = 0;
777  uint64_t startOfCutRegion = 0;
778  frm_dir_map_t delMap = *deleteMap;
779  bool withinCut = false;
780  bool firstMark = true;
781  while (!delMap.empty() && delMap.begin().key() <= oldBookmark)
782  {
783  uint64_t key = delMap.begin().key();
784  MarkTypes mark = delMap.begin().value();
785 
786  if (mark == MARK_CUT_START && !withinCut)
787  {
788  withinCut = true;
789  startOfCutRegion = key;
790  }
791  else if (mark == MARK_CUT_END && firstMark)
792  {
793  subtraction += key;
794  }
795  else if (mark == MARK_CUT_END && withinCut)
796  {
797  withinCut = false;
798  subtraction += (key - startOfCutRegion);
799  }
800  delMap.remove(key);
801  firstMark = false;
802  }
803  if (withinCut)
804  subtraction += (oldBookmark - startOfCutRegion);
805  return oldBookmark - subtraction;
806 }
807 
808 static uint64_t ReloadBookmark(ProgramInfo *pginfo)
809 {
810  MSqlQuery query(MSqlQuery::InitCon());
811  uint64_t currentBookmark = 0;
812  query.prepare("SELECT DISTINCT mark FROM recordedmarkup "
813  "WHERE chanid = :CHANID "
814  "AND starttime = :STARTIME "
815  "AND type = :MARKTYPE ;");
816  query.bindValue(":CHANID", pginfo->GetChanID());
817  query.bindValue(":STARTTIME", pginfo->GetRecordingStartTime());
818  query.bindValue(":MARKTYPE", MARK_BOOKMARK);
819  if (query.exec() && query.next())
820  {
821  currentBookmark = query.value(0).toLongLong();
822  }
823  return currentBookmark;
824 }
825 
826 static void WaitToDelete(ProgramInfo *pginfo)
827 {
828  LOG(VB_GENERAL, LOG_NOTICE,
829  "Transcode: delete old file: waiting while program is in use.");
830 
831  bool inUse = true;
832  MSqlQuery query(MSqlQuery::InitCon());
833  while (inUse)
834  {
835  query.prepare("SELECT count(*) FROM inuseprograms "
836  "WHERE chanid = :CHANID "
837  "AND starttime = :STARTTIME "
838  "AND recusage = 'player' ;");
839  query.bindValue(":CHANID", pginfo->GetChanID());
840  query.bindValue(":STARTTIME", pginfo->GetRecordingStartTime());
841  if (!query.exec() || !query.next())
842  {
843  LOG(VB_GENERAL, LOG_ERR,
844  "Transcode: delete old file: in-use query failed;");
845  inUse = false;
846  }
847  else
848  {
849  inUse = (query.value(0).toUInt() != 0);
850  }
851 
852  if (inUse)
853  {
854  const unsigned kSecondsToWait = 10;
855  LOG(VB_GENERAL, LOG_NOTICE,
856  QString("Transcode: program in use, rechecking in %1 seconds.")
857  .arg(kSecondsToWait));
858  sleep(kSecondsToWait);
859  }
860  }
861  LOG(VB_GENERAL, LOG_NOTICE, "Transcode: program is no longer in use.");
862 }
863 
864 static void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist,
865  frm_dir_map_t *deleteMap, int &exitCode, int resultCode, bool forceDelete)
866 {
867  int status = JOB_UNKNOWN;
868  if (jobID >= 0)
869  status = JobQueue::GetJobStatus(jobID);
870 
871  if (!pginfo)
872  {
873  if (jobID >= 0)
874  JobQueue::ChangeJobStatus(jobID, JOB_ERRORED,
875  QObject::tr("Job errored, unable to find Program Info for job"));
876  LOG(VB_GENERAL, LOG_CRIT, "MythTranscode: Cleanup errored, unable to find Program Info");
877  return;
878  }
879 
880  const QString filename = pginfo->GetPlaybackURL(false, true);
881  const QByteArray fname = filename.toLocal8Bit();
882 
883  if (resultCode == REENCODE_OK)
884  {
885  WaitToDelete(pginfo);
886 
887  // Transcoding may take several minutes. Reload the bookmark
888  // in case it changed, then save its translated value back.
889  uint64_t previousBookmark =
890  ComputeNewBookmark(ReloadBookmark(pginfo), deleteMap);
891  pginfo->SaveBookmark(previousBookmark);
892 
893  QString jobArgs;
894  if (jobID >= 0)
895  jobArgs = JobQueue::GetJobArgs(jobID);
896 
897  const QString tmpfile = filename + ".tmp";
898  const QByteArray atmpfile = tmpfile.toLocal8Bit();
899 
900  // To save the original file...
901  const QString oldfile = filename + ".old";
902  const QByteArray aoldfile = oldfile.toLocal8Bit();
903 
904  QFileInfo st(tmpfile);
905  qint64 newSize = 0;
906  if (st.exists())
907  newSize = st.size();
908 
909  QString cnf = filename;
910  if (jobID >= 0)
911  {
912  if (filename.endsWith(".mpg") && jobArgs == "RENAME_TO_NUV")
913  {
914  QString newbase = pginfo->QueryBasename();
915  cnf.replace(".mpg", ".nuv");
916  newbase.replace(".mpg", ".nuv");
917  pginfo->SaveBasename(newbase);
918  }
919  else if (filename.endsWith(".ts") &&
920  (jobArgs == "RENAME_TO_MPG"))
921  {
922  QString newbase = pginfo->QueryBasename();
923  // MPEG-TS to MPEG-PS
924  cnf.replace(".ts", ".mpg");
925  newbase.replace(".ts", ".mpg");
926  pginfo->SaveBasename(newbase);
927  }
928  }
929 
930  const QString newfile = cnf;
931  const QByteArray anewfile = newfile.toLocal8Bit();
932 
933  if (rename(fname.constData(), aoldfile.constData()) == -1)
934  {
935  LOG(VB_GENERAL, LOG_ERR,
936  QString("mythtranscode: Error Renaming '%1' to '%2'")
937  .arg(filename, oldfile) + ENO);
938  }
939 
940  if (rename(atmpfile.constData(), anewfile.constData()) == -1)
941  {
942  LOG(VB_GENERAL, LOG_ERR,
943  QString("mythtranscode: Error Renaming '%1' to '%2'")
944  .arg(tmpfile, newfile) + ENO);
945  }
946 
947  if (!gCoreContext->GetBoolSetting("SaveTranscoding", false) || forceDelete)
948  {
949  bool followLinks =
950  gCoreContext->GetBoolSetting("DeletesFollowLinks", false);
951 
952  LOG(VB_FILE, LOG_INFO,
953  QString("mythtranscode: About to unlink/delete file: %1")
954  .arg(oldfile));
955 
956  QFileInfo finfo(oldfile);
957  if (followLinks && finfo.isSymLink())
958  {
959  QString link = getSymlinkTarget(oldfile);
960  QByteArray alink = link.toLocal8Bit();
961  int err = transUnlink(alink, pginfo);
962  if (err)
963  {
964  LOG(VB_GENERAL, LOG_ERR,
965  QString("mythtranscode: Error deleting '%1' "
966  "pointed to by '%2'")
967  .arg(alink.constData(), aoldfile.constData()) + ENO);
968  }
969 
970  err = unlink(aoldfile.constData());
971  if (err)
972  {
973  LOG(VB_GENERAL, LOG_ERR,
974  QString("mythtranscode: Error deleting '%1', "
975  "a link pointing to '%2'")
976  .arg(aoldfile.constData(), alink.constData()) + ENO);
977  }
978  }
979  else
980  {
981  int err = transUnlink(aoldfile.constData(), pginfo);
982  if (err)
983  {
984  LOG(VB_GENERAL, LOG_ERR,
985  QString("mythtranscode: Error deleting '%1': ")
986  .arg(oldfile) + ENO);
987  }
988  }
989  }
990 
991  // Rename or delete all preview thumbnails.
992  //
993  // TODO: This cleanup should be moved to RecordingInfo, and triggered
994  // when SaveBasename() is called
995  QFileInfo fInfo(filename);
996  QStringList nameFilters;
997  nameFilters.push_back(fInfo.fileName() + "*.png");
998  nameFilters.push_back(fInfo.fileName() + "*.jpg");
999 
1000  QDir dir (fInfo.path());
1001  QFileInfoList previewFiles = dir.entryInfoList(nameFilters);
1002 
1003  for (const auto & previewFile : std::as_const(previewFiles))
1004  {
1005  QString oldFileName = previewFile.absoluteFilePath();
1006 
1007  // Delete previews if cutlist was applied. They will be re-created as
1008  // required. This prevents the user from being stuck with a preview
1009  // from a cut area and ensures that the "dimensioned" previews
1010  // correspond to the new timeline
1011  if (useCutlist)
1012  {
1013  // If unlink fails, keeping the old preview is not a problem.
1014  // The RENAME_TO_NUV check below will attempt to rename the
1015  // file, if required.
1016  if (transUnlink(oldFileName.toLocal8Bit().constData(), pginfo) != -1)
1017  continue;
1018  }
1019 
1020  if (jobArgs == "RENAME_TO_NUV" || jobArgs == "RENAME_TO_MPG")
1021  {
1022  QString newExtension = "mpg";
1023  if (jobArgs == "RENAME_TO_NUV")
1024  newExtension = "nuv";
1025 
1026  QString oldSuffix = previewFile.completeSuffix();
1027 
1028  if (!oldSuffix.startsWith(newExtension))
1029  {
1030  QString newSuffix = oldSuffix;
1031  QString oldExtension = oldSuffix.section(".", 0, 0);
1032  newSuffix.replace(oldExtension, newExtension);
1033 
1034  QString newFileName = oldFileName;
1035  newFileName.replace(oldSuffix, newSuffix);
1036 
1037  if (!QFile::rename(oldFileName, newFileName))
1038  {
1039  LOG(VB_GENERAL, LOG_ERR,
1040  QString("mythtranscode: Error renaming %1 to %2")
1041  .arg(oldFileName, newFileName));
1042  }
1043  }
1044  }
1045  }
1046 
1047  MSqlQuery query(MSqlQuery::InitCon());
1048 
1049  if (useCutlist)
1050  {
1051  query.prepare("DELETE FROM recordedmarkup "
1052  "WHERE chanid = :CHANID "
1053  "AND starttime = :STARTTIME "
1054  "AND type != :BOOKMARK ");
1055  query.bindValue(":CHANID", pginfo->GetChanID());
1056  query.bindValue(":STARTTIME", pginfo->GetRecordingStartTime());
1057  query.bindValue(":BOOKMARK", MARK_BOOKMARK);
1058 
1059  if (!query.exec())
1060  MythDB::DBError("Error in mythtranscode", query);
1061 
1062  query.prepare("UPDATE recorded "
1063  "SET cutlist = :CUTLIST "
1064  "WHERE chanid = :CHANID "
1065  "AND starttime = :STARTTIME ;");
1066  query.bindValue(":CUTLIST", "0");
1067  query.bindValue(":CHANID", pginfo->GetChanID());
1068  query.bindValue(":STARTTIME", pginfo->GetRecordingStartTime());
1069 
1070  if (!query.exec())
1071  MythDB::DBError("Error in mythtranscode", query);
1072 
1074  }
1075  else
1076  {
1077  query.prepare("DELETE FROM recordedmarkup "
1078  "WHERE chanid = :CHANID "
1079  "AND starttime = :STARTTIME "
1080  "AND type not in ( :COMM_START, "
1081  " :COMM_END, :BOOKMARK, "
1082  " :CUTLIST_START, :CUTLIST_END) ;");
1083  query.bindValue(":CHANID", pginfo->GetChanID());
1084  query.bindValue(":STARTTIME", pginfo->GetRecordingStartTime());
1085  query.bindValue(":COMM_START", MARK_COMM_START);
1086  query.bindValue(":COMM_END", MARK_COMM_END);
1087  query.bindValue(":BOOKMARK", MARK_BOOKMARK);
1088  query.bindValue(":CUTLIST_START", MARK_CUT_START);
1089  query.bindValue(":CUTLIST_END", MARK_CUT_END);
1090 
1091  if (!query.exec())
1092  MythDB::DBError("Error in mythtranscode", query);
1093  }
1094 
1095  if (newSize)
1096  pginfo->SaveFilesize(newSize);
1097 
1098  if (jobID >= 0)
1099  JobQueue::ChangeJobStatus(jobID, JOB_FINISHED);
1100  }
1101  else
1102  {
1103  // Not a successful run, so remove the files we created
1104  QString filename_tmp = filename + ".tmp";
1105  QByteArray fname_tmp = filename_tmp.toLocal8Bit();
1106  LOG(VB_GENERAL, LOG_NOTICE, QString("Deleting %1").arg(filename_tmp));
1107  transUnlink(fname_tmp.constData(), pginfo);
1108 
1109  QString filename_map = filename + ".tmp.map";
1110  QByteArray fname_map = filename_map.toLocal8Bit();
1111  unlink(fname_map.constData());
1112 
1113  if (jobID >= 0)
1114  {
1115  if (status == JOB_ABORTING) // Stop command was sent
1116  {
1117  JobQueue::ChangeJobStatus(jobID, JOB_ABORTED,
1118  QObject::tr("Job Aborted"));
1119  }
1120  else if (status != JOB_ERRORING) // Recoverable error
1121  {
1122  exitCode = GENERIC_EXIT_RESTART;
1123  }
1124  else // Unrecoverable error
1125  {
1126  JobQueue::ChangeJobStatus(jobID, JOB_ERRORED,
1127  QObject::tr("Unrecoverable error"));
1128  }
1129  }
1130  }
1131 }
1132 /* vim: set expandtab tabstop=4 shiftwidth=4: */
HTTPLiveStream::GetSourceFile
QString GetSourceFile(void) const
Definition: httplivestream.h:42
JobQueue::GetJobCmd
static enum JobCmds GetJobCmd(int jobID)
Definition: jobqueue.cpp:1450
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:813
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
ProgramInfo::SaveFilesize
virtual void SaveFilesize(uint64_t fsize)
Sets recording file size in database, and sets "filesize" field.
Definition: programinfo.cpp:6394
mpeg2fix.h
MARK_KEYFRAME
@ MARK_KEYFRAME
Definition: programtypes.h:62
COMM_FLAG_NOT_FLAGGED
@ COMM_FLAG_NOT_FLAGGED
Definition: programtypes.h:121
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:73
MARK_COMM_END
@ MARK_COMM_END
Definition: programtypes.h:60
ProgramInfo::SaveBookmark
void SaveBookmark(uint64_t frame)
Clears any existing bookmark in DB and if frame is greater than 0 sets a new bookmark.
Definition: programinfo.cpp:2669
ProgramInfo::GetHostname
QString GetHostname(void) const
Definition: programinfo.h:421
mythdb.h
ProgramInfo::QueryBasename
QString QueryBasename(void) const
Gets the basename, from the DB if necessary.
Definition: programinfo.cpp:2508
JobQueue::QueueJob
static bool QueueJob(int jobType, uint chanid, const QDateTime &recstartts, const QString &args="", const QString &comment="", QString host="", int flags=0, int status=JOB_QUEUED, QDateTime schedruntime=QDateTime())
Definition: jobqueue.cpp:505
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:72
RecordingInfo
Holds information on a TV Program one might wish to record.
Definition: recordinginfo.h:35
MARK_CUT_END
@ MARK_CUT_END
Definition: programtypes.h:55
ProgramInfo::GetRecordingID
uint GetRecordingID(void) const
Definition: programinfo.h:446
MythContext
Startup context for MythTV.
Definition: mythcontext.h:43
REENCODE_MPEG2TRANS
@ REENCODE_MPEG2TRANS
Definition: transcodedefs.h:5
JOB_USE_CUTLIST
@ JOB_USE_CUTLIST
Definition: jobqueue.h:60
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:204
frm_dir_map_t
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:118
JOB_NONE
@ JOB_NONE
Definition: jobqueue.h:75
getSymlinkTarget
QString getSymlinkTarget(const QString &start_file, QStringList *intermediaries, unsigned maxLinks)
Definition: mythmiscutil.cpp:451
JobQueue::GetJobInfoFromID
static bool GetJobInfoFromID(int jobID, int &jobType, uint &chanid, QDateTime &recstartts)
Definition: jobqueue.cpp:656
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:619
RecordingFile
Holds information on a recording file and it's video and audio streams.
Definition: recordingfile.h:29
ProgramInfo::SaveCommFlagged
void SaveCommFlagged(CommFlagStatus flag)
Set "commflagged" field in "recorded" table to "flag".
Definition: programinfo.cpp:3340
quiet
int quiet
Definition: mythcommflag.cpp:68
BuildKeyframeIndex
static int BuildKeyframeIndex(MPEG2fixup *m2f, const QString &infile, frm_pos_map_t &posMap, frm_pos_map_t &durMap, int jobID)
Definition: mythtranscode.cpp:73
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MPEG2fixup::BuildKeyframeIndex
int BuildKeyframeIndex(const QString &file, frm_pos_map_t &posMap, frm_pos_map_t &durMap)
Definition: mpeg2fix.cpp:2876
httplivestream.h
REPLEX_HDTV
#define REPLEX_HDTV
Definition: multiplex.h:45
JOB_STOP
@ JOB_STOP
Definition: jobqueue.h:54
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:11
jobID
int jobID
Definition: mythcommflag.cpp:80
mythburn.FILE
int FILE
Definition: mythburn.py:139
ProgramInfo::GetRecordingStartTime
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:404
MYTH_APPNAME_MYTHTRANSCODE
static constexpr const char * MYTH_APPNAME_MYTHTRANSCODE
Definition: mythcorecontext.h:27
isVideo
static bool isVideo(const QString &mimeType)
Definition: newssite.cpp:294
RecordingInfo::ApplyTranscoderProfileChange
void ApplyTranscoderProfileChange(const QString &profile) const
Sets the transcoder profile for a recording.
Definition: recordinginfo.cpp:844
QueueTranscodeJob
static int QueueTranscodeJob(ProgramInfo *pginfo, const QString &profile, const QString &hostname, bool usecutlist)
Definition: mythtranscode.cpp:111
MPEG2fixup
Definition: mpeg2fix.h:122
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1544
mythdate.h
RecordingInfo::GetRecordingFile
RecordingFile * GetRecordingFile() const
Definition: recordinginfo.h:282
programinfo.h
mythlogging.h
ReloadBookmark
static uint64_t ReloadBookmark(ProgramInfo *pginfo)
Definition: mythtranscode.cpp:808
GENERIC_EXIT_NO_MYTHCONTEXT
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:14
MythCoreContext::GenMythURL
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
Definition: mythcorecontext.cpp:760
hardwareprofile.scan.profile
profile
Definition: scan.py:97
mythtranscode_commandlineparser.h
remotefile.h
MARK_DURATION_MS
@ MARK_DURATION_MS
Definition: programtypes.h:74
JobQueue::ChangeJobComment
static bool ChangeJobComment(int jobID, const QString &comment="")
Definition: jobqueue.cpp:1001
MythCoreContext::GetBackendServerPort
int GetBackendServerPort(void)
Returns the locally defined backend control port.
Definition: mythcorecontext.cpp:1064
signalhandling.h
CheckJobQueue
static int CheckJobQueue()
Definition: mythtranscode.cpp:101
MARK_GOP_START
@ MARK_GOP_START
Definition: programtypes.h:61
JobQueue::GetJobArgs
static QString GetJobArgs(int jobID)
Definition: jobqueue.cpp:1471
ComputeNewBookmark
static uint64_t ComputeNewBookmark(uint64_t oldBookmark, frm_dir_map_t *deleteMap)
Definition: mythtranscode.cpp:770
REENCODE_CUTLIST_CHANGE
@ REENCODE_CUTLIST_CHANGE
Definition: transcodedefs.h:6
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:551
CleanupGuard
Definition: cleanupguard.h:6
RecordingFile::Save
bool Save()
Definition: recordingfile.cpp:55
JobQueue::GetJobStatus
static enum JobStatus GetJobStatus(int jobID)
Definition: jobqueue.cpp:1513
mark
Definition: lang.cpp:22
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
MSqlQuery::testDBConnection
static bool testDBConnection()
Checks DB connection + login (login info via Mythcontext)
Definition: mythdbcon.cpp:877
RecordingFile::m_containerFormat
AVContainer m_containerFormat
Definition: recordingfile.h:47
REPLEX_DVD
#define REPLEX_DVD
Definition: multiplex.h:44
ProgramInfo::QueryCutList
bool QueryCutList(frm_dir_map_t &delMap, bool loadAutosave=false) const
Definition: programinfo.cpp:3464
MARK_BOOKMARK
@ MARK_BOOKMARK
Definition: programtypes.h:57
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1372
GENERIC_EXIT_NO_RECORDING_DATA
@ GENERIC_EXIT_NO_RECORDING_DATA
No program/recording data.
Definition: exitcodes.h:30
mythtranslation.h
MythCommandLineParser::toUInt
uint toUInt(const QString &key) const
Returns stored QVariant as an unsigned integer, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2236
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1388
jobqueue.h
recorderOptions
static QString recorderOptions
Definition: mythtranscode.cpp:40
REENCODE_OK
@ REENCODE_OK
Definition: transcodedefs.h:7
ProgramInfo::SaveBasename
bool SaveBasename(const QString &basename)
Sets a recording's basename in the database.
Definition: programinfo.cpp:2468
RemoteFile::DeleteFile
static bool DeleteFile(const QString &url)
Definition: remotefile.cpp:411
uint
unsigned int uint
Definition: compat.h:81
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
MythCommandLineParser::ApplySettingsOverride
void ApplySettingsOverride(void)
Apply all overrides to the global context.
Definition: mythcommandlineparser.cpp:2916
GENERIC_EXIT_REMOTE_FILE
@ GENERIC_EXIT_REMOTE_FILE
Can't transcode a remote file.
Definition: exitcodes.h:31
ProgramInfo::GetStorageGroup
QString GetStorageGroup(void) const
Definition: programinfo.h:422
cleanup
static QString cleanup(const QString &str)
Definition: remoteencoder.cpp:673
frm_pos_map_t
QMap< long long, long long > frm_pos_map_t
Frame # -> File offset map.
Definition: programtypes.h:45
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:906
CompleteJob
static void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, frm_dir_map_t *deleteMap, int &exitCode, int resultCode, bool forceDelete)
Definition: mythtranscode.cpp:864
SignalHandler::Init
static void Init(QObject *parent=nullptr)
Definition: signalhandling.cpp:127
MARK_CUT_START
@ MARK_CUT_START
Definition: programtypes.h:56
recordinginfo.h
ProgramInfo::GetChanID
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:372
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
mythmiscutil.h
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2344
HTTPLiveStream
Definition: httplivestream.h:22
transcode.h
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2187
REPLEX_MPEG2
#define REPLEX_MPEG2
Definition: multiplex.h:43
MARK_GOP_BYFRAME
@ MARK_GOP_BYFRAME
Definition: programtypes.h:64
ProgramInfo::ClearPositionMap
void ClearPositionMap(MarkTypes type) const
Definition: programinfo.cpp:3808
cleanupguard.h
REPLEX_TS_SD
#define REPLEX_TS_SD
Definition: multiplex.h:46
glbl_jobID
static int glbl_jobID
Definition: mythtranscode.cpp:39
transUnlink
static int transUnlink(const QString &filename, ProgramInfo *pginfo)
Definition: mythtranscode.cpp:747
ProgramInfo::GetPlaybackURL
QString GetPlaybackURL(bool checkMaster=false, bool forceCheckLocal=false)
Returns filename or URL to be used to play back this recording.
Definition: programinfo.cpp:2546
formatNUV
@ formatNUV
Definition: recordingfile.h:15
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:889
MarkTypes
MarkTypes
Definition: programtypes.h:47
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:17
MythCommandLineParser::toStringList
QStringList toStringList(const QString &key, const QString &sep="") const
Returns stored QVariant as a QStringList, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2375
main
int main(int argc, char *argv[])
Definition: mythtranscode.cpp:148
UpdateJobQueue
static void UpdateJobQueue(float percent_done)
Definition: mythtranscode.cpp:94
GENERIC_EXIT_RESTART
@ GENERIC_EXIT_RESTART
Need to restart transcoding.
Definition: exitcodes.h:32
mythcontext.h
UpdatePositionMap
static void UpdatePositionMap(frm_pos_map_t &posMap, frm_pos_map_t &durMap, const QString &mapfile, ProgramInfo *pginfo)
Definition: mythtranscode.cpp:42
GENERIC_EXIT_KILLED
@ GENERIC_EXIT_KILLED
Process killed or stopped.
Definition: exitcodes.h:24
REENCODE_STOPPED
@ REENCODE_STOPPED
Definition: transcodedefs.h:9
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2849
JobQueue::ChangeJobArgs
static bool ChangeJobArgs(int jobID, const QString &args="")
Definition: jobqueue.cpp:1026
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
MythTranscodeCommandLineParser
Definition: mythtranscode_commandlineparser.h:6
MythTranslation::load
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
Definition: mythtranslation.cpp:37
exitcodes.h
MythCommandLineParser::toInt
int toInt(const QString &key) const
Returns stored QVariant as an integer, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2209
JobQueue::ChangeJobStatus
static bool ChangeJobStatus(int jobID, int newStatus, const QString &comment="")
Definition: jobqueue.cpp:974
WaitToDelete
static void WaitToDelete(ProgramInfo *pginfo)
Definition: mythtranscode.cpp:826
build_compdb.filename
filename
Definition: build_compdb.py:21
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:16
MARK_COMM_START
@ MARK_COMM_START
Definition: programtypes.h:59
JOB_TRANSCODE
@ JOB_TRANSCODE
Definition: jobqueue.h:78
MythCommandLineParser::toDateTime
QDateTime toDateTime(const QString &key) const
Returns stored QVariant as a QDateTime, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2441
gContext
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:64
MythContext::Init
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: mythcontext.cpp:1603
formatMPEG2_PS
@ formatMPEG2_PS
Definition: recordingfile.h:17
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:134
formatMPEG2_TS
@ formatMPEG2_TS
Definition: recordingfile.h:16
ProgramInfo::SavePositionMap
void SavePositionMap(frm_pos_map_t &posMap, MarkTypes type, int64_t min_frame=-1, int64_t max_frame=-1) const
Definition: programinfo.cpp:3846
Transcode
Definition: transcode.h:17
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:838
GENERIC_EXIT_DB_ERROR
@ GENERIC_EXIT_DB_ERROR
Database error.
Definition: exitcodes.h:18