Commit d970ad3c authored by Javinator9889's avatar Javinator9889 🎼

Removed loudness normalization - impossible to work with pipes by using FFmpeg and M4A audio

parent dd6d1747
Pipeline #83 failed with stage
in 7 minutes and 52 seconds
......@@ -17,5 +17,4 @@ from ..audio.ffmpeg import FFmpegOpener
from ..audio.ffmpeg import FFmpegOGG
from ..audio.ffmpeg import FFmpegMP3
from ..audio.ffmpeg import ffmpeg_available
from ..audio.ffmpeg import FFmpegProcessor
from ..audio.fpcalc import FPCalc
......@@ -15,14 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from abc import ABC
from abc import abstractmethod
from io import BytesIO
from typing import List
from subprocess import PIPE
from subprocess import Popen
from ..constants import FFMPEG_OPENER
from ..constants import FFMPEG_CONVERTER
from ..constants import FFMPEG_PROCESSOR
def ffmpeg_available() -> bool:
......@@ -62,11 +60,6 @@ class FFmpeg(ABC):
return self.__err
class FFmpegProcessor(FFmpeg):
def __init__(self, data: bytes):
super().__init__(data=data, command=FFMPEG_PROCESSOR.copy())
class FFmpegOpener(FFmpeg):
def __init__(self, data: bytes):
super().__init__(data=data, command=FFMPEG_OPENER.copy())
......
......@@ -18,5 +18,4 @@ from ..constants.app_constants import FPCALC
from ..constants.app_constants import YDL_CLI_OPTIONS
from ..constants.app_constants import YOUTUBE
from ..constants.app_constants import FFMPEG_OPENER
from ..constants.app_constants import FFMPEG_PROCESSOR
from ..constants.app_constants import FFMPEG_CONVERTER
......@@ -37,6 +37,5 @@ YOUTUBE = {
# FFmpeg commands
FFMPEG_OPENER = "ffmpeg -i - -f s16le -".split(" ")
FFMPEG_PROCESSOR = "ffmpeg -i - -filter:a loudnorm -vn -b:a 128k -f m4a -".split(" ")
FFMPEG_CONVERTER = ["ffmpeg", "-i", "-", "-vn", "-map_metadata", "0",
"-movflags", "use_metadata_tags"]
......@@ -16,8 +16,6 @@
from io import BytesIO
from typing import Tuple
from ..errors import ProcessorError
from ..audio import FFmpegProcessor
from ..constants.app_constants import YDL_CLI_OPTIONS
......@@ -36,13 +34,7 @@ class YouTubeDownloader(object):
stdout, stderr = proc.communicate()
retcode = proc.returncode
if retcode == 0:
processor = FFmpegProcessor(data=stdout)
if processor.process() == 0:
return BytesIO(processor.get_output()), processor.get_output()
else:
raise ProcessorError(
"ffmpeg failed: " + str(processor.get_extra().decode("utf-8"))
)
return BytesIO(stdout), stdout
else:
raise RuntimeError("youtube-dl downloader exception - more info: " +
str(stderr.decode("utf-8")))
......
This diff is collapsed.
No preview for this file type
File added
File added
File added
File added
import mutagen
import subprocess
from pydub import effects, AudioSegment
from io import BytesIO
from tempfile import TemporaryFile
ctr = BytesIO()
# command = "ffmpeg -i Inm-N5rLUSI.m4a -filter:a loudnorm -vn -b:a 128k -c:a aac -f ipod {}".format(tf.name).split(" ")
# print(tf.name)
# proc = subprocess.Popen(command, stderr=subprocess.PIPE)
# out, err = proc.communicate()
# print(err.decode("utf-8"))
with open("Inm-N5rLUSI.m4a", "rb") as audio:
sound = audio.read()
bf = BytesIO(sound)
s = AudioSegment(bf, format="m4a")
s2 = effects.normalize(s)
s2.export(bf, format="m4a")
c = input("Continue? [yes/no] - ")
if c == "yes":
print(tf.closed)
tf.seek(0)
data = BytesIO(tf.read())
data.seek(0)
print(mutagen.File(data).pprint())
with open("out.m4a", "wb") as file:
data.seek(0)
file.write(data.read())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment