Update 2025-04-12_09:56:11
This commit is contained in:
46
calculate_bitrate.sh
Executable file
46
calculate_bitrate.sh
Executable file
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if the folder is provided as an argument
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <folder_with_videos>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VIDEO_FOLDER="$1"
|
||||
OUTPUT_FILE="bitrates.txt"
|
||||
TOTAL_BITRATE=0
|
||||
VIDEO_COUNT=0
|
||||
|
||||
# Clear or create the output file
|
||||
> "$OUTPUT_FILE"
|
||||
|
||||
# Function to get bitrate of a video in Mbps
|
||||
get_bitrate() {
|
||||
local video_file="$1"
|
||||
bitrate_kbps=$(ffprobe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "$video_file" | head -n 1)
|
||||
if [[ "$bitrate_kbps" =~ ^[0-9]+$ ]]; then
|
||||
bitrate_mbps=$(echo "scale=2; $bitrate_kbps / 1000 / 1000" | bc)
|
||||
echo "$bitrate_mbps"
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
# Iterate through each video file in the folder
|
||||
for video_file in "$VIDEO_FOLDER"/*; do
|
||||
if [ -f "$video_file" ]; then
|
||||
bitrate=$(get_bitrate "$video_file")
|
||||
echo "File: $video_file - Bitrate: ${bitrate} Mbps" | tee -a "$OUTPUT_FILE"
|
||||
TOTAL_BITRATE=$(echo "$TOTAL_BITRATE + $bitrate" | bc)
|
||||
((VIDEO_COUNT++))
|
||||
fi
|
||||
done
|
||||
|
||||
# Calculate the average bitrate
|
||||
if [ "$VIDEO_COUNT" -gt 0 ]; then
|
||||
AVERAGE_BITRATE=$(echo "scale=2; $TOTAL_BITRATE / $VIDEO_COUNT" | bc)
|
||||
echo "Average Bitrate: $AVERAGE_BITRATE Mbps" | tee -a "$OUTPUT_FILE"
|
||||
else
|
||||
echo "No video files found in the specified folder." | tee -a "$OUTPUT_FILE"
|
||||
fi
|
||||
|
Reference in New Issue
Block a user