-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusp_segment_duration_to_markdown.sh
More file actions
104 lines (83 loc) · 2.8 KB
/
Copy pathusp_segment_duration_to_markdown.sh
File metadata and controls
104 lines (83 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# Usage: ./script.sh baseurl representation end_number output_folder
# Check if the correct number of arguments are provided
if [ "$#" -ne 4 ]; then
echo "Usage: $0 baseurl representation end_number output_folder"
exit 1
fi
# Input parameters
baseurl="$1"
representation="$2"
end_number="$3"
output_folder="$4"
# Create output folder
mkdir -p "$output_folder"
# Download initialization segment
echo "Downloading initialization segment..."
init_url="$baseurl/index.ism/dash/index-$representation.dash"
curl -s "$init_url" -o "$output_folder/seg-init.m4s"
# Check if the initialization segment was downloaded successfully
if [ ! -f "$output_folder/seg-init.m4s" ]; then
echo "Failed to download initialization segment from $init_url"
exit 1
fi
# Initialize arrays to store durations
declare -a durations
# Iterate from 1 to end_number
for (( i=1; i<=end_number; i++ ))
do
echo "Processing segment $i..."
# Define segment URLs and file paths
segment_url="$baseurl/index.ism/dash/index-$representation-$i.m4s"
segment_file="$output_folder/seg$i.m4s"
combined_file="$output_folder/seg$i-combined.m4s"
# Download each segment
curl -s "$segment_url" -o "$segment_file"
# Check if the segment was downloaded successfully
if [ ! -f "$segment_file" ]; then
echo "Failed to download segment $i from $segment_url"
durations[$i]="0"
continue
fi
# Combine with initialization segment
cat "$output_folder/seg-init.m4s" "$segment_file" > "$combined_file"
# Run ffprobe to get duration
duration=$(ffprobe -v quiet -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$combined_file")
# Check if ffprobe succeeded
if [ -z "$duration" ]; then
echo "Failed to get duration for segment $i."
duration="0"
fi
# Store duration
durations[$i]="$duration"
done
# Create summary.md
summary_file="$output_folder/summary.md"
{
echo "# Segment Timing Summary"
echo ""
echo "**Base URL:** $baseurl"
echo "**Representation:** $representation"
echo "**End Number:** $end_number"
echo ""
echo "| Index | Duration (s) | Length (s) |"
echo "|-------|--------------|------------|"
} > "$summary_file"
# Write table rows
prev_duration=0
for (( i=1; i<=end_number; i++ ))
do
duration=${durations[$i]}
if [ -z "$duration" ]; then
duration="0"
fi
# Calculate length
length=$(echo "$duration - $prev_duration" | bc)
prev_duration="$duration"
# Format the duration and length to 6 decimal places
duration_formatted=$(printf "%.6f" "$duration")
length_formatted=$(printf "%.6f" "$length")
# Write to summary file
echo "| $i | $duration_formatted | $length_formatted |" >> "$summary_file"
done
echo "Summary written to $summary_file"