how to detect shot boundary in video

4 ビュー (過去 30 日間)
malathi mani
malathi mani 2015 年 4 月 15 日
回答済み: prabhat kumar sharma 2025 年 1 月 23 日 4:25
SBD using adaptive threshold

回答 (1 件)

prabhat kumar sharma
prabhat kumar sharma 2025 年 1 月 23 日 4:25
Hello Malathi,
Detecting shot boundaries in a video involves identifying transitions between different scenes or shots. One common approach is to use an adaptive threshold method. Here's a concise guide on how to achieve this:
1. Extract Frames:
  • Convert the video into a series of frames.
2. Compute Frame Differences:
  • Calculate the difference between consecutive frames. This can be done using pixel-wise subtraction or more sophisticated methods like histogram differences.
3. Adaptive Thresholding:
  • Compute a threshold that adapts based on the frame differences. This can be done using statistical measures like mean and standard deviation of differences over a sliding window.
4. Detect Boundaries:
  • Identify frames where the difference exceeds the adaptive threshold. These frames are likely to be shot boundaries.
Here is a basic example :
% Read video
video = VideoReader('video.mp4');
numFrames = video.NumFrames;
% Initialize variables
frameDiffs = zeros(numFrames-1, 1);
% Compute frame differences
for i = 1:numFrames-1
frame1 = read(video, i);
frame2 = read(video, i+1);
frameDiffs(i) = sum(abs(frame1(:) - frame2(:))); % Sum of absolute differences
end
% Adaptive threshold
windowSize = 30; % Example window size
thresholds = movmean(frameDiffs, windowSize) + movstd(frameDiffs, windowSize);
% Detect shot boundaries
shotBoundaries = find(frameDiffs > thresholds);
% Display results
disp('Detected shot boundaries at frames:');
disp(shotBoundaries);
I hope it helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by