1 #include "yuv4mpeg.hpp"
2 #include "parseval.hpp"
5 int main(int argc
, char** argv
)
7 uint64_t last_interval
= 0;
10 for(int i
= 1; i
< argc
; i
++) {
11 std::string arg
= argv
[i
];
13 if(r
= regex("--interval=([1-9][0-9]*)", arg
)) {
15 interval
= parse_value
<unsigned>(r
[1]);
16 } catch(std::exception
& e
) {
17 std::cerr
<< "timeshow: Bad interval '" << r
[1] << "'" << std::endl
;
21 std::cerr
<< "timeshow: Unrecognized option '" << arg
<< "'" << std::endl
;
28 mark_pipe_as_binary(in
);
32 struct yuv4mpeg_stream_header
strmh(in
);
33 if(strmh
.chroma
== "rgb")
34 framesize
= 3 * strmh
.width
* strmh
.height
;
35 else if(strmh
.chroma
== "420")
36 framesize
= 3 * strmh
.width
* strmh
.height
/ 2;
37 else if(strmh
.chroma
== "420p16")
38 framesize
= 6 * strmh
.width
* strmh
.height
/ 2;
39 else if(strmh
.chroma
== "422")
40 framesize
= 2 * strmh
.width
* strmh
.height
;
41 else if(strmh
.chroma
== "422p16")
42 framesize
= 4 * strmh
.width
* strmh
.height
;
43 else if(strmh
.chroma
== "444")
44 framesize
= 3 * strmh
.width
* strmh
.height
;
45 else if(strmh
.chroma
== "444p16")
46 framesize
= 6 * strmh
.width
* strmh
.height
;
48 throw std::runtime_error("Unsupported input chroma type '" + strmh
.chroma
+ "'");
49 bool vfr
= strmh
.find_extension("VFR");
51 uint64_t duration
= 0;
52 std::string _framh
, _framh2
;
53 std::vector
<char> buffer
;
54 buffer
.resize(framesize
);
55 double framerate
= (strmh
.fps_n
&& strmh
.fps_d
) ? (1.0 * strmh
.fps_n
/ strmh
.fps_d
) : 25;
58 if(!read_line2(in
, _framh
))
60 read_or_die(in
, &buffer
[0], buffer
.size());
61 struct yuv4mpeg_frame_header
framh(_framh
);
62 duration
+= (vfr
? framh
.duration
: 1);
63 uint64_t seconds
= duration
/ framerate
;
64 uint64_t cur_interval
= seconds
/ interval
;
65 if(cur_interval
> last_interval
) {
66 last_interval
= cur_interval
;
67 std::cerr
<< "timeshow: " << seconds
<< "s done.\e[K" << std::endl
;
70 } catch(std::exception
& e
) {
71 std::cerr
<< "timeshow: Error: " << e
.what() << std::endl
;