Skip to content

Commit eef4622

Browse files
committed
feat: add video files duration script
1 parent 5ecefb4 commit eef4622

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

playground/34-video-duration.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
total_duration=0
2+
for file in ./*.mp4; do
3+
if [ -f "$file" ]; then
4+
echo "File: $file"
5+
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file" 2>/dev/null)
6+
total_duration=$(echo "$total_duration + $duration" | bc)
7+
fi
8+
done
9+
10+
# Calculate minutes, seconds, and fractional seconds separately
11+
total_minutes=$(bc <<< "scale=0; $total_duration / 60")
12+
total_seconds=$(bc <<< "scale=0; $total_duration % 60")
13+
total_fractional_seconds=$(bc <<< "scale=6; $total_duration - ($total_minutes * 60) - $total_seconds")
14+
15+
echo "Total Duration: $total_minutes minutes $total_seconds seconds $total_fractional_seconds seconds"
16+

playground/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ For Stable Diffusion, you need to add your `STABILITY_AI_KEY`. You can find it i
108108
- [renaming files](22-rename.py) in a folder.
109109
- [reorganizing files](31-reorganizing-files.ipynb).
110110
- [calculating and displaying the total size of files](32-space.sh) modified today using a Bash script.
111+
- [calculating total duration of video files](34-video-duration.sh) in a directory.
111112

112113
## Using ChatGPT for Programming Development
113114

0 commit comments

Comments
 (0)