MythTV  master
mythccextractor.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 // C++ headers
4 #include <iostream>
5 
6 // Qt headers
7 #include <QtGlobal>
8 #include <QCoreApplication>
9 #include <QString>
10 #include <QtCore>
11 #include <QtGui>
12 
13 // MythTV headers
14 #include "libmyth/mythcontext.h"
16 #include "libmythbase/exitcodes.h"
17 #include "libmythbase/mythversion.h"
22 
23 // MythCCExtractor
25 
26 namespace {
27  void cleanup()
28  {
29  delete gContext;
30  gContext = nullptr;
32  }
33 }
34 
35 static int RunCCExtract(ProgramInfo &program_info, const QString & destdir)
36 {
37  QString filename = program_info.GetPlaybackURL();
38  if (filename.startsWith("myth://"))
39  {
40  QString msg =
41  QString("Only locally accessible files are supported (%1).")
42  .arg(program_info.GetPathname());
43  std::cerr << qPrintable(msg) << std::endl;
45  }
46 
47  if (!QFile::exists(filename))
48  {
49  std::cerr << qPrintable(
50  QString("Could not open input file (%1).").arg(filename)) << std::endl;
52  }
53 
55  if (!tmprbuf)
56  {
57  std::cerr << qPrintable(QString("Unable to create RingBuffer for %1")
58  .arg(filename)) << std::endl;
60  }
61 
62  if (program_info.GetRecordingEndTime() > MythDate::current())
63  {
64  std::cout << "Program will end @ "
65  << qPrintable(program_info.GetRecordingEndTime(MythDate::ISODate))
66  << std::endl;
67  tmprbuf->SetWaitForWrite();
68  }
69 
70  auto flags = (PlayerFlags)(kVideoIsNull | kAudioMuted |
74  auto *ctx = new PlayerContext(kCCExtractorInUseID);
75  auto *ccp = new MythCCExtractorPlayer(ctx, flags, true, filename, destdir);
76  ctx->SetPlayingInfo(&program_info);
77  ctx->SetRingBuffer(tmprbuf);
78  ctx->SetPlayer(ccp);
79  if (ccp->OpenFile() < 0)
80  {
81  std::cerr << "Failed to open " << qPrintable(filename) << std::endl;
82  return GENERIC_EXIT_NOT_OK;
83  }
84  if (!ccp->run())
85  {
86  std::cerr << "Failed to decode " << qPrintable(filename) << std::endl;
87  return GENERIC_EXIT_NOT_OK;
88  }
89 
90  delete ctx;
91 
92  return GENERIC_EXIT_OK;
93 }
94 
95 int main(int argc, char *argv[])
96 {
97  QCoreApplication a(argc, argv);
98 
99  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHCCEXTRACTOR);
100 
102  if (!cmdline.Parse(argc, argv))
103  {
104  cmdline.PrintHelp();
106  }
107 
108  int retval = cmdline.ConfigureLogging("none");
109  if (retval != GENERIC_EXIT_OK)
110  return retval;
111 
112  if (cmdline.toBool("showhelp"))
113  {
114  cmdline.PrintHelp();
115  return GENERIC_EXIT_OK;
116  }
117 
118  if (cmdline.toBool("showversion"))
119  {
121  return GENERIC_EXIT_OK;
122  }
123 
124  QString infile = cmdline.toString("inputfile");
125  if (infile.isEmpty())
126  {
127  std::cerr << "The input file --infile is required" << std::endl;
129  }
130 
131  QString destdir = cmdline.toString("destdir");
132 
133  bool useDB = !QFile::exists(infile);
134 
135  CleanupGuard callCleanup(cleanup);
136 
137 #ifndef _WIN32
139 #endif
140 
141  gContext = new MythContext(MYTH_BINARY_VERSION);
142  if (!gContext->Init(
143  false/*use gui*/, false/*prompt for backend*/,
144  false/*bypass auto discovery*/, !useDB/*ignoreDB*/))
145  {
146  std::cerr << "Failed to init MythContext, exiting." << std::endl;
148  }
149 
150  ProgramInfo pginfo(infile);
151  return RunCCExtract(pginfo, destdir);
152 }
153 
154 
155 /* vim: set expandtab tabstop=4 shiftwidth=4: */
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:72
MythContext
Startup context for MythTV.
Definition: mythcontext.h:43
MythMediaBuffer
Definition: mythmediabuffer.h:50
PlayerFlags
PlayerFlags
Definition: mythplayer.h:65
kDecodeLowRes
@ kDecodeLowRes
Definition: mythplayer.h:68
ProgramInfo::GetRecordingEndTime
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:412
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:11
MythCCExtractorPlayer
Definition: mythccextractorplayer.h:112
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
ProgramInfo::GetPathname
QString GetPathname(void) const
Definition: programinfo.h:343
main
int main(int argc, char *argv[])
Definition: mythccextractor.cpp:95
MYTH_APPNAME_MYTHCCEXTRACTOR
static constexpr const char * MYTH_APPNAME_MYTHCCEXTRACTOR
Definition: mythcorecontext.h:26
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1553
programinfo.h
GENERIC_EXIT_NO_MYTHCONTEXT
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:14
signalhandling.h
CleanupGuard
Definition: cleanupguard.h:6
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1381
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1397
GENERIC_EXIT_NOT_OK
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:12
RunCCExtract
static int RunCCExtract(ProgramInfo &program_info, const QString &destdir)
Definition: mythccextractor.cpp:35
kDecodeNoDecode
@ kDecodeNoDecode
Definition: mythplayer.h:72
GENERIC_EXIT_PERMISSIONS_ERROR
@ GENERIC_EXIT_PERMISSIONS_ERROR
File permissions error.
Definition: exitcodes.h:20
mythccextractorplayer.h
cleanup
static QString cleanup(const QString &str)
Definition: remoteencoder.cpp:673
mythmediabuffer.h
kDecodeSingleThreaded
@ kDecodeSingleThreaded
Definition: mythplayer.h:69
SignalHandler::Init
static void Init(QObject *parent=nullptr)
Definition: signalhandling.cpp:127
kVideoIsNull
@ kVideoIsNull
Definition: mythplayer.h:74
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2358
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2201
cleanupguard.h
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
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:17
mythcontext.h
kDecodeNoLoopFilter
@ kDecodeNoLoopFilter
Definition: mythplayer.h:71
kAudioMuted
@ kAudioMuted
Definition: mythplayer.h:75
PlayerContext
Definition: playercontext.h:53
MythMediaBuffer::Create
static MythMediaBuffer * Create(const QString &Filename, bool Write, bool UseReadAhead=true, std::chrono::milliseconds Timeout=kDefaultOpenTimeout, bool StreamOnly=false)
Creates a RingBuffer instance.
Definition: mythmediabuffer.cpp:98
mythccextractor_commandlineparser.h
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2863
exitcodes.h
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
MythCCExtractorCommandLineParser
Definition: mythccextractor_commandlineparser.h:8
gContext
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:57
MythContext::Init
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: mythcontext.cpp:1594
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:134
kDecodeFewBlocks
@ kDecodeFewBlocks
Definition: mythplayer.h:70
kCCExtractorInUseID
const QString kCCExtractorInUseID
Definition: programtypes.cpp:27
MythMediaBuffer::SetWaitForWrite
void SetWaitForWrite(void)
Definition: mythmediabuffer.cpp:319