@@ -13,6 +13,8 @@ use std::{
13
13
use indicatif:: ProgressBar ;
14
14
use parking_lot:: Mutex ;
15
15
16
+ use re_video:: { decode:: SyncDecoder , VideoData } ;
17
+
16
18
fn main ( ) {
17
19
// frames <video.mp4>
18
20
let args: Vec < _ > = std:: env:: args ( ) . collect ( ) ;
@@ -27,17 +29,33 @@ fn main() {
27
29
let video = std:: fs:: read ( video_path) . expect ( "failed to read video" ) ;
28
30
let video = re_video:: VideoData :: load_mp4 ( & video) . expect ( "failed to load video" ) ;
29
31
30
- let sync_decoder = Box :: new (
31
- re_video:: decode:: av1:: SyncDav1dDecoder :: new ( ) . expect ( "Failed to start AV1 decoder" ) ,
32
- ) ;
33
-
34
32
println ! (
35
33
"{} {}x{}" ,
36
34
video. gops. len( ) ,
37
35
video. config. coded_width,
38
36
video. config. coded_height
39
37
) ;
40
38
39
+ let mut decoder = create_decoder ( & video) ;
40
+
41
+ write_video_frames ( & video, decoder. as_mut ( ) , & output_dir) ;
42
+ }
43
+
44
+ fn create_decoder ( video : & VideoData ) -> Box < dyn SyncDecoder > {
45
+ if video. config . is_av1 ( ) {
46
+ Box :: new (
47
+ re_video:: decode:: av1:: SyncDav1dDecoder :: new ( ) . expect ( "Failed to start AV1 decoder" ) ,
48
+ )
49
+ } else {
50
+ panic ! ( "Unsupported codec: {}" , video. human_readable_codec_string( ) ) ;
51
+ }
52
+ }
53
+
54
+ fn write_video_frames (
55
+ video : & re_video:: VideoData ,
56
+ decoder : & mut dyn re_video:: decode:: SyncDecoder ,
57
+ output_dir : & PathBuf ,
58
+ ) {
41
59
let progress = ProgressBar :: new ( video. samples . len ( ) as u64 ) . with_message ( "Decoding video" ) ;
42
60
progress. enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
43
61
@@ -50,16 +68,14 @@ fn main() {
50
68
frames. lock ( ) . push ( frame) ;
51
69
}
52
70
} ;
53
- let mut decoder =
54
- re_video:: decode:: AsyncDecoder :: new ( "debug_name" . to_owned ( ) , sync_decoder, on_output) ;
55
71
56
72
let start = Instant :: now ( ) ;
57
73
for sample in & video. samples {
58
- decoder. decode ( video. get ( sample) . unwrap ( ) ) ;
74
+ let should_stop = std:: sync:: atomic:: AtomicBool :: new ( false ) ;
75
+ let chunk = video. get ( sample) . unwrap ( ) ;
76
+ decoder. submit_chunk ( & should_stop, chunk, & on_output) ;
59
77
}
60
78
61
- decoder. flush ( ) ;
62
- drop ( decoder) ;
63
79
let end = Instant :: now ( ) ;
64
80
progress. finish ( ) ;
65
81
@@ -72,7 +88,7 @@ fn main() {
72
88
) ;
73
89
74
90
println ! ( "Writing frames to {}" , output_dir. display( ) ) ;
75
- std:: fs:: create_dir_all ( & output_dir) . expect ( "failed to create output directory" ) ;
91
+ std:: fs:: create_dir_all ( output_dir) . expect ( "failed to create output directory" ) ;
76
92
77
93
let width = num_digits ( frames. len ( ) ) ;
78
94
for ( i, frame) in frames. iter ( ) . enumerate ( ) {
0 commit comments