not a better man

代码片段

利用mp4fragment 转换mp4格式

最近做一个项目,利用到Media Source Extensions 需要将普通的mp4文件转换问fragment格式的mp4文件,从https://www.bento4.com/downloads/ 下载对应的的二进制文件,对应的bin目录文件下有mp4fragment 可执行程序。教研的视频文件有120来个,打算使用shell脚本来执行这些程序

对应shell记录如下

#!/bin/sh

cd "/Users/vipkid/Downloads"
rm -rf  fragmentDir
rm -rf  cutMp4
## 创建 fragementDir
mkdir fragmentDir 
## 创建 mp4
mkdir cutMp4


path="/Users/vipkid/Downloads/final_trail_videos_1215"

files=$(ls $path)
# 裁剪mp4
for FILE in $files
    do
    ./ffmpeg -i  $path"/"$FILE -filter:v "crop=720:540:560:200" -c:a copy "/Users/vipkid/Downloads/cutMp4/"$FILE
    echo $FILE
    done
# 转换格式
for FILE in $files
   do
    cd "/Users/vipkid/Downloads/Bento4-SDK-1-6-0-637.universal-apple-macosx/bin/"
     ./mp4fragment  --verbosity 3  "/Users/vipkid/Downloads/cutMp4/"$FILE  "/Users/vipkid/Downloads/fragmentDir/"$FILE 
    echo $FILE
   done
#!/bin/sh

## 裁剪文件 将文件裁剪成 320 240的 然后转换为fragment mp4
cd "/Users/vipkid/Downloads"
## 创建 fragementDir
mkdir cut320
mkdir fragmentDir320


path="/Users/vipkid/Downloads/cutMp4"

files=$(ls $path)
# 裁剪mp4
for FILE in $files
    do
    ./ffmpeg -i  $path"/"$FILE -vf scale=320:240 -acodec aac -vcodec h264 "/Users/vipkid/Downloads/cut320/"$FILE
    echo $FILE
    done
# 转换格式
for FILE in $files
   do
    cd "/Users/vipkid/Downloads/Bento4-SDK-1-6-0-637.universal-apple-macosx/bin/"
     ./mp4fragment  --verbosity 3  "/Users/vipkid/Downloads/cut320/"$FILE  "/Users/vipkid/Downloads/fragmentDir320/"$FILE 
    echo $FILE
   done

发表评论