11use crate :: models:: error:: HandlerError ;
2+ use image:: EncodableLayout ;
23use log:: { debug, warn} ;
34use std:: fs:: File ;
45use std:: io;
@@ -7,6 +8,8 @@ use std::path::Path;
78use std:: process:: { Command , Output } ;
89use uuid:: Uuid ;
910
11+ const DEFAULT_AUDIO : & [ u8 ] = include_bytes ! ( "../../assets/input.mp3" ) ;
12+
1013pub fn encode_video_local ( frame : Vec < u8 > , audio : Option < Vec < u8 > > ) -> Result < Vec < u8 > , HandlerError > {
1114 debug ! ( "--->>> encode_video LOCAL" ) ;
1215
@@ -34,15 +37,14 @@ pub fn encode_video_local(frame: Vec<u8>, audio: Option<Vec<u8>>) -> Result<Vec<
3437 "-i" ,
3538 jpg_file. as_str ( ) ,
3639 ] ) ;
37- if let Some ( audio) = audio {
38- File :: create ( mp3_file. as_str ( ) )
39- . expect ( "Unable to create image file" )
40- . write_all ( & * audio)
41- . expect ( "Unable to write image data" ) ;
42- args. extend_from_slice ( & [ "-i" , mp3_file. as_str ( ) ] ) ;
43- } else {
44- args. extend_from_slice ( & [ "-i" , "assets/input.mp3" ] ) ;
40+ let mut audio_file = File :: create ( mp3_file. as_str ( ) )
41+ . expect ( "Unable to create audio file" ) ;
42+ match audio {
43+ None => audio_file. write_all ( DEFAULT_AUDIO ) ,
44+ Some ( data) => audio_file. write_all ( data. as_bytes ( ) )
4545 }
46+ . expect ( "Unable to write audio data" ) ;
47+ args. extend_from_slice ( & [ "-i" , mp3_file. as_str ( ) ] ) ;
4648 args. extend_from_slice ( & [
4749 "-c:v" ,
4850 "libx264" ,
0 commit comments