output metadata (wrongish?)

This commit is contained in:
Brandon Thomas committed 2021-05-29 13:03:19 -04:00
1 parent 6ceed517de
commit 9075f97d7a
3 files changed
+66 -30

No files matched your search

@@ -10,6 +10,7 @@ import tempfile
import shutil
import datetime
import pickle
import magic
from PIL import Image
if 'PRINT_ENV' in os.environ and os.environ['PRINT_ENV']:
@@ -334,6 +335,7 @@ def main(tempdir):
frame_w = 0
frame_h = 0
fps = 0
if not os.path.isfile(args.image_or_video_filename):
raise ValueError('image_or_video_filename is not a file')
@@ -485,6 +487,28 @@ def main(tempdir):
maybe_concatenate_end_bump(tempdir, args, frame_w, frame_h)
# ==== METADATA ====
mime_type = magic.from_file(args.output_video_filename, mime=True)
file_size_bytes = os.path.getsize(args.output_video_filename)
frame_count = len(full_frames)
duration_seconds = frame_count / fps
duration_millis = int(duration_seconds * 1000)
metadata = {
'is_video': True,
'width': frame_w,
'height': frame_h,
'num_frames': frame_count,
'fps': fps,
'duration_millis': duration_millis,
'mimetype': mime_type,
'file_size_bytes': file_size_bytes,
}
with open(args.output_metadata_filename, 'w') as json_file:
json.dump(metadata, json_file)
if __name__ == '__main__':
tempdir = tempfile.mkdtemp()
print('Using Python tempdir: {}'.format(tempdir), flush=True)
+27 -26
View File
@@ -107,32 +107,33 @@ impl SemiPersistentCacheDir {
// ==================== W2L OUTPUT RESULTS ====================
/// We cache W2L faces here.
/// We'll likely need to LRU cache them.
pub fn w2l_output_results_path(&self, temp_dir: &TempDir, inference_job_token: &str) -> PathBuf {
// NB: We don't want colons from the token in the filename.
let filename = inference_job_token.replace(":", "");
let filename = format!("{}_result.mp4", filename);
// We cache W2L faces here.
// We'll likely need to LRU cache them.
//pub fn w2l_output_results_path(&self, temp_dir: &TempDir, inference_job_token: &str) -> PathBuf {
// // NB: We don't want colons from the token in the filename.
// let filename = inference_job_token.replace(":", "");
// let filename = format!("{}_result.mp4", filename);
temp_dir.path().join(&filename)
}
// temp_dir.path().join(&filename)
//}
}
#[cfg(test)]
mod tests {
use crate::util::semi_persistent_cache_dir::SemiPersistentCacheDir;
use tempdir::TempDir;
#[test]
fn test_w2l_output_results_path() {
let dirs = SemiPersistentCacheDir::default_paths();
let temp_dir = TempDir::new("test").unwrap();
let filename = dirs.w2l_output_results_path(&temp_dir, "TYPE:TOKEN")
.to_str()
.map(|s| s.to_string())
.unwrap();
assert!(&filename.ends_with("TYPETOKEN_result.mp4"));
}
}
//#[cfg(test)]
//mod tests {
// use crate::util::semi_persistent_cache_dir::SemiPersistentCacheDir;
// use tempdir::TempDir;
//
// #[test]
// fn test_w2l_output_results_path() {
// let dirs = SemiPersistentCacheDir::default_paths();
// let temp_dir = TempDir::new("test").unwrap();
//
// let filename = dirs.w2l_output_results_path(&temp_dir, "TYPE:TOKEN")
// .to_str()
// .map(|s| s.to_string())
// .unwrap();
//
// assert!(&filename.ends_with("TYPETOKEN_result.mp4"));
// }
//}
//
+15 -4
View File
@@ -431,21 +431,32 @@ async fn process_job(inferencer: &Inferencer, job: &W2lInferenceJobRecord) -> An
// ==================== RUN INFERENCE ==================== //
let output_video_fs_path = temp_dir.path().join("output.mp4");
let output_metadata_fs_path = temp_dir.path().join("metadata.json");
let is_image = w2l_template.template_type.contains("image");
// Metadata is wrong:
// {"is_video": true, "width": 1024, "height": 768,
// "num_frames": 1, -- wrong
// "fps": 25.0, -- wrong??
// "duration_millis": 40, -- wrong
// "mimetype": "video/mp4", "file_size_bytes": 1024594}
inferencer.w2l_inference.execute(
&audio_fs_path,
&template_media_fs_path,
&face_template_fs_path,
&PathBuf::from("todo"),
&PathBuf::from("todo"),
&output_metadata_fs_path,
&output_video_fs_path,
false,
false
)?;
let output_video_fs_path = temp_dir.path().join(&audio_bucket_hash);
info!("Output filename: {:?}", &output_video_fs_path);
if true {
info!("FAKE DONE");
thread::sleep(Duration::from_millis(5000));
thread::sleep(Duration::from_millis(50000));
return Ok(());
}