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
;
97 _rate_denum
= strtoul(x
, &x
, 10);
98 if(*x
|| !_rate_denum
) {
99 std::cerr
<< "--video-framerate: Bad value (d)" << std::endl
;
105 } else if(isstringprefix(arg
, "--video-max-dedup=")) {
106 std::string value
= settingvalue(arg
);
108 _dedup_max
= strtoul(value
.c_str(), &x
, 10);
110 std::cerr
<< "--video-dedup-max: Bad value" << std::endl
;
114 std::cerr
<< "Conflicts with earlier explicit fps: " << arg
<< "." << std::endl
;
118 } else if(isstringprefix(arg
, "--audio-delay=")) {
119 std::string value
= settingvalue(arg
);
120 if(value
.length() && value
[0] == '-')
121 _audio_delay
= -(int64_t)parse_timespec(value
.substr(1));
123 _audio_delay
= -(int64_t)parse_timespec(value
);
124 } else if(isstringprefix(arg
, "--subtitle-delay=")) {
125 std::string value
= settingvalue(arg
);
126 if(value
.length() && value
[0] == '-')
127 _subtitle_delay
= -(int64_t)parse_timespec(value
.substr(1));
129 _subtitle_delay
= -(int64_t)parse_timespec(value
);
130 } else if(isstringprefix(arg
, "--audio-mixer-")) {
131 //We process these later.
132 } else if(isstringprefix(arg
, "--video-hardsub-")) {
133 //We process these later.
134 } else if(isstringprefix(arg
, "--output-")) {
135 //We process these later.
137 std::cerr
<< "Bad option: " << arg
<< "." << std::endl
;
140 } catch(std::exception
& e
) {
141 std::cerr
<< "Error processing option: " << arg
<< ":" << e
.what() << std::endl
;
147 if(!_width
|| !_height
) {
148 std::cout
<< "usage: " << argv
[0] << " [<options>] [--] <filename>..." << std::endl
;
149 std::cout
<< "Convert <filename> to variety of raw formats." << std::endl
;
150 std::cout
<< "--output-<type>=<file>[,<parameters>]" << std::endl
;
151 std::cout
<< "\tSend <type> output to <file>." << std::endl
;
152 std::cout
<< "\tSupported types: " << get_output_driver_list() << std::endl
;
153 std::cout
<< "--audio-delay=<delay>" << std::endl
;
154 std::cout
<< "\tSet audio delay to <delay> (may be negative). Default 0." << std::endl
;
155 std::cout
<< "--subtitle-delay=<delay>" << std::endl
;
156 std::cout
<< "\tSet subtitle delay to <delay> (may be negative). Default 0." << std::endl
;
157 std::cout
<< "--video-width=<width>" << std::endl
;
158 std::cout
<< "\tSet video width to <width>." << std::endl
;
159 std::cout
<< "--video-height=<height>" << std::endl
;
160 std::cout
<< "\tSet video width to <height>." << std::endl
;
161 std::cout
<< "--video-scale-algo=<algo>" << std::endl
;
162 std::cout
<< "\tSet video scaling algo to <algo>." << std::endl
;
163 std::cout
<< "--video-scale-algo=<algo> <w> <h>" << std::endl
;
164 std::cout
<< "\tSet video scaling algo for <w>x<h> frames to <algo>." << std::endl
;
165 std::cout
<< "\tSupported algorithms: " << get_resizer_list() << std::endl
;
166 std::cout
<< "--video-scale-framerate=<n>[/<d>]" << std::endl
;
167 std::cout
<< "\tSet video framerate to <n>/<d>." << std::endl
;
168 std::cout
<< "--video-scale-framerate=auto" << std::endl
;
169 std::cout
<< "\tSet video framerate to variable." << std::endl
;
170 std::cout
<< "--video-max-dedup=<frames>" << std::endl
;
171 std::cout
<< "\tSet maximum consequtive frames to elide to <frames>." << std::endl
;
172 print_hardsubs_help("--video-hardsub-");
173 print_audio_resampler_help("--audio-mixer-");
178 if(!_rate_num
&& !_rate_denum
) {
183 audio_settings
asettings(_audio_rate
);
184 video_settings
vsettings(_width
, _height
, _rate_num
, _rate_denum
);
185 subtitle_settings ssettings
;
186 set_audio_parameters(asettings
);
187 set_video_parameters(vsettings
);
188 set_subtitle_parameters(ssettings
);
192 for(int i
= 1; i
< argc
; i
++) {
193 std::string arg
= argv
[i
];
198 if(!isstringprefix(arg
, "--"))
200 if(isstringprefix(arg
, "--output-")) {
203 std::string parameters
;
204 size_t x
= arg
.find_first_of("=");
205 if(x
> arg
.length()) {
206 std::cerr
<< "Bad output specification: " << arg
<< "." << std::endl
;
209 type
= arg
.substr(9, x
- 9);
210 file
= arg
.substr(x
+ 1);
211 x
= file
.find_first_of(",");
212 if(x
< file
.length()) {
213 parameters
= file
.substr(x
+ 1);
214 file
= file
.substr(0, x
);
216 add_output_driver(type
, file
, parameters
);
220 packet_processor
& p
= create_packet_processor(_audio_delay
, _subtitle_delay
, _audio_rate
, _width
, _height
,
221 _rate_num
, _rate_denum
, _dedup_max
, resize_type
, special_resizers
, argc
, argv
);
223 uint64_t timebase
= 0;
224 for(int i
= 1; i
< argc
; i
++) {
225 std::string arg
= argv
[i
];
230 if(sep
|| !isstringprefix(arg
, "--")) {
231 read_channel
rc(arg
);
232 timebase
= send_stream(p
, rc
, timebase
);
235 p
.send_end_of_stream();
236 close_output_drivers();