How do you convert an entire directory with ffmpeg?

前端 未结 26 2008
长发绾君心
长发绾君心 2020-11-22 04:33

How do you convert an entire directory/folder with ffmpeg via command line or with a batch script?

相关标签:
26条回答
  • 2020-11-22 04:49

    little php script to do it:

    #!/usr/bin/env php
    <?php
    declare(strict_types = 1);
    if ($argc !== 2) {
        fprintf ( STDERR, "usage: %s dir\n", $argv [0] );
        die ( 1 );
    }
    $dir = rtrim ( $argv [1], DIRECTORY_SEPARATOR );
    if (! is_readable ( $dir )) {
        fprintf ( STDERR, "supplied path is not readable! (try running as an administrator?)" );
        die(1);
    }
    if (! is_dir ( $dir )) {
        fprintf ( STDERR, "supplied path is not a directory!" );
        die(1);
    }
    $files = glob ( $dir . DIRECTORY_SEPARATOR . '*.avi' );
    foreach ( $files as $file ) {
        system ( "ffmpeg -i " . escapeshellarg ( $file ) . ' ' . escapeshellarg ( $file . '.mp4' ) );
    }
    
    0 讨论(0)
  • 2020-11-22 04:50

    Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.

    for i in *.avi;
      do name=`echo "$i" | cut -d'.' -f1`
      echo "$name"
      ffmpeg -i "$i" "${name}.mov"
    done
    
    0 讨论(0)
  • 2020-11-22 04:50

    For anyone who wants to batch convert anything with ffmpeg but would like to have a convenient Windows interface, I developed this front-end:

    https://sourceforge.net/projects/ffmpeg-batch

    It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.

    0 讨论(0)
  • 2020-11-22 04:53

    Only this one Worked for me, pls notice that you have to create "newfiles" folder manually where the ffmpeg.exe file is located.

    Convert . files to .wav audio Code:

    for %%a in ("*.*") do ffmpeg.exe -i "%%a" "newfiles\%%~na.wav"
    pause
    

    i.e if you want to convert all .mp3 files to .wav change ("*.*") to ("*.mp3").

    The author of this script is :

    https://forum.videohelp.com/threads/356314-How-to-batch-convert-multiplex-any-files-with-ffmpeg

    hope it helped

    0 讨论(0)
  • 2020-11-22 04:54

    Also if you want same convertion in subfolders. here is the recursive code.

    for /R "folder_path" %%f in (*.mov,*.mxf,*.mkv,*.webm) do (
        ffmpeg.exe -i "%%~f" "%%~f.mp4"
        )
    
    0 讨论(0)
  • 2020-11-22 04:55

    For Linux and macOS this can be done in one line, using parameter expansion to change the filename extension of the output file:

    for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done
    
    0 讨论(0)
提交回复
热议问题