Files
2026-07-09 01:05:56 +02:00

77 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# Usage function to display help
usage() {
echo "Usage: $0 [-no-source-mv] timestamp"
echo "e.g., $0 01:37:18 23:59:59"
}
# Check for the optional background flag
background=false
move_source=true
if [[ "$1" == "-no-source-mv" ]]; then
move_source=false
shift
fi
# Verify timestamp was provided
if [ "$#" -ne 2 ]; then
usage
exit 1
fi
# Find the first .mp4 file
shopt -s nullglob
mp4_files=(*.mp4)
VIDEO_FILE="${mp4_files[0]}"
if [ -z "$VIDEO_FILE" ]; then
echo "No .mp4 files found in the current directory."
exit 1
fi
echo "Video File: ${VIDEO_FILE}"
# Setting up directories
START_CUT="$1"
END_CUT="$2"
PROCESSED_DIR="processed"
OUTPUT_DIR="target"
base="${VIDEO_FILE%.*}"
run=$(date +%Y%m%d_%H%M%S)
RUN_DIR="${OUTPUT_DIR}/${base}/${base} - ${run}"
OUTPUT_FILE="${RUN_DIR}/${base} - ${run} - %03d.png"
# Create directories
mkdir -p "${RUN_DIR}"
mkdir -p "${PROCESSED_DIR}"
# Move the source video to the "processed" directory
SOURCE_PATH="${VIDEO_FILE}"
if $move_source; then
mv "${VIDEO_FILE}" "${PROCESSED_DIR}/"
SOURCE_PATH="${PROCESSED_DIR}/${VIDEO_FILE}"
fi
LOGS_DIR="logs"
mkdir -p "${LOGS_DIR}"
LOG_FILE="${LOGS_DIR}/$(basename "${VIDEO_FILE}" .mp4).log"
export VIDEO_TAG="SCREENSHOT"
# Run ffmpeg command with output redirection to log file
if $background; then
echo "Processing ${VIDEO_FILE} in the background..."
nohup bash -c "VIDEO_TAG='${VIDEO_TAG}' ./ffmpeg -ss '${START_CUT}' -to '${END_CUT}' -i '${SOURCE_PATH}' -vf \"select='eq(pict_type,PICT_TYPE_I)'\" -vsync vfr '${OUTPUT_FILE}'" >> "${LOG_FILE}" 2>&1 &
echo "Extracting screenshots complete! Output is in ${OUTPUT_FILE}"
echo "Log file: ${LOG_FILE}"
else
VIDEO_TAG="${VIDEO_TAG}" ./ffmpeg -ss "${START_CUT}" -to "${END_CUT}" -i "${SOURCE_PATH}" -vf "select='eq(pict_type,PICT_TYPE_I)'" -vsync vfr "${OUTPUT_FILE}" 2>&1 | tee "${LOG_FILE}"
echo "Extracting screenshots complete! Output is in ${OUTPUT_FILE}"
echo "Log file: ${LOG_FILE}"
fi