42 lines
1.1 KiB
Bash
Executable File
42 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check if all required arguments are provided
|
|
if [ $# -lt 3 ]; then
|
|
echo "Usage: $0 <input_file> <output_file> <duration>"
|
|
echo ""
|
|
echo "Arguments:"
|
|
echo " <input_file> Path to the input video file."
|
|
echo " <output_file> Path to the output video file."
|
|
echo " <duration> Duration of the extracted segment in format HH:MM:SS or seconds."
|
|
echo ""
|
|
echo "Example:"
|
|
echo " $0 input.mp4 output.mp4 30"
|
|
echo " $0 input.mp4 output.mp4 00:00:30"
|
|
echo ""
|
|
echo "Note: The output file will contain the first <duration> seconds of the input file."
|
|
exit 1
|
|
fi
|
|
|
|
# Assign input arguments to variables
|
|
input_file=$1
|
|
output_file=$2
|
|
duration=$3
|
|
|
|
# Check if the input file exists
|
|
if [ ! -f "$input_file" ]; then
|
|
echo "Error: The input file '$input_file' does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
# Run the ffmpeg command
|
|
ffmpeg -i "$input_file" -t "$duration" -vcodec copy -acodec copy "$output_file"
|
|
|
|
# Check if the ffmpeg command succeeded
|
|
if [ $? -eq 0 ]; then
|
|
echo "Video extraction completed successfully. Output saved to '$output_file'."
|
|
else
|
|
echo "Error: ffmpeg failed to extract the video."
|
|
exit 1
|
|
fi
|
|
|