Please write a more efficient version of this script that works with files with bad…
Private research annotation
Sign in to add a private research label or note.
- User
Please write a more efficient version of this script that works with files with bad metadata: #!/bin/bash
Function to get video bitrate
get_video_bitrate() { local input_file="$1"
code# Try multiple methods to get bitrate # Method 1: Detailed stream info local bitrate=$(ffprobe -v quiet -print_format json -show_streams "$input_file" | \ jq -r '.streams[] | select(.codec_type=="video") | .bit_rate' 2>/dev/null) # If first method fails, try alternative methods if [ -z "$bitrate" ] || [ "$bitrate" = "N/A" ] || [ "$bitrate" = "0" ]; then # Method 2: Format info bitrate=$(ffprobe -v quiet -print_format json -show_format "$input_file" | \ jq -r '.format.bit_rate' 2>/dev/null) fi # If still no bitrate, estimate from file size if [ -z "$bitrate" ] || [ "$bitrate" = "N/A" ] || [ "$bitrate" = "0" ]; then local file_size=$(stat -c%s "$input_file") local duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$input_file") # Fallback calculation if duration is available if [ ! -z "$duration" ]; then # Convert to bits per second bitrate=$(echo "scale=0; ($file_size * 8) / $duration" | bc) else echo 0 return 1 fi fi # Ensure we have a numeric value if [[ "$bitrate" =~ ^[0-9]+$ ]]; then echo "$bitrate" else echo 0 return 1 fi}
Function to calculate segment time
calculate_segment_time() { local input_file="$1" local target_size_mb=9.5
code Assistant
- User
It is okay for the segment time to be longer than 60 seconds but we absolutely cannot exceed 10mb in total which is why we are targeting 9.5mb
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.