alex
commited on
Commit
·
53eab71
1
Parent(s):
f71d69a
15fpx
Browse files- OmniAvatar/utils/audio_preprocess.py +42 -1
- app.py +4 -2
OmniAvatar/utils/audio_preprocess.py
CHANGED
|
@@ -18,4 +18,45 @@ def add_silence_to_audio_ffmpeg(audio_path, tmp_audio_path, silence_duration_s=0
|
|
| 18 |
try:
|
| 19 |
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 20 |
except subprocess.CalledProcessError as e:
|
| 21 |
-
raise RuntimeError(f"ffmpeg failed ({e.returncode}): {e.stderr.strip()}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
try:
|
| 19 |
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 20 |
except subprocess.CalledProcessError as e:
|
| 21 |
+
raise RuntimeError(f"ffmpeg failed ({e.returncode}): {e.stderr.strip()}")
|
| 22 |
+
|
| 23 |
+
def convert_video_to_15fps_ffmpeg(video_path, output_path=None):
|
| 24 |
+
"""
|
| 25 |
+
Convert a video to 15 FPS using ffmpeg.
|
| 26 |
+
|
| 27 |
+
Parameters
|
| 28 |
+
----------
|
| 29 |
+
video_path : str
|
| 30 |
+
Path to the input .mp4 video.
|
| 31 |
+
output_path : str, optional
|
| 32 |
+
Path for the output video. If None, a new file will be created next to the input.
|
| 33 |
+
|
| 34 |
+
Returns
|
| 35 |
+
-------
|
| 36 |
+
str
|
| 37 |
+
The output video path.
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
if not os.path.exists(video_path):
|
| 41 |
+
raise FileNotFoundError(f"Input video not found: {video_path}")
|
| 42 |
+
|
| 43 |
+
# Auto-generate output path if not provided
|
| 44 |
+
if output_path is None:
|
| 45 |
+
base, ext = os.path.splitext(video_path)
|
| 46 |
+
output_path = base + "_15fps.mp4"
|
| 47 |
+
|
| 48 |
+
cmd = [
|
| 49 |
+
"ffmpeg",
|
| 50 |
+
"-i", video_path,
|
| 51 |
+
"-filter:v", "fps=15", # Set frame rate
|
| 52 |
+
"-c:a", "copy", # Copy audio without re-encoding
|
| 53 |
+
"-y", output_path, # Overwrite output
|
| 54 |
+
"-loglevel", "error"
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 59 |
+
except subprocess.CalledProcessError as e:
|
| 60 |
+
raise RuntimeError(f"ffmpeg failed ({e.returncode}): {e.stderr.strip()}")
|
| 61 |
+
|
| 62 |
+
return output_path
|
app.py
CHANGED
|
@@ -81,7 +81,7 @@ import torchvision.transforms as TT
|
|
| 81 |
from transformers import Wav2Vec2FeatureExtractor
|
| 82 |
import torchvision.transforms as transforms
|
| 83 |
import torch.nn.functional as F
|
| 84 |
-
from OmniAvatar.utils.audio_preprocess import add_silence_to_audio_ffmpeg
|
| 85 |
|
| 86 |
from diffusers import FluxKontextPipeline
|
| 87 |
from diffusers.utils import load_image
|
|
@@ -715,8 +715,10 @@ def infer(image_path, audio_path, text, num_steps, session_id = None, progress=g
|
|
| 715 |
prompt_path = prompt_path,
|
| 716 |
audio_path=tmp2_audio_path if args.use_audio else None,
|
| 717 |
prefix=f'result')
|
|
|
|
|
|
|
| 718 |
|
| 719 |
-
return
|
| 720 |
|
| 721 |
def apply_image(request):
|
| 722 |
print('image applied')
|
|
|
|
| 81 |
from transformers import Wav2Vec2FeatureExtractor
|
| 82 |
import torchvision.transforms as transforms
|
| 83 |
import torch.nn.functional as F
|
| 84 |
+
from OmniAvatar.utils.audio_preprocess import add_silence_to_audio_ffmpeg, convert_video_to_15fps_ffmpeg
|
| 85 |
|
| 86 |
from diffusers import FluxKontextPipeline
|
| 87 |
from diffusers.utils import load_image
|
|
|
|
| 715 |
prompt_path = prompt_path,
|
| 716 |
audio_path=tmp2_audio_path if args.use_audio else None,
|
| 717 |
prefix=f'result')
|
| 718 |
+
|
| 719 |
+
video_path_15fps = convert_video_to_15fps_ffmpeg(video_paths[0])
|
| 720 |
|
| 721 |
+
return video_path_15fps
|
| 722 |
|
| 723 |
def apply_image(request):
|
| 724 |
print('image applied')
|