Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Shane

Shane is a handy module for converting and demuxing video files.

  • Change a container for MKV or MP4 without slow re-encoding.
  • Add new streams to the container (and delete other ones easily)
  • View and change the metadata of a container and of all its streams

It is a new look at some common tasks for FFmpeg (you don't need to know FFmpeg syntax). In fact, you just change some media file attributes, like extension or fps, and save these changes (see examples below).

CONTENTS

  1. INSTALLATION
  2. HOW TO
  3. USAGE

INSTALLATION

Install FFmpeg. You can install it using Homebrew on Mac:

brew install ffmpeg --with-x265

Install Shane with pip:

pip install shane

Note, that only Python 3.6+ is supported.

HOW TO

Open the media file:

>>> import shane
>>> container = shane.open('path/to/file.mkv')

Change the format to another one:

NOTE: It will be executed fast if the input container codecs are supported by the output container.

>>> container.extension = '.m4v'

Delete all audio tracks, that are not Engilsh:

>>> not_eng = lambda s: s.is_audio and s.metadata['language'] != 'eng'
>>> container.remove_streams_if(not_eng)

Add subtitles:

>>> subtitles = shane.open('path/to/fre_subtitles.srt')
>>> subtitles.metadata['language'] = 'fre'
>>> container.streams.append(subtitles)

Extract subtitles:

>>> subtitles = container.subtitles[0]
>>> subtitles = subtitles.extract(path='new_path/to/rus_subtitles.srt')

Save the changes:

After all the changes, the file must be saved.

NOTE: If the path or the extension of a file was not changed, the file will be overwritten.

>>> container.save()

USAGE

Shane operates with two kinds of objects: streams and containers. Streams are separate video/audio/subtitles files and containers contain a number of streams.

Open a file

The open function chooses the object type that needs to be created itself.

Open the file with several video/audio/subtitles tracks in it:

>>> container = shane.open('path/to/file.mkv')
Container(path=path/to/file.mkv, size=142.65 MB, duration=00:02:00)

Open the file that contains only video, without any audio or subtitles:

>>> video_stream = shane.open('path/to/only_video.mkv')
VideoStream(path=path/to/file.mkv, codec=h264, fps=23.97598627787307, width=1272, height=720, language=eng)

Open an audio or subtitles file:

>>> audio_stream = shane.open('path/to/audio.aac')
AudioStream(path=path/to/audio.aac, codec=aac, channels=2, sample_rate=48000.0, language=eng)

>>> subtitle_stream = shane.open('path/to/subtitles.srt')
SubtitleStream(path=path/to/subtitles.srt, codec=subrip, is_forced=False, language=rus)

Discover the media information

Get the list of all streams inside the container:

>>> container.streams
...

Get tuple of streams of a certain type:

>>> container.audios
...
>>> container.subtitles
...
>>> container.videos
...

Get the metadata:

# global metadata
>>> container.metadata
{'title': 'Untitled Movie File'}

# metadata of a certain stream
>>> *_, last_audio_stream = container.audios
>>> last_audio_stream.metadata
{'language': 'eng', 'title': 'Commentary', 'DURATION': '00:02:00'}

Get chapters:

>>> container.chapters
...

Get other media information:

>>> container.path
'path/to/file.mkv'

>>> container.extension
'.mkv'

>>> container.duration
120.0

>>> container.human_duration
'00:02:00'

>>> container.size
149575198

>>> container.human_size
'142.65 MB'

>>> video, *_ = container.videos
>>> video.fps
23.976023976023978

>>> video.codec
'h264'

Change what you want

All the changes to the container are performed by means of changing of its attributes and the following saving.

Change the file extension:

>>> container.extension = '.m4v'

>>> container.path
'path/to/file.m4v'

Change the global metadata:

>>> container.metadata['author'] = "John Dou"

Or delete the global metadata at all:

>>> container.metadata = {}

Change the FPS of the video stream inside the container:

>>> video_stream, *_ = container.videos
>>> video_stream.fps = 23

Change the frame size:

>>> video_stream.width = 640
>>> video_stream.height = 480

And don't forget to save the changes:

>>> container.save()

Metadata

Release files for shane 18.8b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shane 18.8b2
File Size Uploaded Provenance Actions
shane-18.8b2.tar.gz 18.0 kB Without provenance Details for shane-18.8b2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shane 18.8b2
File Interpreter ABI Platform Actions
shane-18.8b2-py3-none-any.whl Python 3 none any Details for shane-18.8b2-py3-none-any.whl

Total release size: 34.4 kB

Release files / shane-18.8b2.tar.gz

Download URL shane-18.8b2.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e27281c672bde7490d683b29ff0e43a60c89001a0ba3a67f4a12fc7dcade34b9
BLAKE2b-256 checksum
How to use checksums
06e7f7f5fd25502e0c2e3d19f98af97843c9c4e91a753c7320675f8177f87898
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

Release files / shane-18.8b2-py3-none-any.whl

Download URL shane-18.8b2-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9b3a105abded876ff6ecafe0d3c4f41b5a638a66aff8455d15fb462fab6b0ad
BLAKE2b-256 checksum
How to use checksums
773bf6b8ff780461284568594ef639630bb00fb621e10fa1f9c1e23eaf7abf99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

Security for shane 18.8b2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page