Files
Video-Processing-Scripts/skill/Get-FramesRange.md
T

3.2 KiB

Get-FramesRange.ps1

Extracts a specific range of frames from a video file to PNG images.

Parameters

  • -Video (required): Path to input video file
  • -Images (optional): Path to output PNG images file pattern. Can be absolute or relative to current directory. If not provided, the output files will be in subdirectory 'Frames' and named as the video file with a frame number suffix padded with zeros to 4 digits.
  • -Frames (required): Frame range specification (see formats below)

Frame Range Formats

  • start-end: Extract frames from start to end index (e.g., 100-200)
  • positive_number: Extract frames from 0 to that number (e.g., 50 extracts frames 0-50)
  • -negative_number: Extract last N frames (e.g., -10 extracts last 10 frames)
  • %: Represents the last frame index. Can be used alone or in ranges:
    • % - Extract only the last frame
    • 10-% - Extract from frame 10 to the last frame
    • -% - Extract only the first frame (frame 0)
  • all: Extract all frames (same as 0-%)

Examples

Extract specific range:

.\Get-Frames.ps1 -Video video.mp4 -Frames "100-200"
# Creates: Frames/video_0100.png, Frames/video_0101.png, ..., Frames/video_0200.png

Extract first 50 frames:

.\Get-Frames.ps1 -Video video.mp4 -Frames "50"
# Creates: Frames/video_0000.png through Frames/video_0050.png

Extract last 10 frames:

.\Get-Frames.ps1 -Video video.mp4 -Frames "-10"
# If video has 500 frames, creates: Frames/video_0490.png through Frames/video_0499.png

Extract only the last frame:

.\Get-Frames.ps1 -Video video.mp4 -Frames "%"
# If video has 500 frames, creates: Frames/video_0499.png

Extract from frame 10 to the last frame:

.\Get-Frames.ps1 -Video video.mp4 -Frames "10-%"
# If video has 500 frames, creates: Frames/video_0010.png through Frames/video_0499.png

Extract only the first frame:

.\Get-Frames.ps1 -Video video.mp4 -Frames "-%"
# Creates: Frames/video_0000.png

Extract all frames:

.\Get-Frames.ps1 -Video video.mp4 -Frames "all"
# If video has 500 frames, creates: Frames/video_0000.png through Frames/video_0499.png

Custom output pattern:

.\Get-Frames.ps1 -Video video.mp4 -Frames "0-100" -Images "output_frame"
# Creates: output_frame_0000.png through output_frame_0100.png

Full output path:

.\Get-Frames.ps1 -Video video.mp4 -Frames "50-150" -Images "C:\Output\frame_%04d.png"

Note: Frame numbers in output filenames reflect the actual video frame index (0-based).

Existing Files

An existing PNG with the same name is replaced. Use -WhatIf to check the output names first.

Safe Execution

This script supports -WhatIf and -Confirm for safe execution:

  • -WhatIf: Simulate the operation without actually extracting frames. Shows which frames would be extracted.
  • -Confirm: Prompt for confirmation before extracting each frame.

Simulate without extracting:

.\Get-Frames.ps1 -Video video.mp4 -Frames "100-200" -WhatIf

Prompt before each frame:

.\Get-Frames.ps1 -Video video.mp4 -Frames "0-10" -Confirm