use std::ffi::CString;
use std::sync::Once;
use ffmpeg_next::format::{self, context};
use crate::Result;
fn init() {
static INIT: Once = Once::new();
INIT.call_once(|| {
let _ = ffmpeg_next::init();
});
}
pub trait AVFile {
fn path_url(&self) -> &str;
fn c_path_url(&self) -> Result<CString> {
CString::new(self.path_url()).map_err(Into::into)
}
fn ifmt_ctx(&self) -> Result<context::Input> {
init();
self.c_path_url()?;
format::input(self.path_url()).map_err(Into::into)
}
fn ofmt_ctx(&self) -> Result<context::Output> {
init();
self.c_path_url()?;
format::output(self.path_url()).map_err(Into::into)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VFile {
pub path_url: String,
}
impl VFile {
pub fn new(path_url: impl AsRef<str>) -> Self {
Self {
path_url: path_url.as_ref().to_owned(),
}
}
}
impl AVFile for VFile {
fn path_url(&self) -> &str {
self.path_url.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AFile {
pub path_url: String,
}
impl AFile {
pub fn new(path_url: impl AsRef<str>) -> Self {
Self {
path_url: path_url.as_ref().to_owned(),
}
}
}
impl AVFile for AFile {
fn path_url(&self) -> &str {
self.path_url.as_str()
}
}