Skip to main content

Remove sections from video files without re-encoding

Project description

remove-sections

A command-line tool to remove sections from video files without re-encoding. Perfect for clipping ads out of recorded TV shows or removing unwanted segments from any video.

Features

  • No re-encoding: Uses ffmpeg's stream copy to maintain original quality
  • Flexible timestamp formats: Support for seconds (90.5), minutes:seconds (5:18.5), or hours:minutes:seconds (1:05:30)
  • Multiple sections: Remove multiple segments in a single command
  • Smart merging: Automatically coalesces overlapping sections
  • Partial ranges: Omit start (-0:10) or end (15:22-) timestamps
  • Strict mode: Optional validation for out-of-bounds sections
  • Any format: Works with any video format supported by ffmpeg (MKV, MP4, AVI, MOV, etc.)

Installation

pip install remove-sections

Or install from source:

git clone https://github.com/lorenzowood/remove-sections.git
cd remove-sections
pip install -e .

Requirements

  • Python 3.11+
  • ffmpeg (must be installed and available in PATH)

Usage

remove-sections <input_file> <section1> [section2 ...] [output_file] [options]

Basic Examples

Remove a single section (5:18.5 to 7:00.7):

remove-sections programme.mkv 5:18.5-7:00.7
# Creates: programme-sections-removed.mkv

Remove multiple sections:

remove-sections programme.mkv 5:18.5-7:00.7 12:11.2-13:15

Specify output filename:

remove-sections input.mp4 1:30-2:45 output.mp4

Remove from start:

remove-sections programme.mkv -0:10
# or
remove-sections programme.mkv 0:00-0:10

Remove to end:

remove-sections programme.mkv 15:22-

Timestamp Formats

All of these formats are supported:

  • Seconds only: 90.5, 120
  • Minutes:seconds: 5:18.5, 1:30
  • Hours:minutes:seconds: 1:05:30, 0:05:18.5

Options

  • --strict: Error if any section falls outside the video duration (default: clips to video length)
  • --preserve-intermediate-files: Keep intermediate part files after processing

Examples with Options

Strict mode (fails if timestamps are invalid):

remove-sections video.mkv 5:00-6:00 --strict

Keep intermediate files for inspection:

remove-sections video.mkv 1:00-2:00 3:00-4:00 --preserve-intermediate-files

Important Notes

  • All timestamps are relative to the original file: The order of sections doesn't matter
  • Overlapping sections merge automatically: 4:00-5:00 4:57-6:00 becomes 4:00-6:00
  • Default behavior clips to video length: Removing 4:54-8:20 from a 5-minute video removes 4:54-5:00
  • No changes = copy: If all sections fall outside the video, output equals input

How It Works

The tool:

  1. Parses the sections to remove and merges any overlaps
  2. Calculates the segments to keep (inverse of removed sections)
  3. Extracts each segment using ffmpeg with stream copy (-c copy)
  4. Concatenates the segments using ffmpeg's concat demuxer
  5. Cleans up intermediate files (unless --preserve-intermediate-files is set)

Development

Run tests:

pytest test_remove_sections.py -v

License

MIT License - see LICENSE file for details

Contributing

Contributions welcome! Please open an issue or pull request on GitHub.

Author

Lorenzo Wood

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remove_sections-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remove_sections-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file remove_sections-0.1.0.tar.gz.

File metadata

  • Download URL: remove_sections-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for remove_sections-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bb8eff581e10e55e75281044855d2d7afc10d79251cabd694f379e653304519
MD5 b2ad972ebb844bde790e0867186f74cc
BLAKE2b-256 0c6011e1f3e53d105be4bc360021d6f6c05eb4699d748e6874be7ddac931b417

See more details on using hashes here.

File details

Details for the file remove_sections-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for remove_sections-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ade8fe4ae4d143862b954054f59e15ddc3c84b5e192d8202cbfd183a1f5c089a
MD5 96a8f8ecd5d348f2a5ca32fe72b6cba0
BLAKE2b-256 d0fc92f01c7b7c6bc683f240129b1e0af31c78e92b2145ee8058987f18a9a76a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page