1
1
use std:: { fs, io, process:: Command } ;
2
2
3
- fn run_command ( command : & str ) {
4
- let cmd = Command :: new ( "sh" )
5
- . arg ( "-c" )
6
- . arg ( command)
7
- . output ( )
8
- . expect ( "Error" ) ;
3
+ fn run_command ( command : & str ) -> io:: Result < ( ) > {
4
+ let cmd = Command :: new ( "sh" ) . arg ( "-c" ) . arg ( command) . output ( ) ?;
9
5
10
6
println ! ( "status: {}" , cmd. status) ;
11
7
@@ -18,34 +14,35 @@ fn run_command(command: &str) {
18
14
let result = result. as_str ( ) ;
19
15
20
16
println ! ( "{}" , result) ;
17
+ Ok ( ( ) )
21
18
}
22
19
23
20
pub fn create_preview_gif ( input : & str , subpath : & str , output : & str ) -> io:: Result < ( ) > {
24
21
let path = format ! ( "{}/{}" , output, subpath) ;
25
22
if fs:: metadata ( & path) . is_err ( ) {
26
- fs:: create_dir_all ( & path) . unwrap ( ) ;
23
+ fs:: create_dir_all ( & path) ? ;
27
24
}
28
25
29
26
let command = format ! (
30
27
"ffmpeg -ss 30 -t 3 -i {} -vf \" fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse\" -loop 0 {}/{}.gif" , input, path, output
31
28
) ;
32
29
33
- run_command ( & command) ;
30
+ run_command ( & command) ? ;
34
31
Ok ( ( ) )
35
32
}
36
33
37
34
pub fn create_preview_image ( input : & str , subpath : & str , output : & str ) -> io:: Result < ( ) > {
38
35
let path = format ! ( "{}/{}" , output, subpath) ;
39
36
if fs:: metadata ( & path) . is_err ( ) {
40
- fs:: create_dir_all ( & path) . unwrap ( ) ;
37
+ fs:: create_dir_all ( & path) ? ;
41
38
}
42
39
43
40
let command = format ! (
44
41
"ffmpeg -i {} -vf scale=iw*sar:ih,setsar=1 -ss 00:00:05 -t 1 -vframes 1 {}/{}.jpg" ,
45
42
input, path, output
46
43
) ;
47
44
48
- run_command ( & command) ;
45
+ run_command ( & command) ? ;
49
46
Ok ( ( ) )
50
47
}
51
48
@@ -56,15 +53,15 @@ pub fn create_thumbnails(input: &str, subpath: &str, output: &str) -> io::Result
56
53
57
54
println ! ( "Path: {}" , thumbs_path) ;
58
55
if fs:: metadata ( & thumbs_path) . is_err ( ) {
59
- fs:: create_dir_all ( & thumbs_path) . unwrap ( ) ;
56
+ fs:: create_dir_all ( & thumbs_path) ? ;
60
57
}
61
58
62
59
let command = format ! (
63
60
"ffmpeg -i {} -vf \" fps=1/4,scale=320:-1\" {}/img%03d.jpg" ,
64
61
input, thumbs_path
65
62
) ;
66
63
67
- run_command ( & command) ;
64
+ run_command ( & command) ? ;
68
65
Ok ( ( ) )
69
66
}
70
67
@@ -74,15 +71,15 @@ pub fn create_hls_encoding(input: &str, subpath: &str, output: &str) -> io::Resu
74
71
let hls_path = format ! ( "{}/{}" , output, subpath) ;
75
72
76
73
if fs:: metadata ( & hls_path) . is_err ( ) {
77
- fs:: create_dir_all ( & hls_path) . unwrap ( ) ;
74
+ fs:: create_dir_all ( & hls_path) ? ;
78
75
}
79
76
80
77
// TODO: Sub add paths
81
78
// let paths = ["hls", "dash"];
82
79
// for path in paths {
83
80
// let p = format!("{}/{}", path, output);
84
81
// if !fs::metadata(&p).is_ok() {
85
- // fs::create_dir_all(&p).unwrap() ;
82
+ // fs::create_dir_all(&p)? ;
86
83
// }
87
84
// }
88
85
@@ -98,6 +95,6 @@ pub fn create_hls_encoding(input: &str, subpath: &str, output: &str) -> io::Resu
98
95
-hls_segment_filename \
99
96
-hls_playlist_type {}/vod \
100
97
{}/720p_%03d.m3u8 {}/720p.m3u8", input, hls_path, hls_path, hls_path) ;
101
- run_command ( & command) ;
98
+ run_command ( & command) ? ;
102
99
Ok ( ( ) )
103
100
}
0 commit comments