---
title: "VideoIntervals"
language: "en"
type: "Symbol"
summary: "VideoIntervals[video, crit] returns time intervals of video for which the criterion crit is satisfied. VideoIntervals[video, crit, n] evaluates criterion crit on partitions of n video frames. VideoIntervals[video, crit, n, d] evaluates crit on partitions with offset d. VideoIntervals[{video1, video2, ...}, crit, ...] applies crit to a list of inputs extracted from each videoi."
keywords: 
- video interval
- still image interval
- video time stamps
- video scenes
- keyframe intervals
- shot segments
- video segments
canonical_url: "https://reference.wolfram.com/language/ref/VideoIntervals.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Video Analysis"
    link: "https://reference.wolfram.com/language/guide/VideoAnalysis.en.md"
  - 
    title: "Video Computation: Update History"
    link: "https://reference.wolfram.com/language/guide/VideoComputation-UpdateHistory.en.md"
related_functions: 
  - 
    title: "Video"
    link: "https://reference.wolfram.com/language/ref/Video.en.md"
  - 
    title: "VideoMapTimeSeries"
    link: "https://reference.wolfram.com/language/ref/VideoMapTimeSeries.en.md"
  - 
    title: "VideoMapList"
    link: "https://reference.wolfram.com/language/ref/VideoMapList.en.md"
  - 
    title: "VideoTrim"
    link: "https://reference.wolfram.com/language/ref/VideoTrim.en.md"
  - 
    title: "VideoExtractFrames"
    link: "https://reference.wolfram.com/language/ref/VideoExtractFrames.en.md"
  - 
    title: "AudioIntervals"
    link: "https://reference.wolfram.com/language/ref/AudioIntervals.en.md"
---
[EXPERIMENTAL]

# VideoIntervals

VideoIntervals[video, crit] returns time intervals of video for which the criterion crit is satisfied.

VideoIntervals[video, crit, n] evaluates criterion crit on partitions of n video frames.

VideoIntervals[video, crit, n, d] evaluates crit on partitions with offset d.

VideoIntervals[{video1, video2, …}, crit, …] applies crit to a list of inputs extracted from each videoi.

## Details and Options

* ``VideoIntervals`` can be used to detect time intervals of interest in a video, such as constant frame, silent audio intervals, intervals containing a specific object, etc.

[image]

* A criterion ``crit`` of a single argument gets applied to image frames or a list of image frames.

* A pure function ``crit`` can access video and audio data as well as time using the following arguments:

|                  |                                                         |
| ---------------- | ------------------------------------------------------- |
| #Image           | video frames as Image objects                           |
| #Audio           | a chunk of the audio as an Audio object                 |
| #Time            | time from the beginning of the video                    |
| #TimeInterval    | beginning and end time stamps for the current partition |
| #FrameIndex      | index of the current output frame                       |
| #InputFrameIndex | index of the current input frame                        |

* In ``VideoIntervals[{video1, video2, …}, crit, …]``, data provided to each of the arguments is a list where the $$\text{\textit{$i$}}^{\text{th}}$$ element corresponds to the data extracted from ``videoi``.

* By default, partitions are offset by one frame.

* ``VideoIntervals`` supports video containers and codecs specified by ``\$VideoDecoders``.

* The following options can be given:

|           |          |                                              |
| --------- | -------- | -------------------------------------------- |
| Alignment | Center   | alignment of the time stamps with partitions |
| MaxItems  | Infinity | maximum number of intervals to return        |

* By default, measurements are returned at the center of each partition. Using the ``Alignment`` option, measurements can be returned at the beginning (``Left``) or end (``Right``) of each partition.

## Examples (10)

### Basic Examples (2)

Find video intervals with constant frames:

```wl
In[1]:= v = Video["ExampleData/Caminandes.mp4"];

In[2]:= VideoIntervals[v, Max[#Image] - Min[#Image] < .01&]

Out[2]= {{0., 2.125}, {63.6667, 65.0833}, {76.0833, 76.3333}, {81.0833, 82.875}, {86.5833, 88.0417}}
```

---

Find video intervals with loud audio:

```wl
In[1]:= v = Video["ExampleData/bullfinch.mkv"];

In[2]:= VideoIntervals[v, First@Mean[Abs@#Audio] > .1&]

Out[2]= {{3.139, 3.239}, {6.877, 6.91}, {7.143, 7.176}, {7.31, 7.377}, {9.479, 9.546}, {9.613, 9.679}, {9.746, 9.812}, {9.88, 9.979}}
```

### Scope (5)

Specify the criterion as a pure function:

```wl
In[1]:= v = VideoTrim[Video["ExampleData/bullfinch.mkv"], {1, 2}];

In[2]:= VideoIntervals[v, ImageMeasurements[#Image, "MeanIntensity"] < .47&]

Out[2]= {{0.067, 0.799999}}
```

Specify the criterion as a normal function:

```wl
In[3]:= crit[assoc_] := ImageMeasurements[assoc["Image"], "MeanIntensity"] < .47

In[4]:= VideoIntervals[v, crit]

Out[4]= {{0.067, 0.799999}}
```

---

The input to the criterion function is an association with keys ``"Time"``, ``"TimeInterval"``, ``"Image"``, ``"FrameIndex"``, ``"InputFrameIndex"`` and ``"Audio"`` (if present):

