1 #include "yuv4mpeg.hpp"
2 #include "parseval.hpp"
5 int main(int argc
, char** argv
)
7 const char* interlace_types
= "bpt";
8 size_t width
= 0, height
= 0;
9 uint32_t fps_n
= 0, fps_d
= 0;
10 uint32_t sar_n
= 0, sar_d
= 0;
12 for(int i
= 1; i
< argc
; i
++) {
13 std::string arg
= argv
[i
];
15 if(r
= regex("--resolution=([1-9][0-9]*)x([1-9][0-9]*)", arg
)) {
16 width
= parse_value
<uint32_t>(r
[1]);
17 height
= parse_value
<uint32_t>(r
[2]);
18 } else if(r
= regex("--fps=([1-9][0-9]*)/([1-9][0-9]*)", arg
)) {
19 fps_n
= parse_value
<uint32_t>(r
[1]);
20 fps_d
= parse_value
<uint32_t>(r
[2]);
21 } else if(r
= regex("--fps=([1-9][0-9]*)", arg
)) {
22 fps_n
= parse_value
<uint32_t>(r
[1]);
24 } else if(r
= regex("--sar=([1-9][0-9]*)/([1-9][0-9]*)", arg
)) {
25 sar_n
= parse_value
<uint32_t>(r
[1]);
26 sar_d
= parse_value
<uint32_t>(r
[2]);
27 } else if(r
= regex("--progressive", arg
)) {
29 } else if(r
= regex("--interlace=top", arg
)) {
31 } else if(r
= regex("--interlace=bottom", arg
)) {
34 std::cerr
<< "rawtoy4m: Unrecognized option '" << arg
<< "'" << std::endl
;
38 if(!width
|| !height
) {
39 std::cerr
<< "rawtoy4m: --resolution=<w>x<h> required" << std::endl
;
46 mark_pipe_as_binary(in
);
47 mark_pipe_as_binary(out
);
50 struct yuv4mpeg_stream_header strmh
;
52 strmh
.height
= height
;
54 strmh
.interlace
= interlace_types
[interlace
+ 1];
59 std::string _strmh
= std::string(strmh
);
60 write_or_die(out
, _strmh
);
62 std::vector
<char> buffer
;
63 buffer
.resize(3 * width
* height
);
66 if(!read_or_die2(in
, &buffer
[0], buffer
.size()))
68 struct yuv4mpeg_frame_header framh
;
69 std::string _framh
= std::string(framh
);
70 write_or_die(out
, _framh
);
71 write_or_die(out
, &buffer
[0], buffer
.size());