feat: representative frame - auto-detect thumbnail + JSON endpoint
This commit is contained in:
@@ -690,7 +690,7 @@ async fn stream_video(
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct ThumbQuery {
|
||||
frame: i64,
|
||||
frame: Option<i64>,
|
||||
x: Option<i32>,
|
||||
y: Option<i32>,
|
||||
w: Option<i32>,
|
||||
@@ -703,6 +703,20 @@ async fn face_thumbnail(
|
||||
Query(q): Query<ThumbQuery>,
|
||||
) -> Result<impl IntoResponse, StatusCode> {
|
||||
let videos_table = schema::table_name("videos");
|
||||
|
||||
let frame = match q.frame {
|
||||
Some(f) => f,
|
||||
None => {
|
||||
let result = crate::core::processor::tkg::query_auto_representative_frame(
|
||||
state.db.pool(),
|
||||
&file_uuid,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| StatusCode::NOT_FOUND)?;
|
||||
result.frame_number
|
||||
}
|
||||
};
|
||||
|
||||
let row: Option<(String,)> = sqlx::query_as(&format!(
|
||||
"SELECT file_path FROM {} WHERE file_uuid = $1",
|
||||
videos_table
|
||||
@@ -713,7 +727,7 @@ async fn face_thumbnail(
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
let (file_path,) = row.ok_or(StatusCode::NOT_FOUND)?;
|
||||
|
||||
let select = format!("select=eq(n\\,{})", q.frame);
|
||||
let select = format!("select=eq(n\\,{})", frame);
|
||||
let vf = if let (Some(x), Some(y), Some(w), Some(h)) = (q.x, q.y, q.w, q.h) {
|
||||
format!("{},crop={}:{}:{}:{}", select, w, h, x, y)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user