Skip to main content

A simple way to manage video files.

Project description

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 extention 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.extention = '.m4v'

Delete all audio tracks, that are not Engilsh:

>>> not_eng = lambda s: s.is_audio and s.metadata['language'] != 'eng'
>>> container.remove_streams(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 extention of a file was not changed, the file will be rewritten entirely.

>>> 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.extention
'.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 extention:

>>> container.extention = '.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()

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

shane-18.7b0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

shane-18.7b0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file shane-18.7b0.tar.gz.

File metadata

  • Download URL: shane-18.7b0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.0

File hashes

Hashes for shane-18.7b0.tar.gz
Algorithm Hash digest
SHA256 f1adbd2b3f6eadcab55e57a4d56e73b1cebd4fb45b736e49ae5fe95b8b7f7964
MD5 8c7a9f0216c06295c232fd0a34156820
BLAKE2b-256 04a66ce2730625b34067cbced21b962f6a7e7a31dc7b141521185a4380e19976

See more details on using hashes here.

File details

Details for the file shane-18.7b0-py3-none-any.whl.

File metadata

  • Download URL: shane-18.7b0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.0

File hashes

Hashes for shane-18.7b0-py3-none-any.whl
Algorithm Hash digest
SHA256 66ba213080d762ba9b97fc30cc3ca274dee666de78abd50f9cb5a103986aade9
MD5 ea3437195e9b5934238d6e6c3405f97c
BLAKE2b-256 e803fa27a6cb6062b85b79d41b2067164809bca3a61fb993db4d7ff088efe0c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page