https://github.com/purarue/mlength
gets the length of media files and caches the result
https://github.com/purarue/mlength
ffmpeg ffprobe media
Last synced: about 2 months ago
JSON representation
gets the length of media files and caches the result
- Host: GitHub
- URL: https://github.com/purarue/mlength
- Owner: purarue
- License: mit
- Created: 2023-09-11T05:56:45.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-25T17:28:59.000Z (over 1 year ago)
- Last Synced: 2025-02-08T23:34:05.293Z (over 1 year ago)
- Topics: ffmpeg, ffprobe, media
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mlength
gets the length of media files and caches the result
## Installation
Requires `python3.10+`
To install with pip, run:
```
pip install mlength
```
This requires either `ffprobe` (from `ffmpeg`) or [`mediainfo`](https://mediaarea.net/en/MediaInfo) to be installed.
## Usage
```
Usage: mlength [OPTIONS] MEDIA...
Compute the duration of media files
This caches the duration of media files in a cache directory, so that
subsequent runs are faster. If media files are modified, the cache is recomputed
MEDIA is a list of media files to compute the duration of
Options:
--cache-dir PATH Cache directory [default: ~/.cache/mlength]
--lib [mediainfo|ffprobe] Library to use for parsing media files [env
var: MLENGTH_LIB; default: ffprobe]
--cache / --no-cache Enable/disable caching [default: cache]
-o, --operation [sum|max|min|avg]
Operation to perform on the durations
-d, --display [ms|s|m|human|path|all]
Display format for durations
--debug Enable debug mode
--help Show this message and exit.
```
```bash
$ mlength sound.mpeg
00:00:02.95
$ mlength -d all sound.mpeg
2951|2.95|0.05|00:00:02.95|sound.mpeg
```
I use this in lots of small scripts:
Get the shortest media file in a directory, with the [list-movies](https://github.com/purarue/pura-utils/blob/main/shellscripts/list-movies) script:
- `list-music -X mlength -o sum` (find length of an album in current directory)
- `list-movies -X mlength -d path -o min` (find shortest movie in current directory)
- `list-movies -X mlength -d all | sort -n` (sort results by length)
If the media file is modified, the cache is recomputed.
### Tests
```bash
git clone 'https://github.com/purarue/mlength'
cd ./mlength
pip install '.[testing]'
flake8 ./mlength
mypy ./mlength
```