These shell scripts are designed to manipulate video files using ffmpeg
, a powerful command-line tool for handling video, audio, and other multimedia files. The scripts allow you to:
- Increase the frame rate of a video.
- Adjust the speed of a video and change the frame rate.
- Compress the videos/audio files. While also having the benefits of being able to do so in an easier way
To run these shell scripts, you need the following:
- Bash Shell: A shell environment to execute the script (typically pre-installed on macOS and Linux, and available on Windows via tools like Git Bash or Windows Subsystem for Linux (WSL)).
- FFmpeg: The core software for video processing.
- macOS: Bash is pre-installed. You can access it through the Terminal.
- Linux: Bash is pre-installed. You can access it through the Terminal.
- Windows:
- macOS:
- Install Homebrew if you don't have it.
- Run the following command in Terminal:
brew install ffmpeg
- Linux:
sudo apt update sudo apt install ffmpeg
- Windows:
- Download FFmpeg from the official website.
- Follow the installation guide for Windows here.
Make sure you add execute permissions to each of these shell scripts, so it run on your terminal. You can do this by running this in the terminal:
chmod +x <filename>
This script takes a video file and saves the output in the specified format, without the need to know how to use the commands in ffmpeg.
./converter <input_video_path> <output_path> <new_fps>
input_video_path
: Path to the input video file (e.g.,input_video.mp4
).output_path
: Path where the output video will be saved (e.g.,output_video.mp4
).new_fps
: Desired frame rate for the output video (e.g.,60
).
./converter input_video.mov output_video.mp4 60
This script adjusts the speed of a video and increases its frame rate simultaneously.
./speedup_vid <input_video_path> <output_path> <speed_factor>
input_video_path
: Path to the input video file (e.g.,input_video.mp4
).output_path
: Path where the output video will be saved (e.g.,output_video.mp4
).speed_factor
: Factor by which to speed up the video (e.g.,1.75
for 1.75x speed).new_fps
: Desired frame rate for the output video (e.g.,60
).
./adjust_speed_and_fps input_video.mp4 output_video.mp4 2.0 60
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 4 ]; then
echo "Usage: $0 <input_video_path> <output_path> <speed_factor> <new_fps>"
exit 1
fi
# Assign arguments to variables
input_video_path="$1"
output_path="$2"
speed_factor="$3"
new_fps="$4"
# Calculate the setpts value
setpts_value=$(echo "scale=2; 1/$speed_factor" | bc)
# Apply speed adjustment and frame rate increase using FFmpeg
ffmpeg -i "$input_video_path" -filter_complex "[0:v]setpts=${setpts_value}*PTS,minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=$new_fps'[v]" -map "[v]" -map 0:a -r "$new_fps" "$output_path"
- Navigate to the directory where the script is located:
cd /path/to/your/scripts
- Make the script executable:
chmod +x increase_fps chmod +x adjust_speed_and_fps
- Run the script using the appropriate parameters:
./increase_fps input_video.mp4 output_video.mp4 60
- Navigate to the directory where the script is located:
cd /path/to/your/scripts
- Make the script executable (if using WSL):
chmod +x increase_fps chmod +x adjust_speed_and_fps
- Run the script:
./increase_fps input_video.mp4 output_video.mp4 60
- Line Endings: Ensure that your shell scripts use Unix-style line endings (LF) rather than Windows-style (CRLF). Tools like
dos2unix
can help convert line endings. - FFmpeg Path: On Windows, make sure that the
ffmpeg
executable is in your system’s PATH or specify the full path toffmpeg
in the script.
- Permission Denied: Ensure that the script has executable permissions (
chmod +x script
). - Command Not Found: Ensure
ffmpeg
is installed and accessible from the command line.