feat: speed up output clips to 1.25x speed by default and scale subtitle/mute timestamps

This commit is contained in:
Renato
2026-07-02 19:38:50 +02:00
parent 05e0217541
commit 174b992335
2 changed files with 34 additions and 18 deletions
+27 -11
View File
@@ -887,6 +887,7 @@ if __name__ == '__main__':
parser.add_argument('-o', '--output', type=str, help="Output directory or file (if processing whole video).")
parser.add_argument('--keep-original', action='store_true', help="Keep the downloaded YouTube video.")
parser.add_argument('--skip-analysis', action='store_true', help="Skip AI analysis and convert the whole video.")
parser.add_argument('--speed', type=float, default=1.25, help="Speed up factor for the output clips (default: 1.25).")
args = parser.parse_args()
@@ -1020,16 +1021,30 @@ if __name__ == '__main__':
clip_temp_path = os.path.join(output_dir, f"temp_{clip_filename}")
clip_final_path = os.path.join(output_dir, clip_filename)
# ffmpeg cut
cut_command = [
'ffmpeg', '-y',
'-ss', str(start),
'-to', str(end),
'-i', input_video,
'-c:v', 'libx264', '-crf', '18', '-preset', 'fast',
'-c:a', 'aac',
clip_temp_path
]
# ffmpeg cut & speed up
if args.speed != 1.0:
setpts = 1.0 / args.speed
cut_command = [
'ffmpeg', '-y',
'-ss', str(start),
'-to', str(end),
'-i', input_video,
'-filter_complex', f'[0:v]setpts={setpts:.6f}*PTS[v];[0:a]atempo={args.speed:.6f}[a]',
'-map', '[v]', '-map', '[a]',
'-c:v', 'libx264', '-crf', '18', '-preset', 'fast',
'-c:a', 'aac',
clip_temp_path
]
else:
cut_command = [
'ffmpeg', '-y',
'-ss', str(start),
'-to', str(end),
'-i', input_video,
'-c:v', 'libx264', '-crf', '18', '-preset', 'fast',
'-c:a', 'aac',
clip_temp_path
]
subprocess.run(cut_command, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
# Generate SRT for this clip and get mute ranges for profanity
@@ -1038,7 +1053,8 @@ if __name__ == '__main__':
success_srt, mute_ranges = generate_srt(
transcript, start, end, srt_path,
max_chars=20, max_duration=2.0,
swears_path=swears_path, return_mute_ranges=True
swears_path=swears_path, return_mute_ranges=True,
speed_factor=args.speed
)
# Process vertical, passing the relative mute ranges for profanity muting