Skip to content

Commit 33f37f7

Browse files
Update documentation
Update documentation to cover all the options and default values
1 parent 4df47b5 commit 33f37f7

3 files changed

Lines changed: 79 additions & 9 deletions

File tree

android/src/main/java/com/visionutils/VideoFrameExtractorAndroid.kt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,44 @@ import kotlin.math.abs
1616
import kotlin.math.min
1717

1818
/**
19-
* Extracts frames from video files at specific timestamps or intervals
19+
* Extracts frames from video files at specific timestamps or intervals.
20+
*
21+
* Supports three extraction modes:
22+
* - `timestamps`: Array of specific timestamps in seconds
23+
* - `interval`: Extract every N seconds (with optional startTime/endTime/maxFrames)
24+
* - `count`: Extract N evenly-spaced frames
25+
*
26+
* If no mode is specified, extracts a single frame at t=0.
27+
*
28+
* **Supported source types:** `file`, `url` only (asset not supported on Android)
29+
*
30+
* **Output formats:**
31+
* - `base64` (default): JPEG encoded, quality 0-100 (default 90)
32+
* - `pixelData`: Raw pixel arrays with optional colorFormat/normalization
33+
*
34+
* **Note:** `colorFormat` and `normalization` only apply when `outputFormat === "pixelData"`.
35+
*
36+
* Per-frame extraction errors are captured in the frame's `error` field; extraction continues for remaining frames.
2037
*/
2138
object VideoFrameExtractorAndroid {
2239

2340
/**
2441
* Extract frames from a video file
25-
* @param source Video source (file path or URL)
26-
* @param options Extraction options (timestamps, interval, resize, etc.)
27-
* @return Map with extracted frames and metadata
42+
*
43+
* @param source Video source with `type` (file/url) and `value` (path or URL string).
44+
* Note: `asset` type is NOT supported on Android.
45+
* @param options Extraction options:
46+
* - `timestamps`: DoubleArray - specific timestamps in seconds
47+
* - `interval`: Double - extract every N seconds
48+
* - `count`: Int - number of evenly-spaced frames
49+
* - `startTime`/`endTime`: Double - range for interval/count modes
50+
* - `maxFrames`: Int - limit for interval mode (default 100)
51+
* - `resize`: {width: Int, height: Int} - resize frames
52+
* - `outputFormat`: "base64" (default) or "pixelData"
53+
* - `quality`: Int 0-100 (default 90) - JPEG quality for base64
54+
* - `colorFormat`: String - for pixelData (rgb/rgba/bgr/grayscale)
55+
* - `normalization`: {preset: String} - for pixelData (scale/imagenet/tensorflow)
56+
* @return WritableMap with `frames`, `frameCount`, `videoDuration`, `videoWidth`, `videoHeight`, `frameRate`, `processingTimeMs`
2857
*/
2958
fun extractFrames(source: ReadableMap, options: ReadableMap): WritableMap {
3059
val startTime = System.currentTimeMillis()

ios/VideoFrameExtractor.swift

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,41 @@ import AVFoundation
22
import UIKit
33
import Accelerate
44

5-
/// Extracts frames from video files at specific timestamps or intervals
5+
/// Extracts frames from video files at specific timestamps or intervals.
6+
///
7+
/// Supports three extraction modes:
8+
/// - `timestamps`: Array of specific timestamps in seconds
9+
/// - `interval`: Extract every N seconds (with optional startTime/endTime/maxFrames)
10+
/// - `count`: Extract N evenly-spaced frames
11+
///
12+
/// If no mode is specified, extracts a single frame at t=0.
13+
///
14+
/// **Supported source types:** `file`, `url`, `asset`
15+
///
16+
/// **Output formats:**
17+
/// - `base64` (default): JPEG encoded, quality 0-100 (default 90)
18+
/// - `pixelData`: Raw pixel arrays with optional colorFormat/normalization
19+
///
20+
/// **Note:** `colorFormat` and `normalization` only apply when `outputFormat === "pixelData"`.
21+
///
22+
/// Per-frame extraction errors are captured in the frame's `error` field; extraction continues for remaining frames.
623
class VideoFrameExtractor {
724

825
/// Extract frames from a video file
926
/// - Parameters:
10-
/// - source: Video source (file path or URL)
11-
/// - options: Extraction options (timestamps, interval, resize, etc.)
12-
/// - Returns: Dictionary with extracted frames and metadata
27+
/// - source: Video source with `type` (file/url/asset) and `value` (path or URL string)
28+
/// - options: Extraction options:
29+
/// - `timestamps`: [Double] - specific timestamps in seconds
30+
/// - `interval`: Double - extract every N seconds
31+
/// - `count`: Int - number of evenly-spaced frames
32+
/// - `startTime`/`endTime`: Double - range for interval/count modes
33+
/// - `maxFrames`: Int - limit for interval mode (default 100)
34+
/// - `resize`: {width: Int, height: Int} - resize frames
35+
/// - `outputFormat`: "base64" (default) or "pixelData"
36+
/// - `quality`: Int 0-100 (default 90) - JPEG quality for base64
37+
/// - `colorFormat`: String - for pixelData (rgb/rgba/bgr/grayscale)
38+
/// - `normalization`: {preset: String} - for pixelData (scale/imagenet/tensorflow)
39+
/// - Returns: Dictionary with `frames`, `frameCount`, `videoDuration`, `videoWidth`, `videoHeight`, `frameRate`, `processingTimeMs`
1340
static func extractFrames(source: [String: Any], options: [String: Any]) async throws -> [String: Any] {
1441
let startTime = CFAbsoluteTimeGetCurrent()
1542

src/index.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,21 @@ export async function detectBlur(
26292629
* Frames can be returned as base64-encoded JPEG images or as raw pixel arrays
26302630
* suitable for direct use with ML models.
26312631
*
2632-
* @param source - Video source (file path or URL)
2632+
* **Defaults:**
2633+
* - If no mode specified (timestamps/interval/count), extracts single frame at t=0
2634+
* - outputFormat: 'base64'
2635+
* - quality: 90 (0-100 for JPEG compression)
2636+
* - colorFormat/normalization: Only applied when outputFormat === 'pixelData'
2637+
*
2638+
* **Platform Notes:**
2639+
* - iOS: Supports 'file', 'url', and 'asset' source types
2640+
* - Android: Only supports 'file' and 'url' (asset not supported)
2641+
*
2642+
* **Error Handling:**
2643+
* - Per-frame errors are captured in frame.error field (extraction continues)
2644+
* - Result includes requestedTimestamp vs actual timestamp for each frame
2645+
*
2646+
* @param source - Video source (file path or URL). Note: 'asset' type is iOS-only.
26332647
* @param options - Extraction options (timestamps, interval, count, resize, etc.)
26342648
* @returns Promise resolving to extracted frames with metadata
26352649
*

0 commit comments

Comments
 (0)