feat(transcoding): add FFmpeg HLS transcoding support
- Introduced `TranscodeManager` for managing on-demand transcoding of local video files. - Added configuration options for transcoding in `Config` and `LocalFilesConfig`. - Implemented new API routes for managing transcoding settings, stats, and cache. - Updated `LocalFilesProvider` to support transcoding capabilities. - Created frontend components for managing transcode settings and displaying stats. - Added database migration for transcode settings. - Enhanced existing routes and DTOs to accommodate new transcoding features.
This commit is contained in:
@@ -75,6 +75,10 @@ async fn main() -> anyhow::Result<()> {
|
||||
// Build provider registry — all configured providers are registered simultaneously.
|
||||
#[cfg(feature = "local-files")]
|
||||
let mut local_index: Option<Arc<infra::LocalIndex>> = None;
|
||||
#[cfg(feature = "local-files")]
|
||||
let mut transcode_manager: Option<Arc<infra::TranscodeManager>> = None;
|
||||
#[cfg(feature = "local-files")]
|
||||
let mut sqlite_pool_for_state: Option<sqlx::SqlitePool> = None;
|
||||
|
||||
let mut registry = infra::ProviderRegistry::new();
|
||||
|
||||
@@ -99,12 +103,41 @@ async fn main() -> anyhow::Result<()> {
|
||||
let lf_cfg = infra::LocalFilesConfig {
|
||||
root_dir: dir.clone(),
|
||||
base_url: config.base_url.clone(),
|
||||
transcode_dir: config.transcode_dir.clone(),
|
||||
cleanup_ttl_hours: config.transcode_cleanup_ttl_hours,
|
||||
};
|
||||
let idx = Arc::new(infra::LocalIndex::new(&lf_cfg, sqlite_pool.clone()).await);
|
||||
local_index = Some(Arc::clone(&idx));
|
||||
let scan_idx = Arc::clone(&idx);
|
||||
tokio::spawn(async move { scan_idx.rescan().await; });
|
||||
registry.register("local", Arc::new(infra::LocalFilesProvider::new(idx, lf_cfg)));
|
||||
|
||||
// Build TranscodeManager if TRANSCODE_DIR is set.
|
||||
let tm = config.transcode_dir.as_ref().map(|td| {
|
||||
std::fs::create_dir_all(td).ok();
|
||||
tracing::info!("Transcoding enabled; cache dir: {:?}", td);
|
||||
let tm = infra::TranscodeManager::new(td.clone(), config.transcode_cleanup_ttl_hours);
|
||||
// Load persisted TTL from DB.
|
||||
let tm_clone = Arc::clone(&tm);
|
||||
let pool_clone = sqlite_pool.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Ok(row) = sqlx::query_as::<_, (i64,)>(
|
||||
"SELECT cleanup_ttl_hours FROM transcode_settings WHERE id = 1",
|
||||
)
|
||||
.fetch_one(&pool_clone)
|
||||
.await
|
||||
{
|
||||
tm_clone.set_cleanup_ttl(row.0 as u32);
|
||||
}
|
||||
});
|
||||
tm
|
||||
});
|
||||
|
||||
registry.register(
|
||||
"local",
|
||||
Arc::new(infra::LocalFilesProvider::new(idx, lf_cfg, tm.clone())),
|
||||
);
|
||||
transcode_manager = tm;
|
||||
sqlite_pool_for_state = Some(sqlite_pool.clone());
|
||||
} else {
|
||||
tracing::warn!("local-files requires SQLite; ignoring LOCAL_FILES_DIR");
|
||||
}
|
||||
@@ -137,6 +170,8 @@ async fn main() -> anyhow::Result<()> {
|
||||
#[cfg(feature = "local-files")]
|
||||
{
|
||||
state.local_index = local_index;
|
||||
state.transcode_manager = transcode_manager;
|
||||
state.sqlite_pool = sqlite_pool_for_state;
|
||||
}
|
||||
|
||||
let server_config = ServerConfig {
|
||||
@@ -206,6 +241,7 @@ impl IMediaProvider for NoopMediaProvider {
|
||||
search: false,
|
||||
streaming_protocol: StreamingProtocol::DirectFile,
|
||||
rescan: false,
|
||||
transcode: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user