mirror of
https://github.com/gryf/flac2ogg.git
synced 2026-10-06 05:20:38 +02:00
Added opus encoder and decoder
This commit is contained in:
1 parent
38dc4234e0
commit
5a45d56784
2 files changed
+41
-10
No files matched your search
+10
-5
@@ -18,6 +18,7 @@ Requirements
|
|||||||
- python 3
|
- python 3
|
||||||
- `mutagen`_ python library for tag read/write
|
- `mutagen`_ python library for tag read/write
|
||||||
- `vorbis tools`_ for ``ogg`` files encode/decode
|
- `vorbis tools`_ for ``ogg`` files encode/decode
|
||||||
|
- `opus tools`_ for ``opus`` files encode/decode
|
||||||
- `lame`_ for ``mp3`` files encode/decode
|
- `lame`_ for ``mp3`` files encode/decode
|
||||||
- `flac`_ for ``flac`` files decode
|
- `flac`_ for ``flac`` files decode
|
||||||
- `mac`_ for ``Monkey audio codecs``/``ape`` files decode
|
- `mac`_ for ``Monkey audio codecs``/``ape`` files decode
|
||||||
@@ -37,16 +38,19 @@ Conversion can be performed from the following formats:
|
|||||||
- WavePack
|
- WavePack
|
||||||
- Ape
|
- Ape
|
||||||
- Ogg Vorbis
|
- Ogg Vorbis
|
||||||
|
- Ogg Opus
|
||||||
|
|
||||||
Currently supported encoders:
|
Currently supported encoders:
|
||||||
|
|
||||||
- Ogg Vorbis
|
- Ogg Vorbis
|
||||||
|
- Ogg Opus
|
||||||
- MP3 (lame)
|
- MP3 (lame)
|
||||||
|
|
||||||
There is an option to set the quality for the encoders - for *Ogg* files there
|
There is an option to set the quality for the encoders - for *Vorbis* files
|
||||||
would be used an ``-q`` option for ``oggenc`` command, and for the *mp3*
|
there would be used an ``-q`` option for ``oggenc`` command, for the *mp3*
|
||||||
format, ``-V`` option would be used for ``lame`` command. Consult corresponding
|
format ``-V`` option would be used for ``lame`` command and ``--bitrate`` for
|
||||||
man pages for details.
|
``opusenc`` for the *Opus* files. Consult corresponding encoder man pages for
|
||||||
|
details.
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
@@ -57,7 +61,7 @@ Given that there are couple of music files, simplest usage is as follows:
|
|||||||
|
|
||||||
$ flac2ogg.py directory_of_music_files/*
|
$ flac2ogg.py directory_of_music_files/*
|
||||||
|
|
||||||
All files from that directory will be encoded to *ogg* by defaults. If there
|
All files from that directory will be encoded to *ogg* by default. If there
|
||||||
are already some *ogg* files, new files would have ``_encoded_`` added into the
|
are already some *ogg* files, new files would have ``_encoded_`` added into the
|
||||||
filename. Note, that output files will be placed next to the original files.
|
filename. Note, that output files will be placed next to the original files.
|
||||||
|
|
||||||
@@ -69,6 +73,7 @@ This work is licensed on 3-clause BSD license. See LICENSE file for details.
|
|||||||
|
|
||||||
.. _mutagen: https://mutagen.readthedocs.io/en/latest/
|
.. _mutagen: https://mutagen.readthedocs.io/en/latest/
|
||||||
.. _vorbis tools: http://www.vorbis.com/
|
.. _vorbis tools: http://www.vorbis.com/
|
||||||
|
.. _opus tools: https://opus-codec.org
|
||||||
.. _flac: http://www.vorbis.com/
|
.. _flac: http://www.vorbis.com/
|
||||||
.. _lame: http://lame.sourceforge.net/
|
.. _lame: http://lame.sourceforge.net/
|
||||||
.. _mac: http://www.deb-multimedia.org/dists/testing/main/binary-amd64/package/monkeys-audio.php
|
.. _mac: http://www.deb-multimedia.org/dists/testing/main/binary-amd64/package/monkeys-audio.php
|
||||||
|
|||||||
+31
-5
@@ -147,6 +147,21 @@ class Mp3Encoder(Encoder):
|
|||||||
sp.check_call(["lame", f"-V{self.quality}", input_fname, output_fname])
|
sp.check_call(["lame", f"-V{self.quality}", input_fname, output_fname])
|
||||||
|
|
||||||
|
|
||||||
|
class OpusEncoder(Encoder):
|
||||||
|
"""Opus encoder"""
|
||||||
|
EXT = ".opus"
|
||||||
|
|
||||||
|
def __init__(self, quality=None):
|
||||||
|
"""Init"""
|
||||||
|
super().__init__(quality)
|
||||||
|
if self.quality is None:
|
||||||
|
self.quality = 128
|
||||||
|
|
||||||
|
def encode(self, input_fname, output_fname):
|
||||||
|
sp.check_call(["opusenc", "--bitrate", self.quality, input_fname,
|
||||||
|
output_fname])
|
||||||
|
|
||||||
|
|
||||||
class FileType:
|
class FileType:
|
||||||
"""Base class for file objects"""
|
"""Base class for file objects"""
|
||||||
extensions = {'ogg': '.ogg',
|
extensions = {'ogg': '.ogg',
|
||||||
@@ -333,6 +348,14 @@ class OggType(FileType):
|
|||||||
sp.check_call(["oggdec", self.filename])
|
sp.check_call(["oggdec", self.filename])
|
||||||
|
|
||||||
|
|
||||||
|
class OpusType(FileType):
|
||||||
|
"""Opus filetype"""
|
||||||
|
|
||||||
|
def extract_wav(self):
|
||||||
|
"""Extract opus file to wav"""
|
||||||
|
sp.check_call(["opusdec", self.filename])
|
||||||
|
|
||||||
|
|
||||||
class Converter:
|
class Converter:
|
||||||
"""Main class for converting files"""
|
"""Main class for converting files"""
|
||||||
extract_map = {'.ape': ApeType,
|
extract_map = {'.ape': ApeType,
|
||||||
@@ -341,6 +364,7 @@ class Converter:
|
|||||||
'.mp3': Mp3Type,
|
'.mp3': Mp3Type,
|
||||||
'.mpc': MusepackType,
|
'.mpc': MusepackType,
|
||||||
'.ogg': OggType,
|
'.ogg': OggType,
|
||||||
|
'.opus': OpusType,
|
||||||
'.wav': WavType,
|
'.wav': WavType,
|
||||||
'.wv': WvType}
|
'.wv': WvType}
|
||||||
|
|
||||||
@@ -424,7 +448,8 @@ class Converter:
|
|||||||
|
|
||||||
|
|
||||||
ENCODERS = {'ogg': OggEncoder,
|
ENCODERS = {'ogg': OggEncoder,
|
||||||
'mp3': Mp3Encoder}
|
'mp3': Mp3Encoder,
|
||||||
|
'opus': OpusEncoder}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -436,11 +461,12 @@ def main():
|
|||||||
arg.add_argument('-r', '--recursive', action='store_true',
|
arg.add_argument('-r', '--recursive', action='store_true',
|
||||||
help='Do the files searching recursive')
|
help='Do the files searching recursive')
|
||||||
arg.add_argument('-e', '--encoder', default='ogg', type=str,
|
arg.add_argument('-e', '--encoder', default='ogg', type=str,
|
||||||
choices=('ogg', 'mp3'), help='Encoder to use. Defaults '
|
choices=('ogg', 'mp3', 'opus'),
|
||||||
'to "ogg"')
|
help='Encoder to use. Defaults to "ogg"')
|
||||||
arg.add_argument('-q', '--quality', help='Quality of the encoded file. '
|
arg.add_argument('-q', '--quality', help='Quality of the encoded file. '
|
||||||
'Consult "lame" and "oggenc" for details. Defaults are '
|
'Consult "lame", "oggenc" and "opusenc" manuals for '
|
||||||
'6 for lame and 8 for oggenc.')
|
'details. Defaults are -V6 for lame, -q8 for oggenc and '
|
||||||
|
'--bitrate 128 for opusenc')
|
||||||
arg.add_argument('-v', '--version', action='version',
|
arg.add_argument('-v', '--version', action='version',
|
||||||
version='%(prog)s v' + VERSION,
|
version='%(prog)s v' + VERSION,
|
||||||
help='Display version and exit.')
|
help='Display version and exit.')
|
||||||
|
|||||||
Reference in new issue
Block a user