1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
///////////////////////////////////////////////////////////////////////////////
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is MP4v2.
//
// The Initial Developer of the Original Code is Kona Blend.
// Portions created by Kona Blend are Copyright (C) 2008.
// All Rights Reserved.
//
// Contributors:
// Kona Blend, kona8lend@@gmail.com
// Edward Groenendaal, egroenen@@cisco.com
//
///////////////////////////////////////////////////////////////////////////////
#include "util/impl.h"
namespace mp4v2 { namespace util {
///////////////////////////////////////////////////////////////////////////////
class SubtitleUtility : public Utility
{
private:
enum SubtitleLongCode {
LC_LIST = _LC_MAX,
LC_EXPORT,
LC_IMPORT,
LC_REMOVE,
};
public:
SubtitleUtility( int, char** );
protected:
// delegates implementation
bool utility_option( int, bool& );
bool utility_job( JobContext& );
private:
bool actionList ( JobContext& );
bool actionExport ( JobContext& );
bool actionImport ( JobContext& );
bool actionRemove ( JobContext& );
private:
Group _actionGroup;
bool (SubtitleUtility::*_action)( JobContext& );
string _stTextFile;
};
///////////////////////////////////////////////////////////////////////////////
SubtitleUtility::SubtitleUtility( int argc, char** argv )
: Utility ( "mp4subtitle", argc, argv )
, _actionGroup ( "ACTIONS" )
, _action ( NULL )
{
// add standard options which make sense for this utility
_group.add( STD_OPTIMIZE );
_group.add( STD_DRYRUN );
_group.add( STD_KEEPGOING );
_group.add( STD_OVERWRITE );
_group.add( STD_FORCE );
_group.add( STD_QUIET );
_group.add( STD_DEBUG );
_group.add( STD_VERBOSE );
_group.add( STD_HELP );
_group.add( STD_VERSION );
_group.add( STD_VERSIONX );
_actionGroup.add( "list", false, LC_LIST, "list available subtitles" );
_actionGroup.add( "export", true, LC_EXPORT, "export subtitles to TXT", "TXT" );
_actionGroup.add( "import", true, LC_IMPORT, "import subtitles from TXT", "TXT" );
_actionGroup.add( "remove", false, LC_REMOVE, "remove all subtitles" );
_groups.push_back( &_actionGroup );
_usage = "[OPTION]... ACTION file...";
_description =
// 79-cols, inclusive, max desired width
// |----------------------------------------------------------------------------|
"\nFor each mp4 file specified, perform the specified ACTION. An action must be"
"\nspecified. Some options are not applicable to some actions.";
}
///////////////////////////////////////////////////////////////////////////////
bool
SubtitleUtility::actionExport( JobContext& job )
{
job.fileHandle = MP4Read( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for read: %s\n", job.file.c_str() );
verbose1f( "NOT IMPLEMENTED\n" );
return FAILURE;
}
///////////////////////////////////////////////////////////////////////////////
bool
SubtitleUtility::actionImport( JobContext& job )
{
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
verbose1f( "NOT IMPLEMENTED\n" );
return FAILURE;
}
///////////////////////////////////////////////////////////////////////////////
bool
SubtitleUtility::actionList( JobContext& job )
{
job.fileHandle = MP4Read( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for read: %s\n", job.file.c_str() );
verbose1f( "NOT IMPLEMENTED\n" );
return FAILURE;
}
///////////////////////////////////////////////////////////////////////////////
bool
SubtitleUtility::actionRemove( JobContext& job )
{
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
verbose1f( "NOT IMPLEMENTED" );
return FAILURE;
}
///////////////////////////////////////////////////////////////////////////////
bool
SubtitleUtility::utility_job( JobContext& job )
{
if( !_action )
return herrf( "no action specified\n" );
return (this->*_action)( job );
}
///////////////////////////////////////////////////////////////////////////////
bool
SubtitleUtility::utility_option( int code, bool& handled )
{
handled = true;
switch( code ) {
case LC_LIST:
_action = &SubtitleUtility::actionList;
break;
case LC_EXPORT:
_action = &SubtitleUtility::actionExport;
_stTextFile = prog::optarg;
if( _stTextFile.empty() )
return herrf( "invalid TXT file: empty-string\n" );
break;
case LC_IMPORT:
_action = &SubtitleUtility::actionImport;
_stTextFile = prog::optarg;
if( _stTextFile.empty() )
return herrf( "invalid TXT file: empty-string\n" );
break;
case LC_REMOVE:
_action = &SubtitleUtility::actionRemove;
break;
default:
handled = false;
break;
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
}} // namespace mp4v2::util
///////////////////////////////////////////////////////////////////////////////
extern "C"
int main( int argc, char** argv )
{
mp4v2::util::SubtitleUtility util( argc, argv );
return util.process();
}
|