1 #include "yuv4mpeg.hpp"
2 #include "parseval.hpp"
4 #include "rendertext.hpp"
7 int main(int argc
, char** argv
)
9 subtitle_render_context rctx
;
10 std::vector
<pre_subtitle
*> presubs
;
12 for(int i
= 1; i
< argc
; i
++) {
13 std::string arg
= argv
[i
];
15 if(!rctx
.argument(arg
, presubs
)) {
16 std::cerr
<< "subtitle: Unrecognized option '" << arg
<< "'" << std::endl
;
19 } catch(std::exception
& e
) {
20 std::cerr
<< "subtitle: Error in option '" << arg
<< "': " << e
.what() << std::endl
;
28 mark_pipe_as_binary(in
);
29 mark_pipe_as_binary(out
);
33 struct yuv4mpeg_stream_header
strmh(in
);
34 if(strmh
.chroma
== "rgb")
35 framesize
= 3 * strmh
.width
* strmh
.height
;
36 else if(strmh
.chroma
== "420")
37 framesize
= 3 * strmh
.width
* strmh
.height
/ 2;
38 else if(strmh
.chroma
== "420p16")
39 framesize
= 6 * strmh
.width
* strmh
.height
/ 2;
40 else if(strmh
.chroma
== "422")
41 framesize
= 2 * strmh
.width
* strmh
.height
;
42 else if(strmh
.chroma
== "422p16")
43 framesize
= 4 * strmh
.width
* strmh
.height
;
44 else if(strmh
.chroma
== "444")
45 framesize
= 3 * strmh
.width
* strmh
.height
;
46 else if(strmh
.chroma
== "444p16")
47 framesize
= 6 * strmh
.width
* strmh
.height
;
49 throw std::runtime_error("Unsupported input chroma type '" + strmh
.chroma
+ "'");
50 std::vector
<subtitle
*> subs
= subtitle::from_presub(presubs
, strmh
);
51 write_or_die(out
, static_cast<std::string
>(strmh
));
53 uint64_t curframe
= 0;
54 std::string _framh
, _framh2
;
55 std::vector
<char> buffer
;
56 buffer
.resize(framesize
);
57 struct yuv4mpeg_frame_header framh
;
62 unsigned duration
= 1;
63 if(!read_line2(in
, _framh
))
65 framh
= yuv4mpeg_frame_header(_framh
);
66 read_or_die(in
, &buffer
[0], buffer
.size());
67 duration
= framh
.duration
;
69 i
->stamp(reinterpret_cast<uint8_t*>(&buffer
[0]), strmh
.width
, strmh
.height
, curframe
);
70 write_or_die(out
, static_cast<std::string
>(framh
));
71 write_or_die(out
, &buffer
[0], buffer
.size());
74 } catch(std::exception
& e
) {
75 std::cerr
<< "subtitle: Error: " << e
.what() << std::endl
;