```wl
In[1]:= v = VideoTrim[Video["ExampleData/bullfinch.mkv"], {1, 2}];

In[2]:=
inputs = {};
VideoIntervals[v, (AppendTo[inputs, #];False)&];
inputs[[1]]

Out[2]= <|"Time" -> 0.0166665, "TimeInterval" -> {0., 0.033333}, "TimeList" -> {0.0166665}, "TimeIntervalList" -> {{0., 0.033333}}, "InputFrameIndex" -> 1, "FrameIndex" -> 1, "Image" -> [image], "Audio" -> \!\(\*AudioBox["![Embedded Audio Player](audio://content-lc3b5)"]\)|>
```

---

Evaluate the criterion on a buffer of five frames:

```wl
In[1]:= v = VideoTrim[Video["ExampleData/bullfinch.mkv"], {1, 2}];

In[2]:= VideoIntervals[v, ImageMeasurements[Mean@#Image, "MeanIntensity"] < .47&, 5]

Out[2]= {{0., 0.899999}}
```

If the partition size is not ``Automatic``, the value for ``"Image"`` will be a list of images:

```wl
In[3]:=
inputs = {};
VideoIntervals[v, (AppendTo[inputs, #];False)&, 5];

In[4]:= inputs[[1, "Image"]]

Out[4]= {[image], [image], [image], [image], [image]}
```

The value for ``"Audio"`` is always a single ``Audio`` object of the appropriate duration:

```wl
In[5]:= Duration@inputs[[1, "Audio"]]

Out[5]= Quantity[0.16666666666666666, "Seconds"]
```

---

Evaluate the criterion on non-overlapping partitions of five frames:

```wl
In[1]:= v = Video["ExampleData/bullfinch.mkv"];VideoIntervals[v, ImageMeasurements[Mean@#Image, "MeanIntensity"] < .47&, 5, 5]

Out[1]= {{0.003, 0.335999}, {1.171, 1.337}, {2.339, 2.672}, {2.839, 14.017}}
```

---

Specify partition size and offset using time quantities:

```wl
In[1]:= v = Video["ExampleData/bullfinch.mkv"];VideoIntervals[v, ImageMeasurements[Mean@#Image, "MeanIntensity"] < .47&, Quantity[1, "Seconds"], Quantity[0.5, "Seconds"]]

Out[1]= {{2.506, 14.516}}
```

### Options (1)

#### MaxItems (1)

By default, using ``MaxItems -> ∞``, the whole input is evaluated for possible intervals of interest:

```wl
In[1]:= v = Video["ExampleData/bullfinch.mkv"];

In[2]:= Options[VideoIntervals]

Out[2]= {MaxItems -> ∞}

In[3]:= VideoIntervals[v, ImageMeasurements[#Image, "MeanIntensity"] < .47&]

Out[3]= {{0.003, 0.235999}, {1.104, 1.337}, {1.571, 1.738}, {2.239, 2.672}, {2.806, 8.611}, {8.645, 14.05}, {14.084, 14.117}}
```

Stop the computation once ``n`` complete intervals have been detected:

```wl
In[4]:= VideoIntervals[v, ImageMeasurements[#Image, "MeanIntensity"] < .47&, MaxItems -> 2]

Out[4]= {{0.003, 0.235999}, {1.104, 1.337}}
```

### Applications (2)

Find the intervals that contain the most motion in a video:

```wl
In[1]:= v = Video["ExampleData/bullfinch.mkv"];VideoIntervals[v, ImageMeasurements[ImageDifference@@#Image, "MeanIntensity"] > .025&, 2]

Out[1]= {{0.871, 0.936999}, {8.512, 8.611}, {8.712, 8.778}}
```

Extract the corresponding frames:

```wl
In[2]:= VideoExtractFrames[v, Interval@@%]//ImageCollage

Out[2]= [image]
```

---

Find the intervals that contain constant frames:

```wl
In[1]:= v = Video["ExampleData/Caminandes.mp4"];

In[2]:= int = VideoIntervals[v, Max[#Image] - Min[#Image] < .1&]

Out[2]= {{0., 2.41667}, {63.6667, 65.1667}, {76.0833, 76.3333}, {81.0833, 82.875}, {86.25, 88.0417}}
```

Delete such intervals from the video:

```wl
In[3]:= VideoDelete[v, int]

Out[3]= [image]
```

Compare the duration of the original and resulting videos:

```wl
In[4]:= Duration /@ {v, %}

Out[4]= {Quantity[MixedMagnitude[{1, 30.023}], MixedUnit[{"Minutes", "Seconds"}]], Quantity[MixedMagnitude[{1, 22.362}], MixedUnit[{"Minutes", "Seconds"}]]}
```

## See Also

* [`Video`](https://reference.wolfram.com/language/ref/Video.en.md)
* [`VideoMapTimeSeries`](https://reference.wolfram.com/language/ref/VideoMapTimeSeries.en.md)
* [`VideoMapList`](https://reference.wolfram.com/language/ref/VideoMapList.en.md)
* [`VideoTrim`](https://reference.wolfram.com/language/ref/VideoTrim.en.md)
* [`VideoExtractFrames`](https://reference.wolfram.com/language/ref/VideoExtractFrames.en.md)
* [`AudioIntervals`](https://reference.wolfram.com/language/ref/AudioIntervals.en.md)

## Related Guides

* [Video Analysis](https://reference.wolfram.com/language/guide/VideoAnalysis.en.md)
* [Video Computation: Update History](https://reference.wolfram.com/language/guide/VideoComputation-UpdateHistory.en.md)

## History

* [Introduced in 2020 (12.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn122.en.md)