npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expo-trim-video

v1.0.1

Published

A video trimmer package for Expo apps

Readme

expo-trim-video

A native Expo module for trimming videos on Android and iOS devices.

Features

  • ✅ Trim videos by specifying start and end times
  • ✅ Support for various video formats (MP4, MOV, etc.)
  • ✅ Handle file:// and content:// URIs
  • ✅ Error handling for invalid inputs and file issues
  • ✅ Fast video processing using native platform APIs
  • ✅ Cross-platform support for Android and iOS

Installation

npm install expo-trim-video

Usage

import { trimVideo } from 'expo-trim-video';

// Trim a video from 5 seconds to 15 seconds
try {
  const result = await trimVideo({
    uri: 'file:///path/to/your/video.mp4', // or content:// URI
    start: 5,  // Start time in seconds
    end: 15    // End time in seconds
  });
  
  console.log('Trimmed video saved to:', result.uri);
} catch (error) {
  console.error('Error trimming video:', error.message);
}

API

trimVideo(options: TrimVideoOptions): Promise<TrimVideoResult>

Trims a video file according to the specified options.

Parameters

  • options.uri (string): The URI of the video file to trim. Supports:

    • File URIs: file:///path/to/video.mp4
    • Content URIs (Android): content://...
    • Photos URIs (iOS): ph://...
    • Absolute paths: /storage/emulated/0/Movies/video.mp4
  • options.start (number): Start time in seconds (must be >= 0)

  • options.end (number): End time in seconds (must be > start and <= video duration)

Returns

Promise that resolves to:

{
  uri: string; // File URI of the trimmed video
}

Error Codes

  • INVALID_ARGUMENTS: Missing or invalid URI
  • INVALID_START: Start time is negative
  • INVALID_END: End time exceeds video duration
  • INVALID_RANGE: Start time is greater than or equal to end time
  • INVALID_URI: Invalid URI format (iOS)
  • FILE_NOT_FOUND: Video file not found or invalid
  • TRIM_ERROR: General error during video processing

Platform Support

  • Android: Full support using MediaExtractor/MediaMuxer
  • iOS: Full support using AVFoundation
  • Web: Not supported (returns error)

Example App

The example app demonstrates how to use the module:

  1. Enter a video URI (file path or content URI)
  2. Set start and end times
  3. Tap "Trim Video" to process

To run the example:

cd example
npm install

# For Android
npx expo run:android

# For iOS
npx expo run:ios

Technical Details

Android Implementation

The Android implementation uses:

  • MediaExtractor to read video data
  • MediaMuxer to write the trimmed output
  • MediaMetadataRetriever to validate video duration and get metadata

The module preserves:

  • Video quality (no re-encoding when possible)
  • Audio tracks
  • Video rotation metadata
  • Original codecs and formats

iOS Implementation

The iOS implementation uses:

  • AVAsset to load and analyze video files
  • AVAssetExportSession for efficient video trimming
  • CMTime for precise time handling

The module preserves:

  • Video quality using AVAssetExportPresetHighestQuality
  • Audio tracks
  • Video orientation and metadata
  • Optimal file compression

Performance

Video trimming is performed efficiently by:

Android:

  • Seeking to the start position using SEEK_TO_CLOSEST_SYNC
  • Copying video/audio samples without re-encoding
  • Processing only the required time range

iOS:

  • Using AVAssetExportSession for hardware-accelerated processing
  • Setting precise time ranges with CMTimeRange
  • Preserving original video quality and metadata

Troubleshooting

Common Issues

  1. "File not found" error:

    • Ensure the video file exists and is accessible
    • Check file permissions
    • Try using a content:// URI (Android) or ph:// URI (iOS) for media files
  2. "End time exceeds video duration":

    • Check the actual video duration
    • Ensure end time is less than video length
  3. "Invalid range" error:

    • Ensure start < end
    • Both times must be positive
  4. "Invalid URI format" (iOS):

    • Ensure the URI is properly formatted
    • Use file:// prefix for local files
    • Use ph:// for Photos library assets

Getting Video URIs

You can get video URIs using:

  • expo-document-picker for user-selected files
  • expo-media-library for accessing device media
  • expo-file-system for app-specific files
  • expo-image-picker for camera/gallery videos

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.