使用FFMPEG的Shell脚本转换为mp4会产生带有两次附加.mp4扩展名的新视频

Avi*_*Avi 2 linux shell ffmpeg

我正在将整个视频文件夹转换为MP4。该脚本起作用,除了新视频两次附加了“ .mp4”。例如。转换后,“ video.mp3”将是“ video.mp3.mp4”。下面是shell脚本。TIA

#!/bin/bash
#Shell Script which converts all videos in a folder to MP4


for file in *.*; 
    do 
        if[ ${file: -4} != ".mp4"]   #don't want to convert mp4 files           
            ffmpeg -i "$file" "${file}".mp4 
done
Run Code Online (Sandbox Code Playgroud)

aid*_*dan 5

这将删除最后一个文件扩展名: ${file%.*}

所以你想要 ${file%.*}.mp4

这是在bash中进行字符串操作的良好参考:http : //tldp.org/LDP/abs/html/string-manipulation.html