From 4efef86793c748b0724c09c06692207dab9d3f7f Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Wed, 5 Apr 2023 16:11:30 +0200 Subject: [PATCH] codec --- src/music_kraken/audio/__init__.py | 4 +++- src/music_kraken/audio/codec.py | 38 ++++++++++++++++++++++++++++++ src/music_kraken/audio/codex.py | 8 ------- src/music_kraken/utils/shared.py | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/music_kraken/audio/codec.py delete mode 100644 src/music_kraken/audio/codex.py diff --git a/src/music_kraken/audio/__init__.py b/src/music_kraken/audio/__init__.py index 824376b..bb9ce38 100644 --- a/src/music_kraken/audio/__init__.py +++ b/src/music_kraken/audio/__init__.py @@ -1,7 +1,9 @@ from . import metadata -from . import codex +from . import codec AudioMetadata = metadata.AudioMetadata write_many_metadata = metadata.write_many_metadata write_metadata = metadata.write_metadata write_metadata_to_target = metadata.write_metadata_to_target + +correct_codec = codec.correct_codec diff --git a/src/music_kraken/audio/codec.py b/src/music_kraken/audio/codec.py new file mode 100644 index 0000000..b0adc55 --- /dev/null +++ b/src/music_kraken/audio/codec.py @@ -0,0 +1,38 @@ +from pathlib import Path + +import ffmpeg + +from ..utils.shared import BITRATE, CODEX_LOGGER as LOGGER +from ..objects import Target + +def correct_codec(target: Target, bitrate: int = BITRATE): + if not target.exists: + LOGGER.warning(f"Target doesn't exist: {target.file_path}") + + output_file = Path(str(target.file_path) + ".out") + + # https://www.audioranger.com/audio-formats.php + # https://kkroening.github.io/ffmpeg-python/index.html?highlight=audio#ffmpeg.output + + ffmpeg_out = ffmpeg.output( + ffmpeg.input(target.file_path), + output_file, + audio_bitrate=bitrate, + format="mp3" + ).run() + """ + +in_file = ffmpeg.input('input.mp4') +overlay_file = ffmpeg.input('overlay.png') +( + ffmpeg + .concat( + in_file.trim(start_frame=10, end_frame=20), + in_file.trim(start_frame=30, end_frame=40), + ) + .overlay(overlay_file.hflip()) + .drawbox(50, 50, 120, 120, color='red', thickness=5) + .output('out.mp4') + .run() +) + """ diff --git a/src/music_kraken/audio/codex.py b/src/music_kraken/audio/codex.py deleted file mode 100644 index 7b72e75..0000000 --- a/src/music_kraken/audio/codex.py +++ /dev/null @@ -1,8 +0,0 @@ -import ffmpeg - -from ..utils.shared import BITRATE -from ..objects import Target - -def correct_codex(target: Target, bitrate: int = BITRATE): - if not target.exists: - pass diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 5e3a2ab..813c64f 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -62,8 +62,8 @@ ENCYCLOPAEDIA_METALLUM_LOGGER = logging.getLogger("ma") DOWNLOAD_LOGGER = logging.getLogger("download") TAGGING_LOGGER = logging.getLogger("tagging") +CODEX_LOGGER = logging.getLogger("codex") -NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea" MUSIC_DIR: Path = Path(os.path.expanduser("~"), "Music") NOT_A_GENRE_REGEX: List[str] = ( r'^\.', # is hidden/starts with a "."