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 real_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 framerate_reducer
* dropper
;
23 std::string resize_type
= DEFAULT_RESIZE_TYPE
;
24 std::map
<std::pair
<uint32_t, uint32_t>, std::string
> special_resizers
;
27 dropper
= new framerate_reducer_dropframes();
29 for(int i
= 1; i
< argc
; i
++) {
30 std::string arg
= argv
[i
];
35 if(!isstringprefix(arg
, "--"))
38 if(isstringprefix(arg
, "--video-width=")) {
39 std::string value
= settingvalue(arg
);
41 _width
= strtoul(value
.c_str(), &x
, 10);
43 std::cerr
<< "--video-width: Bad width" << std::endl
;
46 } else if(isstringprefix(arg
, "--video-height=")) {
47 std::string value
= settingvalue(arg
);
49 _height
= strtoul(value
.c_str(), &x
, 10);
51 std::cerr
<< "--video-height: Bad height" << std::endl
;
54 } else if(isstringprefix(arg
, "--video-scale-algo=")) {
55 std::string tmptype
= settingvalue(arg
);
58 size_t p
= tmptype
.find_first_of(" ");
59 if(p
> tmptype
.length())
60 resize_type
= settingvalue(arg
);
62 std::string tmptype_tail
= tmptype
.substr(p
+ 1);
63 tmptype
= tmptype
.substr(0, p
);
64 const char* x
= tmptype_tail
.c_str();
66 width
= (uint32_t)strtoul(x
, &end
, 10);
68 throw std::runtime_error("Bad resolution for resolution-dependent scaler (width).");
70 height
= (uint32_t)strtoul(x
, &end
, 10);
72 throw std::runtime_error("Bad resolution for resolution-dependent scaler (height).");
73 special_resizers
[std::make_pair(width
, height
)] = tmptype
;
75 } else if(isstringprefix(arg
, "--video-scale-algo-")) {
76 std::string tmptype
= settingvalue(arg
);
80 special_resizers
[std::make_pair(width
, height
)] = tmptype
;
81 } else if(arg
== "--video-framerate=auto") {
83 std::cerr
<< "Conflicts with earlier explicit fps: " << arg
<< "." << std::endl
;
87 } else if(isstringprefix(arg
, "--video-framerate=")) {
88 std::string value
= settingvalue(arg
);
90 if(_rate_num
|| _rate_denum
) {
91 std::cerr
<< "Conflicts with earlier fps: " << arg
<< "." << std::endl
;
94 _rate_num
= strtoul(value
.c_str(), &x
, 10);
95 if((*x
!= '\0' && *x
!= '/') || !_rate_num
) {
96 std::cerr
<< "--video-framerate: Bad value (n)" << std::endl
;
101 _rate_denum
= strtoul(x
, &x
, 10);
102 if(*x
|| !_rate_denum
) {
103 std::cerr
<< "--video-framerate: Bad value (d)" << std::endl
;
109 } else if(isstringprefix(arg
, "--video-max-dedup=")) {
110 std::string value
= settingvalue(arg
);
112 _dedup_max
= strtoul(value
.c_str(), &x
, 10);
114 std::cerr
<< "--video-dedup-max: Bad value" << std::endl
;
118 std::cerr
<< "Conflicts with earlier explicit fps: " << arg
<< "." << std::endl
;
122 } else if(isstringprefix(arg
, "--audio-delay=")) {
123 std::string value
= settingvalue(arg
);
124 if(value
.length() && value
[0] == '-')
125 _audio_delay
= -(int64_t)parse_timespec(value
.substr(1));
127 _audio_delay
= -(int64_t)parse_timespec(value
);
128 } else if(isstringprefix(arg
, "--subtitle-delay=")) {
129 std::string value
= settingvalue(arg
);
130 if(value
.length() && value
[0] == '-')
131 _subtitle_delay
= -(int64_t)parse_timespec(value
.substr(1));
133 _subtitle_delay
= -(int64_t)parse_timespec(value
);
134 } else if(isstringprefix(arg
, "--audio-mixer-")) {
135 //We process these later.
136 } else if(isstringprefix(arg
, "--video-hardsub-")) {
137 //We process these later.
138 } else if(isstringprefix(arg
, "--output-")) {
139 //We process these later.
141 std::cerr
<< "Bad option: " << arg
<< "." << std::endl
;
144 } catch(std::exception
& e
) {
145 std::cerr
<< "Error processing option: " << arg
<< ":" << e
.what() << std::endl
;
151 if(!_width
|| !_height
) {
152 std::cout
<< "usage: " << argv
[0] << " [<options>] [--] <filename>..." << std::endl
;
153 std::cout
<< "Convert <filename> to variety of raw formats." << std::endl
;
154 std::cout
<< "--output-<type>=<file>[,<parameters>]" << std::endl
;
155 std::cout
<< "\tSend <type> output to <file>." << std::endl
;
156 std::cout
<< "\tSupported types: " << get_output_driver_list() << std::endl
;
157 std::cout
<< "--audio-delay=<delay>" << std::endl
;
158 std::cout
<< "\tSet audio delay to <delay> (may be negative). Default 0." << std::endl
;
159 std::cout
<< "--subtitle-delay=<delay>" << std::endl
;
160 std::cout
<< "\tSet subtitle delay to <delay> (may be negative). Default 0." << std::endl
;
161 std::cout
<< "--video-width=<width>" << std::endl
;
162 std::cout
<< "\tSet video width to <width>." << std::endl
;
163 std::cout
<< "--video-height=<height>" << std::endl
;
164 std::cout
<< "\tSet video width to <height>." << std::endl
;
165 std::cout
<< "--video-scale-algo=<algo>" << std::endl
;
166 std::cout
<< "\tSet video scaling algo to <algo>." << std::endl
;
167 std::cout
<< "--video-scale-algo=<algo> <w> <h>" << std::endl
;
168 std::cout
<< "\tSet video scaling algo for <w>x<h> frames to <algo>." << std::endl
;
169 std::cout
<< "\tSupported algorithms: " << get_resizer_list() << std::endl
;
170 std::cout
<< "--video-scale-framerate=<n>[/<d>]" << std::endl
;
171 std::cout
<< "\tSet video framerate to <n>/<d>." << std::endl
;
172 std::cout
<< "--video-scale-framerate=auto" << std::endl
;
173 std::cout
<< "\tSet video framerate to variable." << std::endl
;
174 std::cout
<< "--video-max-dedup=<frames>" << std::endl
;
175 std::cout
<< "\tSet maximum consequtive frames to elide to <frames>." << std::endl
;
176 print_hardsubs_help("--video-hardsub-");
177 print_audio_resampler_help("--audio-mixer-");
182 if(!_rate_num
&& !_rate_denum
) {
187 audio_settings
asettings(_audio_rate
);
188 video_settings
vsettings(_width
, _height
, _rate_num
, _rate_denum
);
189 subtitle_settings ssettings
;
190 set_audio_parameters(asettings
);
191 set_video_parameters(vsettings
);
192 set_subtitle_parameters(ssettings
);
196 for(int i
= 1; i
< argc
; i
++) {
197 std::string arg
= argv
[i
];
202 if(!isstringprefix(arg
, "--"))
204 if(isstringprefix(arg
, "--output-")) {
207 std::string parameters
;
208 size_t x
= arg
.find_first_of("=");
209 if(x
> arg
.length()) {
210 std::cerr
<< "Bad output specification: " << arg
<< "." << std::endl
;
213 type
= arg
.substr(9, x
- 9);
214 file
= arg
.substr(x
+ 1);
215 x
= file
.find_first_of(",");
216 if(x
< file
.length()) {
217 parameters
= file
.substr(x
+ 1);
218 file
= file
.substr(0, x
);
220 add_output_driver(type
, file
, parameters
);
224 packet_processor
& p
= create_packet_processor(_audio_delay
, _subtitle_delay
, _audio_rate
, _width
, _height
,
225 _rate_num
, _rate_denum
, _dedup_max
, resize_type
, special_resizers
, argc
, argv
, dropper
);
227 uint64_t timebase
= 0;
228 for(int i
= 1; i
< argc
; i
++) {
229 std::string arg
= argv
[i
];
234 if(sep
|| !isstringprefix(arg
, "--")) {
235 read_channel
rc(arg
);
236 timebase
= send_stream(p
, rc
, timebase
);
239 p
.send_end_of_stream();
240 close_output_drivers();