Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Simple script for converting all MTS videos in directory or in all subdirectories using ffmpeg package
- # Author: ceskyDJ
- #
- # Dependencies: ffmpeg
- #
- # Prepare:
- # - Save to file (ex. /usr/local/bin/MTSToAVI)
- # - Set execute permission with chmod +x YourFile (ex. sudo chmod +x /usr/local/bin/MTSToAVI)
- #
- # Usage:
- # - For convert all files in specific directory:
- # * Go to the directory (ex. cd ~/Videos/FromCamera)
- # * Run script from saved file (ex. MTSToAVI)
- # - For convert all files in all subdirectories:
- # * Go to the directory contains subdirectories with files
- # * Run script from saved file (ex. MTSToAVI)
- # Converts one file
- convertFile() {
- # Rename to underscore name (fix for file names with spaces)
- file="$1";
- mv "$file" "${file// /_}";
- file="${file// /_}";
- echo -e "\033[1;33mConverting file: '$1'...\033[0m";
- ffmpeg -i $file -vcodec libxvid -b 18000k -acodec libmp3lame -ac 2 -ab 320k -deinterlace -s 1440x1080 `echo $file | cut -d'.' -f1`.avi;
- # Rename back to original
- mv "$file" "${file//_/ }";
- # Rename new file
- newFile="${file//.MTS/.avi}";
- newFile="${newFile//.mts/.avi}";
- mv "$newFile" "${newFile//_/ }";
- return;
- }
- # Converts files in selected directory
- convertFilesInDirectory() {
- for f in *.MTS; do
- convertFile "$f";
- done
- return;
- }
- # Converts files in subdirectories of selected directory
- convertFilesInSubDirectories() {
- # Move to subdirectory
- cd "$1";
- echo -e "\033[1;35mActual directory: '$1'\033[0m";
- convertFilesInDirectory;
- # Move back to parent directory
- cd "..";
- return;
- }
- # Search for subdirectories
- for d in */; do
- # Subdirectories not found -> convert files in this directory
- if [[ $d = "*/" ]]; then
- convertFilesInDirectory;
- # Subdirectories found -> convert their files
- else
- convertFilesInSubDirectories "$d";
- fi
- done
- exit
Add Comment
Please, Sign In to add comment