Fix -Frames negative range calculation to extract last N frames correctly (off-by-one error), add validation to reject invalid '-%' and '-0' formats with exit code 1, change '%' alone to extract single last frame instead of range, remove duplicate last frame from PNG sequence concat list, update Get-LastFrame.ps1 and Get-Frame.ps1 to clamp out-of-range frame indices instead of erroring and improve error messages with inline stderr output, add -y flag and -- separator to ffprobe calls, replace deprecated

This commit is contained in:
guru committed 2026-11-02 06:30:38 -05:00
1 parent cf41fb0ce5
commit 1227c6e153
13 files changed
+100 -86

No files matched your search

+13 -20
View File
@@ -12,11 +12,11 @@ Extracts a specific range of frames from a video file to PNG images.
- **`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:
- **`-negative_number`**: Extract the last N frames (e.g., `-10` extracts frames 90 to 99 of a 100-frame video; `-1` extracts the last frame only)
- **`%`**: The last frame index. Alone (`%`) it extracts only the last frame. In a range it is the end of the range:
- `%` - Extract only the last frame
- `10-%` - Extract from frame 10 to the last frame
- `-%` - Extract only the first frame (frame 0)
- `-%` is not supported and is rejected with exit code `1`
- **`all`**: Extract all frames (same as `0-%`)
## Examples
@@ -24,63 +24,56 @@ Extracts a specific range of frames from a video file to PNG images.
**Extract specific range:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "100-200"
.\Get-FramesRange.ps1 -Video video.mp4 -Frames "100-200"
# Creates: Frames/video_0100.png, Frames/video_0101.png, ..., Frames/video_0200.png
```
**Extract first 50 frames:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "50"
.\Get-FramesRange.ps1 -Video video.mp4 -Frames "50"
# Creates: Frames/video_0000.png through Frames/video_0050.png
```
**Extract last 10 frames:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "-10"
.\Get-FramesRange.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:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "%"
.\Get-FramesRange.ps1 -Video video.mp4 -Frames "%"
# If video has 500 frames, creates: Frames/video_0499.png
```
**Extract from frame 10 to the last frame:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "10-%"
.\Get-FramesRange.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:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "-%"
# Creates: Frames/video_0000.png
```
**Extract all frames:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "all"
.\Get-FramesRange.ps1 -Video video.mp4 -Frames "all"
# If video has 500 frames, creates: Frames/video_0000.png through Frames/video_0499.png
```
**Custom output pattern:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "0-100" -Images "output_frame"
.\Get-FramesRange.ps1 -Video video.mp4 -Frames "0-100" -Images "output_frame"
# Creates: output_frame_0000.png through output_frame_0100.png
```
**Full output path:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "50-150" -Images "C:\Output\frame_%04d.png"
.\Get-FramesRange.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).
@@ -99,11 +92,11 @@ This script supports `-WhatIf` and `-Confirm` for safe execution:
**Simulate without extracting:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "100-200" -WhatIf
.\Get-FramesRange.ps1 -Video video.mp4 -Frames "100-200" -WhatIf
```
**Prompt before each frame:**
```powershell
.\Get-Frames.ps1 -Video video.mp4 -Frames "0-10" -Confirm
.\Get-FramesRange.ps1 -Video video.mp4 -Frames "0-10" -Confirm
```