Skip to main content

Python program to trim-then-concatenate A/V media files using ffmpeg

Project description

Concatrim

Concatrim is a python program to trim-and-concatenate media files. It depends on ffmpeg.

License

Concatrim is distributed as source code on this repository and PyPI under MIT license.

Features

  1. Trim an input time-based media file based on given time spans and concatenate trimmed pieces into a single file.
  2. Mapping between time points in the original and trimmed file.

Installation

Dependencies

System application

Python libraries

See requirements.txt.

From PyPI

Install using pip

pip install concatrim

From source

Clone this repository and run setup.py to install

python setup.py install

Usage

Caveats

At the moment;

  • the package only provides Python API's for its supported operations (no command line interface).
  • the program only supports audio inputs.

trim-then-concatenate

To trim a media file, use Concatrimmer class from concatrim package. Initiate an instance with the input file name and optionally configuration for padding. When you trim more than two parts of the input media, a silence padding (configured in milliseconds) will be inserted between each slice.

from concatrim import Concatrimmer

c = Concatrimmer('input-file.mp3', 1000)  # will insert 1-second silences between slices

From here, you can set which part of the input we want to trim, using add_spans method.

c.add_spans([1000, 4000], [12000, 22000])
#  configures the program to extract two parts, 1-4 second and 12-22 second. 

When you're done adding spans, call concatrim method, with a directory name you want to use to store trimmed output file.

c.concatrim('../outputs')

Additionally, we can pass prefix, suffix arguments to rename the output file (suffix will be added at before the extension name).

c.concatrim('../outputs', suffix='.trimmmed')

Timepoint conversion

Once you have all spans for trimming configured in a Concatrimmer object, you can also ask for conversion between two time points; one from the original media file, and the other from the trimmed one. This conversion will consider the padding pauses that'd be inserted between spans. Again, all input and output of the conversion is in milliseconds.

c.conv_to_trimmed(2100)  # will return 1100
c.conv_to_original(1100)  # will return 2100
c.conv_to_original(11100)  # will return None because 11100 ms is trimmed out
c.conv_to_original(12100)  # will return 4100

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

concatrim-1.0.3.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file concatrim-1.0.3.tar.gz.

File metadata

  • Download URL: concatrim-1.0.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10

File hashes

Hashes for concatrim-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ce36acc51b020a8edf8af72c0fe662386122b0e9d879ea365fe46730952afc45
MD5 772acfb79f7d3b466adc848cef67fb96
BLAKE2b-256 3ea1517be88ea19899180a4d6840bc3d75585bdd176d5f3be09db4d537d62a4c

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