added convertion of the audio itself vie ffmpeg
This commit is contained in:
@@ -2,37 +2,33 @@ from pathlib import Path
|
||||
|
||||
import ffmpeg
|
||||
|
||||
from ..utils.shared import BITRATE, CODEX_LOGGER as LOGGER
|
||||
from ..utils.shared import BITRATE, AUDIO_FORMAT, CODEX_LOGGER as LOGGER
|
||||
from ..objects import Target
|
||||
|
||||
def correct_codec(target: Target, bitrate: int = BITRATE):
|
||||
|
||||
def correct_codec(target: Target, bitrate_kb: int = BITRATE, audio_format: str = AUDIO_FORMAT):
|
||||
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),
|
||||
return
|
||||
|
||||
bitrate_b = int(bitrate_kb / 1024)
|
||||
|
||||
output_target = Target(
|
||||
path=target._path,
|
||||
file=str(target._file) + "." + audio_format
|
||||
)
|
||||
.overlay(overlay_file.hflip())
|
||||
.drawbox(50, 50, 120, 120, color='red', thickness=5)
|
||||
.output('out.mp4')
|
||||
.run()
|
||||
)
|
||||
"""
|
||||
|
||||
stream = ffmpeg.input(target.file_path)
|
||||
stream = stream.audio
|
||||
stream = ffmpeg.output(
|
||||
stream,
|
||||
str(output_target.file_path),
|
||||
audio_bitrate=bitrate_b,
|
||||
format=audio_format
|
||||
)
|
||||
out, err = ffmpeg.run(stream, quiet=True, overwrite_output=True)
|
||||
if err != "":
|
||||
LOGGER.debug(err)
|
||||
|
||||
output_target.copy_content(target)
|
||||
output_target.file_path.unlink()
|
||||
|
||||
Reference in New Issue
Block a user