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
- File input: Read sections from a file with
-fflag - 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-
Using a Sections File
Create a text file with one section per line:
sections.txt:
# Remove ads
5:18.5-7:00.7
12:11.2-13:15
# Remove outro
45:30-
Then use it with the -f flag:
remove-sections programme.mkv -f sections.txt
# Creates: programme-sections-removed.mkv
Specify output filename:
remove-sections input.mp4 -f sections.txt output.mp4
Combine file sections with command-line sections:
remove-sections input.mp4 -f sections.txt 10:00-11:00 output.mp4
File format:
- One section per line (START-END format)
- Lines starting with
#are comments - Blank lines are ignored
- Invalid lines will cause an error
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
-f,--file <filename>: Read sections from a file (one section per line)--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:00becomes4:00-6:00 - Default behavior clips to video length: Removing
4:54-8:20from a 5-minute video removes4:54-5:00 - No changes = copy: If all sections fall outside the video, output equals input
How It Works
The tool:
- Parses the sections to remove and merges any overlaps
- Calculates the segments to keep (inverse of removed sections)
- Extracts each segment using ffmpeg with stream copy (
-c copy) - Concatenates the segments using ffmpeg's concat demuxer
- Cleans up intermediate files (unless
--preserve-intermediate-filesis 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file remove_sections-0.2.0.tar.gz.
File metadata
- Download URL: remove_sections-0.2.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
681f7b4358da1ead74800b578ad82ce206ae0e41b14b9ad8e08228f4fb69e2ba
|
|
| MD5 |
4d64facfcd02c980600bbf6ffffa497c
|
|
| BLAKE2b-256 |
72a0880c24477261f44b9b344c1544438a322662dd4c2c3f3b0c7dd1c74fd6e3
|
File details
Details for the file remove_sections-0.2.0-py3-none-any.whl.
File metadata
- Download URL: remove_sections-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c898888cda14795e5f9c4baec1768b00a89f730983c8815603082d65d114103
|
|
| MD5 |
ba8b0d7a7cb0c4367b1b96cb6361038e
|
|
| BLAKE2b-256 |
3605673cb1e8ccf487e933d7142aedcefd60300effbc4dbc70ad5d05c059a236
|