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"
15#include "libmythbase/mythversion.h"
19
20// MythCCExtractor
22
23static int RunCCExtract(ProgramInfo &program_info, const QString & destdir)
24{
25 QString filename = program_info.GetPlaybackURL();
26 if (filename.startsWith("myth://"))
27 {
28 QString msg =
29 QString("Only locally accessible files are supported (%1).")
30 .arg(program_info.GetPathname());
31 std::cerr << qPrintable(msg) << std::endl;
33 }
34
36 {
37 std::cerr << qPrintable(
38 QString("Could not open input file (%1).").arg(filename)) << std::endl;
40 }
41
43 if (!tmprbuf)
44 {
45 std::cerr << qPrintable(QString("Unable to create RingBuffer for %1")
46 .arg(filename)) << std::endl;
48 }
49
50 if (program_info.GetRecordingEndTime() > MythDate::current())
51 {
52 std::cout << "Program will end @ "
53 << qPrintable(program_info.GetRecordingEndTime(MythDate::ISODate))
54 << std::endl;
55 tmprbuf->SetWaitForWrite();
56 }
57
58 auto flags = (PlayerFlags)(kVideoIsNull | kAudioMuted |
62 auto *ctx = new PlayerContext(kCCExtractorInUseID);
63 auto *ccp = new MythCCExtractorPlayer(ctx, flags, true, filename, destdir);
64 ctx->SetPlayingInfo(&program_info);
65 ctx->SetRingBuffer(tmprbuf);
66 ctx->SetPlayer(ccp);
67 if (ccp->OpenFile() < 0)
68 {
69 std::cerr << "Failed to open " << qPrintable(filename) << std::endl;
71 }
72 if (!ccp->run())
73 {
74 std::cerr << "Failed to decode " << qPrintable(filename) << std::endl;
76 }
77
78 delete ctx;
79
80 return GENERIC_EXIT_OK;
81}
82
83int main(int argc, char *argv[])
84{
85 QCoreApplication a(argc, argv);
86
87 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHCCEXTRACTOR);
88
90 if (!cmdline.Parse(argc, argv))
91 {
94 }
95
96 int retval = cmdline.ConfigureLogging("none");
97 if (retval != GENERIC_EXIT_OK)
98 return retval;
99
100 if (cmdline.toBool("showhelp"))
101 {
103 return GENERIC_EXIT_OK;
104 }
105
106 if (cmdline.toBool("showversion"))
107 {
109 return GENERIC_EXIT_OK;
110 }
111
112 QString infile = cmdline.toString("inputfile");
113 if (infile.isEmpty())
114 {
115 std::cerr << "The input file --infile is required" << std::endl;
117 }
118
119 QString destdir = cmdline.toString("destdir");
120
121 bool useDB = !QFile::exists(infile);
122
123 MythContext context {MYTH_BINARY_VERSION};
124 if (!context.Init(
125 false/*use gui*/, false/*prompt for backend*/,
126 false/*bypass auto discovery*/, !useDB/*ignoreDB*/))
127 {
128 std::cerr << "Failed to init MythContext, exiting." << std::endl;
130 }
131
132 ProgramInfo pginfo(infile);
133 return RunCCExtract(pginfo, destdir);
134}
135
136
137/* vim: set expandtab tabstop=4 shiftwidth=4: */
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
static void PrintVersion(void)
Print application version information.
void PrintHelp(void) const
Print command line option help.
Startup context for MythTV.
Definition: mythcontext.h:20
static MythMediaBuffer * Create(const QString &Filename, bool Write, bool UseReadAhead=true, std::chrono::milliseconds Timeout=kDefaultOpenTimeout, bool StreamOnly=false)
Creates a RingBuffer instance.
void SetWaitForWrite(void)
Holds information on recordings and videos.
Definition: programinfo.h:68
QString GetPathname(void) const
Definition: programinfo.h:344
QString GetPlaybackURL(bool checkMaster=false, bool forceCheckLocal=false)
Returns filename or URL to be used to play back this recording.
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:413
@ GENERIC_EXIT_PERMISSIONS_ERROR
File permissions error.
Definition: exitcodes.h:22
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:14
static constexpr const char * MYTH_APPNAME_MYTHCCEXTRACTOR
Definition: mythappname.h:10
int main(int argc, char *argv[])
static int RunCCExtract(ProgramInfo &program_info, const QString &destdir)
MythCommFlagCommandLineParser cmdline
PlayerFlags
Definition: mythplayer.h:65
@ kDecodeLowRes
Definition: mythplayer.h:67
@ kAudioMuted
Definition: mythplayer.h:74
@ kDecodeFewBlocks
Definition: mythplayer.h:69
@ kDecodeNoDecode
Definition: mythplayer.h:71
@ kDecodeNoLoopFilter
Definition: mythplayer.h:70
@ kDecodeSingleThreaded
Definition: mythplayer.h:68
@ kVideoIsNull
Definition: mythplayer.h:73
@ ISODate
Default UTC.
Definition: mythdate.h:17
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
bool exists(str path)
Definition: xbmcvfs.py:51
const QString kCCExtractorInUseID