#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Copyright (C) Intel Corporation # # Prepare the sample video for the scene-change-detection use case. # This use case uses classical computer vision (frame histogram # comparison) with OpenCV; no model export or quantization is required. # # A single continuous shot never triggers a scene change, so this script # builds a short montage (test_video.mp4) from several distinct sample # clips joined with hard cuts. Each clip is normalized to the same size and # frame rate and trimmed to 2 seconds, producing a scene change every 2 # seconds that the histogram detector flags. # Usage: ./export_and_quantize.sh set -euo pipefail SAMPLE_BASE_URL="https://github.com/intel-iot-devkit/sample-videos/raw/master" # Distinct scenes joined into the montage, in order. SAMPLE_CLIPS=( "one-by-one-person-detection.mp4" "bottle-detection.mp4" "person-bicycle-car-detection.mp4" "head-pose-face-detection-female.mp4" ) CLIP_SECONDS=2 # length of each scene in the montage CLIP_WIDTH=640 CLIP_HEIGHT=360 CLIP_FPS=30 # Ask for approval before downloading models and sample files echo "" echo "This script will download:" echo " - Model weights and/or sample files" echo "" read -p "Continue with downloads? (yes/no): " APPROVAL if [[ "${APPROVAL}" != "yes" ]]; then echo "Download cancelled by user." exit 0 fi command -v ffmpeg >/dev/null 2>&1 || { echo "ERROR: ffmpeg is required to build the montage sample video." >&2 exit 1 } echo "" if [[ -f test_video.mp4 ]]; then echo "Already present: test_video.mp4" else echo "--- Downloading sample clips and building montage ---" WORK_DIR="$(mktemp -d)" trap 'rm -rf "${WORK_DIR}"' EXIT CONCAT_LIST="${WORK_DIR}/concat.txt" : > "${CONCAT_LIST}" idx=0 for clip in "${SAMPLE_CLIPS[@]}"; do src="${WORK_DIR}/src_${idx}.mp4" norm="${WORK_DIR}/clip_${idx}.mp4" echo "Downloading: ${clip}" wget -q -O "${src}" "${SAMPLE_BASE_URL}/${clip}" # Trim to CLIP_SECONDS and normalize size/fps so the clips concatenate # cleanly and every join is a clean scene cut. ffmpeg -nostdin -y -loglevel error -t "${CLIP_SECONDS}" -i "${src}" \ -vf "scale=${CLIP_WIDTH}:${CLIP_HEIGHT},fps=${CLIP_FPS},setsar=1" \ -an -pix_fmt yuv420p "${norm}" echo "file 'clip_${idx}.mp4'" >> "${CONCAT_LIST}" idx=$((idx + 1)) done ffmpeg -nostdin -y -loglevel error -f concat -safe 0 -i "${CONCAT_LIST}" \ -c copy test_video.mp4 echo "Built: test_video.mp4 (${#SAMPLE_CLIPS[@]} scenes, ${CLIP_SECONDS}s each)" fi echo "--- Done ---" echo "Sample : $(pwd)/test_video.mp4" echo "Note : This use case requires no model; run the README samples directly."