FfmpegTask

Struct FfmpegTask 

Source
pub struct FfmpegTask { /* private fields */ }
Expand description

FFmpeg 任务构建器

用于构建并执行服务端的 FFmpeg 转码任务。 采用 Builder 模式,支持链式调用。

§Example

use vtx_sdk::prelude::*;

fn handle_video(vid: String) -> VtxResult<Response> {
    FfmpegTask::new("mini", vid)
        .arg("-ss 10")
        .arg("-t 30")
        .execute()
}

Implementations§

Source§

impl FfmpegTask

Source

pub fn new(profile: impl Into<String>, input_id: impl Into<String>) -> Self

创建一个新的 FFmpeg 任务

§Parameters
  • profile: 目标 Profile 名称 (如 “mini”, “remux”, “thumbnail”)
  • input_id: 输入视频的唯一资源 ID (UUID)
Source

pub fn new_pipe(profile: impl Into<String>) -> Self

创建一个使用 stdin 管道作为输入的任务(等价于 input_id = "pipe:0")。

Source

pub fn arg(self, arg: impl Into<String>) -> Self

添加单个 FFmpeg 参数

自动处理参数转义,防止注入风险。

§Example

.arg("-ss").arg("10")

Source

pub fn args<I, S>(self, args: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

批量添加参数

Source

pub fn format(self, format: &str) -> Self

快捷方法:设置输出格式 等同于 .arg("-f").arg(format)

Source

pub fn seek(self, start: &str, duration: Option<&str>) -> Self

快捷方法:设置时间裁剪 等同于 .arg("-ss").arg(start).arg("-t").arg(duration)

Source

pub fn execute_buffer(self) -> VtxResult<Buffer>

执行任务并返回 Buffer 资源句柄。

这允许你在返回响应前,使用 buffer.write(...)stdin 写入数据(当 input_id="pipe:0" 时)。

Source

pub fn execute(self) -> VtxResult<HttpResponse>

执行任务并返回 HTTP 响应(200 + body=stdout 管道 Buffer)。

该方法会阻塞等待子进程启动,并立即返回包含 stdout 管道流的 HttpResponse。 数据将以流式传输给客户端,无需等待转码完成。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.