忍者ブログ
Yaleで、遊んで学ぶ日々。

Yaleで、遊んで学ぶ日々。

囲碁、ときどきプログラミング、ところにより経済。
[113]  [112]  [111]  [110]  [109]  [108]  [107]  [106]  [105]  [104]  [103
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

あるディレクトリ内の特定の拡張子のファイルをmp3に変換するシェルスクリプト。シェルの勉強に書いた。

syntax:
 $ sh dir2mp3 <target directory> <input extension> [ffmpeg options]

ffmpegがインストールされていて、libmp3lameコーデックがencodaleであることが前提(参考)。
1行目は環境に応じて変える。
一応 dir2mp3.sh という名前をつけたけど名前は何でもいい。
実質的には最後の6行だけでいい。


#!/bin/sh

# convert files in a directory into mp3.
# does not look for files in sub-directories.
# depends on ffmpeg.
# author: kohta
# date: 05/19/2010

# arguments
#   $1: target directory (can be relative)
#   $2: input extension (can be video)
#   $3: (optional) options to cast to ffmpeg (please quote by " ")

# example
#   dir2mp3.sh ~/Music m4a "-y -ac 2 -ab 128k"

# hint
#   add "-y" to the third argument to avoid overwrite queries


echo "This is" $0 "..."
echo "syntax:"
echo "  sh" $0 "<target directory> <input extension> [ffmpeg options]"



if [ $# -eq 2 ]; then
    echo "target directory:" $1
    echo "input extension: " $2
elif [ $# -eq 3 ]; then
    echo "target directory:" $1
    echo "input extension: " $2
    echo "ffmpeg options:  " $3
else
    echo "need at least 2 arguments: <target directory> and <input extension>"
    exit
fi



for file in $1/*.$2
do
    echo "converting" $file "to mp3 with options" $3 "..."
    ffmpeg -i "$file" -acodec libmp3lame $3 "${file%$2}mp3"
    echo "done."
done







PR
この記事にコメントする
お名前:
タイトル:
文字色:
メールアドレス:
URL:
コメント:
パスワード:   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
この記事へのトラックバック
この記事にトラックバックする:
Calender
02 2024/03 04
S M T W T F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Search in This Blog
Latest Comments
[03/30 川内のばば山田]
[03/30 川内のばば山田]
[08/06 Aterarie]
[07/05 Agazoger]
[07/01 Thomaskina]
Oldest Posts
Latest Trackbacks
フリーエリア

Barcode
Access Analysis
Powerd by NINJAブログ / Designed by SUSH
Copyright © Yaleで、遊んで学ぶ日々。 All Rights Reserved.
忍者ブログ [PR]