Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -x #echo on
- SOURCE_VIDEO="$1"
- START_TIME="$2"
- END_TIME="$3"
- # Get total number of frames for progress tracking
- TOTAL_FRAMES=$(ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 "$SOURCE_VIDEO")
- if [ -z "$TOTAL_FRAMES" ]; then
- echo "Error: Unable to retrieve the total number of frames."
- exit 1
- fi
- # Initialize variables for tracking progress
- frames_processed=0
- start_frame=""
- end_frame=""
- start_diff=999999
- end_diff=999999
- # Function to display progress and information dynamically
- display_progress() {
- local progress=$(( frames_processed * 100 / TOTAL_FRAMES ))
- echo -ne "\rProcessed frames: $frames_processed / $TOTAL_FRAMES ($progress%) | Closest start frame: $start_frame | Closest end frame: $end_frame"
- }
- # Process frames
- ffprobe -show_frames -select_streams v:0 \
- -print_format csv "$SOURCE_VIDEO" 2>&1 |
- grep -n frame,video,1 |
- awk 'BEGIN { FS="," } { print $1 " " $5 }' |
- sed 's/:frame//g' |
- awk -v start="$START_TIME" -v end="$END_TIME" '
- BEGIN {
- start_frame="";
- end_frame="";
- start_diff=999999;
- end_diff=999999;
- between_frames="";
- }
- {
- split($2, time, ".");
- current = time[1];
- if (current > end) {
- exit;
- }
- if (start_frame == "" && current >= start) {
- start_frame = $1;
- start_diff = current - start;
- } else if (current >= start && (current - start) < start_diff) {
- start_frame = $1;
- start_diff = current - start;
- }
- if (current <= end && (end - current) < end_diff) {
- end_frame = $1;
- end_diff = end - current;
- }
- if (current >= start && current <= end) {
- between_frames = between_frames $1 ",";
- }
- }
- END {
- print "\nProcessing completed."
- print "Closest keyframe to start time: " start_frame;
- print "Closest keyframe to end time: " end_frame;
- print "All keyframes between start and end:";
- print substr(between_frames, 1, length(between_frames)-1);
- }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement