Skip to content

Commit 136cfed

Browse files
committed
store default audio as include_bytes
1 parent c456215 commit 136cfed

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/engine/local_ffmpeg.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::models::error::HandlerError;
2+
use image::EncodableLayout;
23
use log::{debug, warn};
34
use std::fs::File;
45
use std::io;
@@ -7,6 +8,8 @@ use std::path::Path;
78
use std::process::{Command, Output};
89
use uuid::Uuid;
910

11+
const DEFAULT_AUDIO: &[u8] = include_bytes!("../../assets/input.mp3");
12+
1013
pub 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

Comments
 (0)