1 #include "newpacket.hpp"
3 #include "output-drv.hpp"
4 #include "packet-processor.hpp"
7 #include "timeparse.hpp"
10 #define DEFAULT_RESIZE_TYPE "lanczos2"
12 int main(int argc
, char** argv
)
14 int64_t _audio_delay
= 0;
15 int64_t _subtitle_delay
= 0;
16 uint32_t _audio_rate
= 44100;
19 uint32_t _rate_num
= 0;
20 uint32_t _rate_denum
= 0;
21 uint32_t _dedup_max
= 0;
22 std::string resize_type
= DEFAULT_RESIZE_TYPE
;
23 std::map
<std::pair
<uint32_t, uint32_t>, std::string
> special_resizers
;
26 for(int i
= 1; i
< argc
; i
++) {
27 std::string arg
= argv
[i
];
32 if(!isstringprefix(arg
, "--"))
35 if(isstringprefix(arg
, "--video-width=")) {
36 std::string value
= settingvalue(arg
);
38 _width
= strtoul(value
.c_str(), &x
, 10);
40 std::cerr
<< "--video-width: Bad width" << std::endl
;
43 } else if(isstringprefix(arg
, "--video-height=")) {
44 std::string value
= settingvalue(arg
);
46 _height
= strtoul(value
.c_str(), &x
, 10);
48 std::cerr
<< "--video-height: Bad height" << std::endl
;
51 } else if(isstringprefix(arg
, "--video-scale-algo=")) {
52 std::string tmptype
= settingvalue(arg
);
55 size_t p
= tmptype
.find_first_of(" ");
56 if(p
> tmptype
.length())
57 resize_type
= settingvalue(arg
);
59 std::string tmptype_tail
= tmptype
.substr(p
+ 1);
60 tmptype
= tmptype
.substr(0, p
);
61 const char* x
= tmptype_tail
.c_str();
63 width
= (uint32_t)strtoul(x
, &end
, 10);
65 throw std::runtime_error("Bad resolution for resolution-dependent scaler (width).");
67 height
= (uint32_t)strtoul(x
, &end
, 10);
69 throw std::runtime_error("Bad resolution for resolution-dependent scaler (height).");
70 special_resizers
[std::make_pair(width
, height
)] = tmptype
;
72 } else if(isstringprefix(arg
, "--video-scale-algo-")) {
73 std::string tmptype
= settingvalue(arg
);
77 special_resizers
[std::make_pair(width
, height
)] = tmptype
;
78 } else if(arg
== "--video-framerate=auto") {
80 std::cerr
<< "Conflicts with earlier explicit fps: " << arg
<< "." << std::endl
;
84 } else if(isstringprefix(arg
, "--video-framerate=")) {
85 std::string value
= settingvalue(arg
);
87 if(_rate_num
|| _rate_denum
) {
88 std::cerr
<< "Conflicts with earlier fps: " << arg
<< "." << std::endl
;
91 _rate_num
= strtoul(value
.c_str(), &x
, 10);
92 if((*x
!= '\0' && *x
!= '/') || !_rate_num
) {
93 std::cerr
<< "--video-framerate: Bad value (n)" << std::endl
;
98 _rate_denum
= strtoul(x
, &x
, 10);
99 if(*x
|| !_rate_denum
) {
100 std::cerr
<< "--video-framerate: Bad value (d)" << std::endl
;
106 } else if(isstringprefix(arg
, "--video-max-dedup=")) {
107 std::string value
= settingvalue(arg
);
109 _dedup_max
= strtoul(value
.c_str(), &x
, 10);
111 std::cerr
<< "--video-dedup-max: Bad value" << std::endl
;
115 std::cerr
<< "Conflicts with earlier explicit fps: " << arg
<< "." << std::endl
;
119 } else if(isstringprefix(arg
, "--audio-delay=")) {
120 std::string value
= settingvalue(arg
);
121 if(value
.length() && value
[0] == '-')
122 _audio_delay
= -(int64_t)parse_timespec(value
.substr(1));
124 _audio_delay
= -(int64_t)parse_timespec(value
);
125 } else if(isstringprefix(arg
, "--subtitle-delay=")) {
126 std::string value
= settingvalue(arg
);
127 if(value
.length() && value
[0] == '-')
128 _subtitle_delay
= -(int64_t)parse_timespec(value
.substr(1));
130 _subtitle_delay
= -(int64_t)parse_timespec(value
);
131 } else if(isstringprefix(arg
, "--audio-mixer-")) {
132 //We process these later.
133 } else if(isstringprefix(arg
, "--video-hardsub-")) {
134 //We process these later.
135 } else if(isstringprefix(arg
, "--output-")) {
136 //We process these later.
138 std::cerr
<< "Bad option: " << arg
<< "." << std::endl
;
141 } catch(std::exception
& e
) {
142 std::cerr
<< "Error processing option: " << arg
<< ":" << e
.what() << std::endl
;
148 if(!_width
|| !_height
) {
149 std::cout
<< "usage: " << argv
[0] << " [<options>] [--] <filename>..." << std::endl
;
150 std::cout
<< "Convert <filename> to variety of raw formats." << std::endl
;
151 std::cout
<< "--output-<type>=<file>[,<parameters>]" << std::endl
;
152 std::cout
<< "\tSend <type> output to <file>." << std::endl
;
153 std::cout
<< "\tSupported types: " << get_output_driver_list() << std::endl
;
154 std::cout
<< "--audio-delay=<delay>" << std::endl
;
155 std::cout
<< "\tSet audio delay to <delay> (may be negative). Default 0." << std::endl
;
156 std::cout
<< "--subtitle-delay=<delay>" << std::endl
;
157 std::cout
<< "\tSet subtitle delay to <delay> (may be negative). Default 0." << std::endl
;
158 std::cout
<< "--video-width=<width>" << std::endl
;
159 std::cout
<< "\tSet video width to <width>." << std::endl
;
160 std::cout
<< "--video-height=<height>" << std::endl
;
161 std::cout
<< "\tSet video width to <height>." << std::endl
;
162 std::cout
<< "--video-scale-algo=<algo>" << std::endl
;
163 std::cout
<< "\tSet video scaling algo to <algo>." << std::endl
;
164 std::cout
<< "--video-scale-algo=<algo> <w> <h>" << std::endl
;
165 std::cout
<< "\tSet video scaling algo for <w>x<h> frames to <algo>." << std::endl
;
166 std::cout
<< "\tSupported algorithms: " << get_resizer_list() << std::endl
;
167 std::cout
<< "--video-scale-framerate=<n>[/<d>]" << std::endl
;
168 std::cout
<< "\tSet video framerate to <n>/<d>." << std::endl
;
169 std::cout
<< "--video-scale-framerate=auto" << std::endl
;
170 std::cout
<< "\tSet video framerate to variable." << std::endl
;
171 std::cout
<< "--video-max-dedup=<frames>" << std::endl
;
172 std::cout
<< "\tSet maximum consequtive frames to elide to <frames>." << std::endl
;
173 print_hardsubs_help("--video-hardsub-");
174 print_audio_resampler_help("--audio-mixer-");
179 if(!_rate_num
&& !_rate_denum
) {
184 audio_settings
asettings(_audio_rate
);
185 video_settings
vsettings(_width
, _height
, _rate_num
, _rate_denum
);
186 subtitle_settings ssettings
;
187 set_audio_parameters(asettings
);
188 set_video_parameters(vsettings
);
189 set_subtitle_parameters(ssettings
);
193 for(int i
= 1; i
< argc
; i
++) {
194 std::string arg
= argv
[i
];
199 if(!isstringprefix(arg
, "--"))
201 if(isstringprefix(arg
, "--output-")) {
204 std::string parameters
;
205 size_t x
= arg
.find_first_of("=");
206 if(x
> arg
.length()) {
207 std::cerr
<< "Bad output specification: " << arg
<< "." << std::endl
;
210 type
= arg
.substr(9, x
- 9);
211 file
= arg
.substr(x
+ 1);
212 x
= file
.find_first_of(",");
213 if(x
< file
.length()) {
214 parameters
= file
.substr(x
+ 1);
215 file
= file
.substr(0, x
);
217 add_output_driver(type
, file
, parameters
);
221 packet_processor
& p
= create_packet_processor(_audio_delay
, _subtitle_delay
, _audio_rate
, _width
, _height
,
222 _rate_num
, _rate_denum
, _dedup_max
, resize_type
, special_resizers
, argc
, argv
);
224 uint64_t timebase
= 0;
225 for(int i
= 1; i
< argc
; i
++) {
226 std::string arg
= argv
[i
];
231 if(sep
|| !isstringprefix(arg
, "--")) {
232 read_channel
rc(arg
);
233 timebase
= send_stream(p
, rc
, timebase
);
236 p
.send_end_of_stream();
237 close_output_drivers();