encode_audio.py: v1.0.8
* Bump version * Add opus support * Add new params - --codec: Pick lossy codec to encode with (default: opus) {aac, opus} - --bitrate: Bitrate for opus encoding (default: 192000) * Renamed --noaac to --nolossy, -N
This commit is contained in:
parent
1163eaed65
commit
cc54a97354
|
@ -18,7 +18,7 @@ import tempfile
|
|||
|
||||
__author__ = "LightArrowsEXE"
|
||||
__license__ = 'MIT'
|
||||
__version__ = '1.0.7'
|
||||
__version__ = '1.0.8'
|
||||
|
||||
|
||||
ignored_formats = ["audio/opus", "audio/aac"]
|
||||
|
@ -31,10 +31,10 @@ def main():
|
|||
for f in filelist:
|
||||
mime = mimetypes.types_map.get(os.path.splitext(f)[-1], "")
|
||||
if f.endswith('.m2ts'):
|
||||
encode(f, wav_only=True)
|
||||
encode_main(f, wav_only=True)
|
||||
elif mime.startswith("audio/") or mime.startswith("video/"):
|
||||
if mime not in ignored_formats:
|
||||
encode(f)
|
||||
encode_main(f)
|
||||
|
||||
|
||||
def encode_flac(f):
|
||||
|
@ -43,13 +43,19 @@ def encode_flac(f):
|
|||
|
||||
def encode_aac(f):
|
||||
temp = tempfile.mkstemp(prefix=f"{os.path.splitext(f)[0]}_")
|
||||
subprocess.run(["ffmpeg", "-i", f, "-loglevel", "panic",
|
||||
"-stats", f"{temp[1]}.wav"])
|
||||
subprocess.run(["qaac", f"{temp[1]}.wav", "-V 127",
|
||||
"--no-delay", "-o", f"{os.path.splitext(f)[0]}.m4a"])
|
||||
subprocess.run(["ffmpeg", "-i", f, "-loglevel", "panic", "-stats",
|
||||
f"{temp[1]}.wav"])
|
||||
subprocess.run(["qaac", f"{temp[1]}.wav", "-V 127", "--no-delay",
|
||||
"-o", f"{os.path.splitext(f)[0]}.m4a"])
|
||||
|
||||
|
||||
def encode(f, wav_only: bool = False):
|
||||
def encode_opus(f):
|
||||
subprocess.run(["ffmpeg", "-i", f, "-stats",
|
||||
"-c:a", "libopus", "-b:a", f"{args.bitrate}",
|
||||
f"{os.path.splitext(f)[0]}.opus"])
|
||||
|
||||
|
||||
def encode_main(f, wav_only: bool = False):
|
||||
print(f"\n{f}\n")
|
||||
if wav_only:
|
||||
if args.track:
|
||||
|
@ -61,8 +67,12 @@ def encode(f, wav_only: bool = False):
|
|||
else:
|
||||
if not args.noflac:
|
||||
encode_flac(f)
|
||||
if not args.noaac:
|
||||
encode_aac(f)
|
||||
if not args.nolossy:
|
||||
codec = args.codec.lower()
|
||||
if codec in ['aac']:
|
||||
encode_aac(f)
|
||||
elif codec in ['opus']:
|
||||
encode_opus(f)
|
||||
if not args.keep:
|
||||
os.remove(f)
|
||||
|
||||
|
@ -72,18 +82,25 @@ if __name__ == "__main__":
|
|||
parser.add_argument("-R", "--recursive",
|
||||
action="store_true", default=False,
|
||||
help="Encode files recursively (default: %(default)s)")
|
||||
parser.add_argument("-C", "--codec",
|
||||
action="store", type=str, default="opus",
|
||||
choices=('aac', 'opus'),
|
||||
help="Pick lossy codec to encode with (default: %(default)s)")
|
||||
parser.add_argument("-B", "--bitrate",
|
||||
action="store", type=int, default=192000,
|
||||
help="Bitrate for opus encoding (default: %(default)s)")
|
||||
parser.add_argument("-K", "--keep",
|
||||
action="store_true", default=False,
|
||||
help="Do not delete source file after re-encoding (default: %(default)s)")
|
||||
parser.add_argument("-T", "--track",
|
||||
action="store", type=int, default=None,
|
||||
help="Track to encode using eac3to. If none; first audio track (default: %(default)s)")
|
||||
help="Track to encode using eac3to. If none; autoselects first audio track (default: %(default)s)")
|
||||
parser.add_argument("--noflac",
|
||||
action="store_true", default=False,
|
||||
help="Disable FLAC encoding (default: %(default)s)")
|
||||
parser.add_argument("--noaac",
|
||||
parser.add_argument("-N", "--nolossy",
|
||||
action="store_true", default=False,
|
||||
help="Disable AAC encoding (default: %(default)s)")
|
||||
help="Disable lossy encoding (default: %(default)s)")
|
||||
parser.parse_args()
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
Loading…
Reference in a new issue