Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mslinn/media_trim
Trim an audio or video file using ffmpeg
https://github.com/mslinn/media_trim
ffmpeg ruby-gem trimming
Last synced: about 1 month ago
JSON representation
Trim an audio or video file using ffmpeg
- Host: GitHub
- URL: https://github.com/mslinn/media_trim
- Owner: mslinn
- License: mit
- Created: 2023-11-28T02:10:01.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-05T20:26:52.000Z (about 1 year ago)
- Last Synced: 2024-11-11T05:45:37.561Z (about 2 months ago)
- Topics: ffmpeg, ruby-gem, trimming
- Language: Ruby
- Homepage: https://www.mslinn.com/av_studio/425-trimming-media.html
- Size: 63.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# `media_trim` [![Gem Version](https://badge.fury.io/rb/media_trim.svg)](https://badge.fury.io/rb/media_trim)
Trims an audio or video file using `ffmpeg`.
* Works with all formats supported by `ffmpeg`, including `mp3`, `mp4`, `mkv`, and many more.
* Seeks to the nearest frame positions by re-encoding the media.
* Reduces file size produced by OBS Studio by over 80 percent.
* Can be used as a Ruby gem.
* Installs the `trim` command.## Installation
You need a working Ruby environment to install this program.
I describe how to set that up [here](http://localhost:4001/ruby/1000-ruby-setup.html).### Standalone
The `trim` command is provided by the `media_trim` Ruby gem.
Install it like this:```shell
$ gem install media_trim
```### As a Dependency of a Ruby Program
Add this line to your application’s `Gemfile`:
```ruby
gem 'media_trim'
```Then execute:
```shell
$ bundle
```### As a Dependency of a Ruby Gem
Add the following to your application’s `.gemspec`:
```ruby
spec.add_dependency 'media_trim'
```Then execute:
```shell
$ bundle
```## Usage
### Command-line Usage
```shell
trim [OPTIONS] dir/file.ext start [[to|for] end]
```* The `start` and `end` timecodes have the format `[HH:[MM:]]SS[.XXX]`.
Note that decimal seconds may be specified, but frames may not;
this is consistent with how `ffmpeg` parses timecodes.
* `end` defaults to the end of the audio/video fileWhen run as a command, output files are named by adding a `trim.` prefix to the media file name,
e.g. `dir/trim.file.ext`.
By default, the `trim` command does not overwrite pre-existing output files.
When trimming is complete, the `trim` command displays the trimmed file,
unless the `-q` option is specified.`OPTIONS` are:
* `-d` Enable debug output.
* `-h` Display help information.
* `-f` Overwrite output file if present.
* `-v` Verbose output.
* `-V` Do not view the trimmed file when complete.#### Examples
Crop `dir/file.mp4` from 15.0 seconds to the end of the video, save to `demo/trim.demo.mp4`:
```shell
$ trim demo/demo.mp4 15
```Crop dir/file.mkv from 3 minutes, 25 seconds to 9 minutes, 35 seconds, save to `demo/trim.demo.mp4`:
```shell
$ trim demo/demo.mp4 3:25 9:35
```Same as the previous example, using optional `to` syntax:
```shell
$ trim demo/demo.mp4 3:25 to 9:35
```Save as the previous example, but specify the duration instead of the end time by using the `for` keyword:
```shell
$ trim demo/demo.mp4 3:25 for 6:10
```## Figuring Out Start and Stop Times
Need a way to figure out the start and stop times to trim a video?
[DJV](https://darbyjohnston.github.io/DJV/) is an excellent video viewer.* Allows frame-by-frame stepping
* Displays the current time reliabily
* F/OSS
* Mac, Windows, Linux
* High quality## Development
After checking out this git repository, install dependencies by typing:
```shell
$ bin/setup
```You should do the above before running Visual Studio Code.
### Run the Tests
```shell
$ bundle exec rake test
```### Interactive Session
The following will allow you to experiment:
```shell
$ bin/console
```### Local Installation
To install this gem onto your local machine, type:
```shell
$ bundle exec rake install
```### To Release A New Version
To create a git tag for the new version, push git commits and tags,
and push the new version of the gem to https://rubygems.org, type:```shell
$ bundle exec rake release
```## Contributing
Bug reports and pull requests are welcome at https://github.com/mslinn/trim.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).