Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ver Very very Slow #2231

Open
sysmaya opened this issue Oct 17, 2024 · 6 comments
Open

Ver Very very Slow #2231

sysmaya opened this issue Oct 17, 2024 · 6 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@sysmaya
Copy link

sysmaya commented Oct 17, 2024

What an absurdly slow and exasperating thing.
2 hours to make a 5 minute video??
There are faster alternatives:
FFmpeg only
VidGear

  • Anything is faster than MoviePY, it is faster to make the video in

Expected Behavior

You expect a 5-minute video to take less than 10 minutes to complete.

Actual Behavior

2 long hours waiting to build the video

Steps to Reproduce the Problem

Get started by downloading MoviePY
Upload a 5 minute wav audio
place some image clips
and 50 text subtitles

@sysmaya sysmaya added the bug Issues that report (apparent) bugs. label Oct 17, 2024
@steinathan
Copy link

Very slow indeed, found an alternative yet?

@sysmaya
Copy link
Author

sysmaya commented Oct 18, 2024

Very slow indeed, found an alternative yet?

I'm writing my own functions to use ffmpeg, they are 10 times faster. But it's tedious.

def ffmpeg_image_overlay( start_time, duration, x='(W-w)/2', y='(H-h)/2'):
    """
    Generates an overlay filter for FFmpeg.
    Args:
        image_file (str): Path to the image file.
        start_time (float): Start time in seconds to display the image.
        duration (float): Duration in seconds to display the image.
        x (str): Expression for the horizontal position of the image.
        y (str): Expression for the vertical position of the image.
    Returns:
        str: Overlay filter for FFmpeg.
    """
    return f"[0:v][1:v] overlay={x}:{y}:enable='between(t,{start_time},{start_time + duration})'"
def ffmpeg_run_command(video_input, video_output, filtro, imageFile=''):
    """
    Run the FFmpeg command with the provided filter.    
    Args:
        video_input (str): Path of the input video file.
        video_output (str): Path to the output video file.
        filter (str): Command or FFmpeg filter to apply to the video.    
    Returns:
        bool: True if the command succeeds, False if it fails.
    """
    inicioExec = time.time()
    filtro = re.sub(r'\s+', ' ', filtro)
    lentxt = len(filtro)
    
    caracteres = string.ascii_uppercase + string.digits
    nombreTMP = ''.join(random.choice(caracteres) for _ in range(12))
    nombreTMP = nombreTMP + '.mp4'

    ffmpeg_path = r'C:\\ffmpeg\\bin\\ffmpeg.exe'
    directorio_actual = os.path.dirname(os.path.abspath(__file__))
    video_input = os.path.join(directorio_actual, video_input)

    if imageFile == '' :
        comando = [
            ffmpeg_path,
            '-i', video_input,              # Input del video
            '-vf', filtro,                  # Filtro de video para superponer el texto
            '-codec:a', 'copy',             # Copiar el audio sin modificar
            '-stats',                       # Muestra el banner de avance del proceso
            nombreTMP                       # Archivo de salida
        ]
    else :
        comando = [
            ffmpeg_path,
            '-i', video_input,              # Input del video
            '-i', imageFile,                # Input de la imagen
            '-filter_complex', filtro,      # Filtro de video para superponer la imagen
            '-pix_fmt', 'yuv420p',          # Formato de píxeles
            '-codec:a', 'copy',             # Copiar el audio sin modificar
            '-v', 'quiet',                  # Oculta todos los mensajes excepto el banner de progreso
            '-stats',                       # Muestra el banner de avance del proceso
            nombreTMP                       # Archivo de salida
        ]
    
    try:
        subprocess.run(comando, check=True)
        duracion_ejecucion = time.time() - inicioExec
        minutos = int(duracion_ejecucion // 60)
        segundos = int(duracion_ejecucion % 60)
        milisegundos = int((duracion_ejecucion - int(duracion_ejecucion)) * 1000)
        print(f"run_ffmpeg() OK: {minutos}:{segundos}:{milisegundos}")

        if os.path.exists(video_output): os.remove(video_output)   
        os.rename(nombreTMP, video_output)
        return True
    except subprocess.CalledProcessError as e:
        print(f"run_ffmpeg() Error: {e}")
        return False

@ericmadureira
Copy link

Hi everyone, haven't used the lib yet but this issue caught my attention. Is rendering really taking that long?
I'm looking for "video edit via code" libs to automate video editing.

@steinathan
Copy link

It is slow, but thats just because of ffmpeg - moviepy don't efficiently make use of ffmpeg, but if you're on Mac, it can get 30% faster by using hevc_videotoolbox decoders

I'm currently using moviepy in my app: https://dub.sh/voidface

@ericmadureira
Copy link

Have you heard of https://www.remotion.dev/ or https://re.video/?
I'm reading about them. I'm interested in editing content faster without using GUI programs like capcut, etc.

@steinathan
Copy link

Yes heard about them but haven't used them, if you're just looking for editing and cool with react then remotion is the way to go - you'd still need a headless browser to render the video - but it's faster

My use case is mainly automation and Python - sad they're no alternatives to moviepy that's faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

3 participants