[Python] How to convert multiple video files in a specific path outputvideo with the same...

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    The following code to converts a one video from mp4 to avi using ffmpeg

    ffmpeg.exe -i "kingman.mp4" -c copy "kingman.avi"

    I need to convert multiple videos in a specific path. "outputvideo" with the same video name

    This is the my code that needs to be modified.

    from pathlib import Path
    import subprocess
    from glob import glob

    all_files = glob('./video/*.mp4')

    for filename in all_files:
    videofile = Path(filename)
    outputfile = Path(r"./outputvideo/")
    codec = "copy"
    ffmpeg_path = (r"ffmpeg.exe")

    outputfile = outputfile / f"{videofile.stem}"

    outputfile.mkdir(parents=True, exist_ok=True)

    command = [
    f"{ffmpeg_path}",
    "-i", f"{videofile}",
    "-c", f"{codec}",
    "{outputfile}",]

    process = subprocess.Popen(
    command,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    text=True,
    bufsize=1,
    universal_newlines=True)
    process.communicate()

    Continue reading...

Compartilhe esta Página