mirror of
https://github.com/master-of-zen/Av1an.git
synced 2024-11-25 02:29:40 +00:00
ffmpeg module to rust.
Ported get frame types
This commit is contained in:
parent
b09a3a615d
commit
df68733e93
4 changed files with 43 additions and 46 deletions
|
@ -220,3 +220,38 @@ pub fn concatenate_ffmpeg(temp: &Path, output: &Path, encoder: Encoder) {
|
|||
|
||||
assert!(out.status.success());
|
||||
}
|
||||
|
||||
pub fn get_frame_types(file: &Path) -> Vec<String> {
|
||||
let mut cmd = Command::new("ffmpeg");
|
||||
|
||||
cmd.stdout(Stdio::piped());
|
||||
cmd.stderr(Stdio::piped());
|
||||
|
||||
let args = [
|
||||
"ffmpeg",
|
||||
"-hide_banner",
|
||||
"-i",
|
||||
file.to_str().unwrap(),
|
||||
"-vf",
|
||||
"showinfo",
|
||||
"-f",
|
||||
"null",
|
||||
"-loglevel",
|
||||
"debug",
|
||||
"-",
|
||||
];
|
||||
|
||||
cmd.args(args);
|
||||
|
||||
let out = cmd.output().unwrap();
|
||||
|
||||
assert!(out.status.success());
|
||||
|
||||
let output = String::from_utf8(out.stderr).unwrap();
|
||||
|
||||
let str_vec = output.split("\n").collect::<Vec<_>>();
|
||||
|
||||
let string_vec: Vec<String> = str_vec.iter().map(|x| x.to_string()).collect();
|
||||
|
||||
string_vec
|
||||
}
|
||||
|
|
|
@ -107,6 +107,13 @@ fn get_ffmpeg_info() -> String {
|
|||
av1an_core::get_ffmpeg_info()
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn get_frame_types(file: String) -> Vec<String> {
|
||||
let input_file = Path::new(&file);
|
||||
|
||||
av1an_core::ffmpeg::get_frame_types(input_file)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn determine_workers(encoder: &str) -> PyResult<u64> {
|
||||
Ok(av1an_core::determine_workers(
|
||||
|
@ -173,6 +180,6 @@ fn av1an_pyo3(_py: Python, m: &PyModule) -> PyResult<()> {
|
|||
m.add_function(wrap_pyfunction!(construct_target_quality_command, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(concatenate_ffmpeg, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(extract_audio, m)?)?;
|
||||
|
||||
m.add_function(wrap_pyfunction!(get_frame_types, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
from .ffmpeg import *
|
|
@ -1,44 +0,0 @@
|
|||
#!/bin/env python
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, STDOUT
|
||||
from typing import List
|
||||
from av1an.logger import log
|
||||
|
||||
|
||||
def get_frametypes(file: Path) -> List:
|
||||
"""
|
||||
Read file and return list with all frame types
|
||||
:param file: Path for file
|
||||
:return: list with sequence of frame types
|
||||
"""
|
||||
|
||||
frames = []
|
||||
|
||||
ff = [
|
||||
"ffmpeg",
|
||||
"-hide_banner",
|
||||
"-i",
|
||||
file.as_posix(),
|
||||
"-vf",
|
||||
"showinfo",
|
||||
"-f",
|
||||
"null",
|
||||
"-loglevel",
|
||||
"debug",
|
||||
"-",
|
||||
]
|
||||
|
||||
pipe = subprocess.Popen(ff, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
|
||||
while True:
|
||||
line = pipe.stdout.readline().strip().decode("utf-8")
|
||||
|
||||
if len(line) == 0 and pipe.poll() is not None:
|
||||
break
|
||||
|
||||
frames.append(line)
|
||||
|
||||
return frames
|
Loading…
Reference in a new issue