How do you convert an entire directory with ffmpeg

2019-01-03 01:30发布

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

12条回答
做自己的国王
2楼-- · 2019-01-03 02:01

To convert with subdirectories use e.g.

find . -exec ffmpeg -i {} {}.mp3 \;
查看更多
何必那么认真
3楼-- · 2019-01-03 02:03
for i in *.flac;
  do name=`echo "${i%.*}"`;
  echo $name;
  ffmpeg -i "${i}" -ab 320k -map_metadata 0 -id3v2_version 3 "${name}".mp3;
done

Batch process flac files into mp3 (safe for file names with spaces) using [1] [2]

查看更多
走好不送
4楼-- · 2019-01-03 02:04

Another simple solution that hasn't been suggested yet would be to use xargs:

ls *.avi | xargs -i -n1 ffmpeg -i {} "{}.mp4"

One minor pitfall is the awkward naming of output files (e.g. input.avi.mp4). A possible workaround for this might be:

ls *.avi | xargs -i -n1 bash -c "i={}; ffmpeg -i {} "\${i%.*}.mp4""

查看更多
对你真心纯属浪费
5楼-- · 2019-01-03 02:06

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
查看更多
我想做一个坏孩纸
6楼-- · 2019-01-03 02:06

A one-line bash script would be easy to do - replace *.avi with your filetype:

for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov  ; done
查看更多
闹够了就滚
7楼-- · 2019-01-03 02:08

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' ) );
}
查看更多
登录 后发表回答