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 
11 // MythTV headers
12 #include "libmyth/mythcontext.h"
14 #include "libmythbase/exitcodes.h"
15 #include "libmythbase/mythversion.h"
20 
21 // MythCCExtractor
23 
24 namespace {
25  void cleanup()
26  {
27  delete gContext;
28  gContext = nullptr;
30  }
31 }
32 
33 static int RunCCExtract(ProgramInfo &program_info, const QString & destdir)
34 {
35  QString filename = program_info.GetPlaybackURL();
36  if (filename.startsWith("myth://"))
37  {
38  QString msg =
39  QString("Only locally accessible files are supported (%1).")
40  .arg(program_info.GetPathname());
41  std::cerr << qPrintable(msg) << std::endl;
43  }
44 
45  if (!QFile::exists(filename))
46  {
47  std::cerr << qPrintable(
48  QString("Could not open input file (%1).").arg(filename)) << std::endl;
50  }
51 
53  if (!tmprbuf)
54  {
55  std::cerr << qPrintable(QString("Unable to create RingBuffer for %1")
56  .arg(filename)) << std::endl;
58  }
59 
60  if (program_info.GetRecordingEndTime() > MythDate::current())
61  {
62  std::cout << "Program will end @ "
63  << qPrintable(program_info.GetRecordingEndTime(MythDate::ISODate))
64  << std::endl;
65  tmprbuf->SetWaitForWrite();
66  }
67 
68  auto flags = (PlayerFlags)(kVideoIsNull | kAudioMuted |
72  auto *ctx = new PlayerContext(kCCExtractorInUseID);
73  auto *ccp = new MythCCExtractorPlayer(ctx, flags, true, filename, destdir);
74  ctx->SetPlayingInfo(&program_info);
75  ctx->SetRingBuffer(tmprbuf);
76  ctx->SetPlayer(ccp);
77  if (ccp->OpenFile() < 0)
78  {
79  std::cerr << "Failed to open " << qPrintable(filename) << std::endl;
80  return GENERIC_EXIT_NOT_OK;
81  }
82  if (!ccp->run())
83  {
84  std::cerr << "Failed to decode " << qPrintable(filename) << std::endl;
85  return GENERIC_EXIT_NOT_OK;
86  }
87 
88  delete ctx;
89 
90  return GENERIC_EXIT_OK;
91 }
92 
93 int main(int argc, char *argv[])
94 {
95  QCoreApplication a(argc, argv);
96 
97  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHCCEXTRACTOR);
98 
100  if (!cmdline.Parse(argc, argv))
101  {
102  cmdline.PrintHelp();
104  }
105 
106  int retval = cmdline.ConfigureLogging("none");
107  if (retval != GENERIC_EXIT_OK)
108  return retval;
109 
110  if (cmdline.toBool("showhelp"))
111  {
112  cmdline.PrintHelp();
113  return GENERIC_EXIT_OK;
114  }
115 
116  if (cmdline.toBool("showversion"))
117  {
119  return GENERIC_EXIT_OK;
120  }
121 
122  QString infile = cmdline.toString("inputfile");
123  if (infile.isEmpty())
124  {
125  std::cerr << "The input file --infile is required" << std::endl;
127  }
128 
129  QString destdir = cmdline.toString("destdir");
130 
131  bool useDB = !QFile::exists(infile);
132 
133  CleanupGuard callCleanup(cleanup);
134 
135 #ifndef _WIN32
137 #endif
138 
139  gContext = new MythContext(MYTH_BINARY_VERSION);
140  if (!gContext->Init(
141  false/*use gui*/, false/*prompt for backend*/,
142  false/*bypass auto discovery*/, !useDB/*ignoreDB*/))
143  {
144  std::cerr << "Failed to init MythContext, exiting." << std::endl;
146  }
147 
148  ProgramInfo pginfo(infile);
149  return RunCCExtract(pginfo, destdir);
150 }
151 
152 
153 /* 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:64
kDecodeLowRes
@ kDecodeLowRes
Definition: mythplayer.h:67
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:93
MYTH_APPNAME_MYTHCCEXTRACTOR
static constexpr const char * MYTH_APPNAME_MYTHCCEXTRACTOR
Definition: mythcorecontext.h:25
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1544
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:1372
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1388
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:33
kDecodeNoDecode
@ kDecodeNoDecode
Definition: mythplayer.h:71
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:68
SignalHandler::Init
static void Init(QObject *parent=nullptr)
Definition: signalhandling.cpp:127
kVideoIsNull
@ kVideoIsNull
Definition: mythplayer.h:73
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:2344
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2187
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:70
kAudioMuted
@ kAudioMuted
Definition: mythplayer.h:74
PlayerContext
Definition: playercontext.h:49
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:2849
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:64
MythContext::Init
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: mythcontext.cpp:1603
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:134
kDecodeFewBlocks
@ kDecodeFewBlocks
Definition: mythplayer.h:69
kCCExtractorInUseID
const QString kCCExtractorInUseID
Definition: programtypes.cpp:27
MythMediaBuffer::SetWaitForWrite
void SetWaitForWrite(void)
Definition: mythmediabuffer.cpp:319