利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(upload): reject referenced media disguised as standalone files
Rudy Celeklib4b431d96e1b
diff --git a/app/services/bgm.py b/app/services/bgm.pyindex 4e3ec079..83379473 100644--- a/app/services/bgm.py+++ b/app/services/bgm.py@@ -159,6 +159,12 @@ def _validate_audio(file_path: str, timeout_seconds: int = 30) -> None:"-v","error","-xerror",+ # Uploaded files must be self-contained media, not playlists+ # that cause validation/rendering to read adjacent files or URLs.+ "-protocol_whitelist",+ "file,pipe",+ "-format_whitelist",+ "mp3,mov,aac,wav,flac,ogg,asf","-i",file_path,"-map",diff --git a/app/services/material_upload.py b/app/services/material_upload.pyindex 333b318b..b36085a1 100644--- a/app/services/material_upload.py+++ b/app/services/material_upload.py@@ -195,6 +195,12 @@ def _validate_video("-v","error","-xerror",+ # Uploaded files must be self-contained media, not playlists+ # that cause validation/rendering to read adjacent files or URLs.+ "-protocol_whitelist",+ "file,pipe",+ "-format_whitelist",+ "mov,avi,flv,matroska","-i",file_path,"-map",diff --git a/test/services/test_standalone_upload_containers.py b/test/services/test_standalone_upload_containers.pynew file mode 100644index 00000000..8c4d9f52--- /dev/null+++ b/test/services/test_standalone_upload_containers.py@@ -0,0 +1,45 @@+import shutil+import subprocess++import pytest+from app.services import bgm, material_upload+from app.utils import utils+++def standalone_media(tmp_path):+ ffmpeg = utils.get_ffmpeg_binary()+ audio = tmp_path / "standalone.wav"+ video = tmp_path / "standalone.mp4"+ for path, options in [+ (audio, ["-f", "lavfi", "-i", "sine=frequency=440:duration=0.1"]),+ (video, ["-f", "lavfi", "-i", "color=c=red:s=32x32:r=10", "-t", "0.2", "-c:v", "libx264"]),+ ]:+ subprocess.run([ffmpeg, "-nostdin", "-v", "error", *options, "-y", str(path)], check=True, capture_output=True)+ return audio, video++[email protected]("kind", ["audio", "video"])+def test_upload_rejects_concat_reference_disguised_as_media(standalone_media, kind):+ audio, video = standalone_media+ target = audio if kind == "audio" else video+ disguised = target.with_name("disguised" + target.suffix)+ disguised.write_text("ffconcat version 1.0\nfile '" + target.name + "'\n")+ validate = bgm.validate_audio_file if kind == "audio" else material_upload._validate_video+ error = bgm.BgmUploadError if kind == "audio" else material_upload.MaterialUploadError+ with pytest.raises(error):+ validate(str(disguised))+++def test_standalone_uploads_still_decode_and_use_content_detection(standalone_media):+ audio, video = standalone_media+ bgm.validate_audio_file(str(audio))+ material_upload._validate_video(str(video))+ # TTS/media validators have historically detected actual containers rather+ # than forcing a demuxer solely from the filename extension.+ renamed_audio = audio.with_suffix(".mp3")+ renamed_video = video.with_suffix(".mov")+ shutil.copyfile(audio, renamed_audio)+ shutil.copyfile(video, renamed_video)+ bgm.validate_audio_file(str(renamed_audio))+ material_upload._validate_video(str(renamed_video))