use std::ffi::CString;
use rsmpeg::avformat::{AVFormatContextInput, AVFormatContextOutput};
use crate::Result;
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<AVFormatContextInput> {
AVFormatContextInput::open(self.c_path_url()?.as_c_str()).map_err(Into::into)
}
fn ofmt_ctx(&self) -> Result<AVFormatContextOutput> {
AVFormatContextOutput::create(self.c_path_url()?.as_c_str()).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()
}
}