1 #include "yuv4mpeg.hpp"
2 #include "parseval.hpp"
6 int main(int argc
, char** argv
)
13 for(int i
= 1; i
< argc
; i
++) {
14 std::string arg
= argv
[i
];
16 if(r
= regex("--duration=([1-9][0-9]*)", arg
)) {
19 fps_d
= parse_value
<unsigned>(r
[1]);
20 } catch(std::exception
& e
) {
21 std::cerr
<< "imgload: Bad duration '" << r
[1] << "'" << std::endl
;
24 } else if(r
= regex("--duration=([1-9][0-9]*)/([1-9][0-9]*)", arg
)) {
26 fps_n
= parse_value
<unsigned>(r
[2]);
27 fps_d
= parse_value
<unsigned>(r
[1]);
28 } catch(std::exception
& e
) {
29 std::cerr
<< "imgload: Bad duration '" << r
[1] << "/" << r
[2] << "'" << std::endl
;
32 } else if(r
= regex("--interlace=top", arg
)) {
34 } else if(r
= regex("--interlace=bottom", arg
)) {
36 } else if(r
= regex("--.*", arg
)) {
37 std::cerr
<< "imgload: Unrecognized option '" << arg
<< "'" << std::endl
;
41 std::cerr
<< "imgload: Only one image can be specified" << std::endl
;
49 std::cerr
<< "imgload: Image to load required" << std::endl
;
54 FILE* in
= fopen(imgfile
.c_str(), "rb");
56 std::cerr
<< "imgload: Can't open '" << imgfile
<< "'" << std::endl
;
60 mark_pipe_as_binary(out
);
64 yuv4mpeg_stream_header phdr
;
66 parsed_png
image(imgfile
);
68 phdr
.width
= image
.width
;
69 phdr
.height
= image
.height
;
71 phdr
.interlace
= interlace
;
74 write_or_die(out
, static_cast<std::string
>(phdr
));
76 yuv4mpeg_frame_header framh
;
77 std::vector
<char> buffer
;
78 buffer
.resize(3 * phdr
.width
* phdr
.height
);
80 for(size_t i
= 0; i
< phdr
.width
* phdr
.height
; i
++) {
81 buffer
[3 * i
+ 0] = image
.data
[i
];
82 buffer
[3 * i
+ 1] = image
.data
[i
] >> 8;
83 buffer
[3 * i
+ 2] = image
.data
[i
] >> 16;
86 write_or_die(out
, std::string(framh
));
87 write_or_die(out
, &buffer
[0], buffer
.size());
90 } catch(std::exception
& e
) {
91 std::cerr
<< "imgload: Error: " << e
.what() << std::endl
;