Advertisement
DenisSergeevitch

ffmpeg: timestamps // gpt4

May 15th, 2024
1,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. input_file="google-io_p2_compressed.mp4"
  4. output_file="highlighted_gemini_p2.mp4"
  5.  
  6. # Updated list of timestamps
  7. timestamps=("00:24" "04:00" "04:15" "04:35" "07:18" "09:15" "09:46" "11:27" "11:56" "12:07" "12:16" "12:58" "15:54" "16:43" "17:15" "18:29" "19:01" "19:30" "20:03" "24:09" "27:29" "28:09" "28:44" "29:02" "29:10" "29:27" "29:52" "31:20" "31:56" "34:46" "35:35" "35:40" "36:27" "36:31" "36:48" "36:56" "39:32")
  8.  
  9. mkdir temp_segments
  10. cd temp_segments
  11.  
  12. # Cutting video into segments ensuring they start on a keyframe
  13. for ts in "${timestamps[@]}"; do
  14.     IFS=: read min sec <<< "$ts"
  15.     start_time=$(bc <<< "scale=2; $min*60 + $sec - 0.5")
  16.     end_time=$(bc <<< "scale=2; $min*60 + $sec + 0.5")
  17.     ffmpeg -ss $start_time -to $end_time -i "../$input_file" -c:v libx264 -force_key_frames "expr:gte(t,n_forced*1)" -preset fast "segment_${min}_${sec}.mp4"
  18. done
  19.  
  20. # Create a text file for file concatenation
  21. for f in segment_*.mp4; do
  22.     echo "file '$f'" >> concat_list.txt
  23. done
  24.  
  25. # Using the concat filter to re-encode and concatenate segments
  26. ffmpeg -f concat -safe 0 -i concat_list.txt -c:v libx264 -preset fast -c:a aac -b:a 192k "../$output_file"
  27.  
  28. cd ..
  29. rm -r temp_segments
  30.  
  31. echo "Processing complete. Check your output file: $output_file"
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement