bash shell ffmpeg mp4批量轉換爲mp3

最需要把視頻mp4轉換爲mp3,
從百度網盤下載mp4到本地蘋果電腦後,使用bash shell 和ffmpeg 批量轉換,
下面是實現代碼:

前提條件:
1.電腦安裝了bash shell
2.安裝了ffmpeg
3.有mp4或其他格式的視頻文件.

mp4tomp3

#!/usr/bin/env bash
echo "批量轉換當前文件夾的mp4爲mp3文件"
mp4PostFix=".mp4";
file_not_ready="downloading"
fileList=$(ls -1 | tr " " "_")
for file in $fileList
    do
	    found=0
		case "${mp4PostFix}" in
		  *${file}*)
		    found=1;;
		esac

		#判斷是否下載完成
		is_finish=1
        case "${file_not_ready}" in
          *${file}*)
           is_finish=0;;
        esac

        if [ $found==1 ] && [ $is_finish==1 ]
        then                
            srcMp4File_bd=$(echo $file | tr "_" " ")
            srcMp4File=$file 
            destMp3File=$(echo $file | tr ".mp4" ".mp3")
            echo "舊的mp4文件=${srcMp4File_bd}新的mp4文件=${srcMp4File} 新的mp3文件=${destMp3File}"
            mv "$srcMp4File_bd" "${srcMp4File_bd// /_}"
            #mv "${srcMp4File_bd}"  "${srcMp4File}"
            ffmpeg -i ${srcMp4File} -f mp3 -ab 192000 -vn ${destMp3File}
            sleep 1;
		 else
		    echo "文件{$file}不包含${mp4PostFix}"
		 fi
	done

在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章