Created
October 15, 2024 10:33
-
-
Save ingjavierpinilla/e83bb08a146676f1d9b233b3b75c89d0 to your computer and use it in GitHub Desktop.
Davinci create 1 min video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| OUTPUT_NAME="" | |
| project_manager = resolve.GetProjectManager() | |
| project = project_manager.GetCurrentProject() | |
| if project is None: | |
| print("No se encontró ningún proyecto activo.") | |
| exit() | |
| timeline = project.GetCurrentTimeline() | |
| if timeline is None: | |
| print("No hay un timeline activo.") | |
| exit() | |
| # Intentar obtener la duración mediante los cuadros de inicio y fin | |
| start_frame = timeline.GetStartFrame() | |
| end_frame = timeline.GetEndFrame() | |
| if start_frame is None or end_frame is None: | |
| print("No se pudieron obtener los cuadros iniciales o finales del timeline.") | |
| exit() | |
| # Calcular la duración total | |
| total_duration = end_frame - start_frame | |
| print(f"start_frame: {start_frame}, end_frame: {end_frame}") | |
| print(f"Duración total del timeline: {total_duration} cuadros.") | |
| # Obtener el frame rate | |
| frame_rate = timeline.GetSetting("timelineFrameRate") | |
| if frame_rate is None: | |
| print("No se pudo obtener la tasa de cuadros del timeline.") | |
| exit() | |
| else: | |
| print(f"Frame rate: {frame_rate} fps") | |
| clip_duration = 58 * frame_rate # 58 segundos en frames | |
| print(f"Duración de cada clip: {clip_duration} frames.") | |
| print(f"Duración de cada clip: {clip_duration/frame_rate} segundos.") | |
| total_clips = int( | |
| total_duration // clip_duration + (1 if total_duration % clip_duration else 0) | |
| ) | |
| print(f"Total de clips a generar: {total_clips}") | |
| # Loop para dividir y exportar el timeline | |
| for i in range(total_clips): | |
| # Ajustar el cálculo del inicio y fin en base al start_frame | |
| clip_start_frame = start_frame + int(i * clip_duration) | |
| clip_end_frame = start_frame + int(min((i + 1) * clip_duration, total_duration)) | |
| print(f"Clip {i + 1}: Inicio = {clip_start_frame}, Fin = {clip_end_frame}") | |
| print( | |
| f"Clip {i + 1}: Inicio = {clip_start_frame / frame_rate}, Fin = {clip_end_frame / frame_rate}" | |
| ) | |
| print("*" * 10) | |
| # Asegurarse de que los puntos de entrada y salida sean correctos | |
| if clip_end_frame <= clip_start_frame: | |
| print(f"Clip {i + 1} tiene un inicio y fin inválidos.") | |
| continue | |
| # Nombre del archivo exportado | |
| output_name = f"{OUTPUT_NAME}_{i + 1}.mp4" | |
| # Utilizar los ajustes de renderización seleccionados y añadir el trabajo de render | |
| project.SetRenderSettings( | |
| { | |
| "CustomName": output_name, | |
| "SelectAllFrames": False, | |
| "MarkIn": clip_start_frame, | |
| "MarkOut": clip_end_frame, | |
| } | |
| ) | |
| # Verificar si se han establecido correctamente los puntos de entrada y salida | |
| print( | |
| f"Configurando render para el clip {i + 1} desde {clip_start_frame} hasta {clip_end_frame}." | |
| ) | |
| project.AddRenderJob() | |
| print(f"Se han agregado {total_clips} clips para renderizado.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment