Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed loudness normalization - impossible to work with pipes by usi…
…ng FFmpeg and M4A audio
  • Loading branch information
Javinator9889 committed Oct 9, 2019
1 parent dd6d174 commit d970ad3
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 19 deletions.
1 change: 0 additions & 1 deletion YouTubeMDBot/audio/__init__.py
Expand Up @@ -17,5 +17,4 @@
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
7 changes: 0 additions & 7 deletions YouTubeMDBot/audio/ffmpeg.py
Expand Up @@ -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:
Expand Down Expand Up @@ -62,11 +60,6 @@ def get_extra(self) -> bytes:
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())
Expand Down
1 change: 0 additions & 1 deletion YouTubeMDBot/constants/__init__.py
Expand Up @@ -18,5 +18,4 @@
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
1 change: 0 additions & 1 deletion YouTubeMDBot/constants/app_constants.py
Expand Up @@ -37,6 +37,5 @@

# 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"]
10 changes: 1 addition & 9 deletions YouTubeMDBot/downloader/youtube_downloader.py
Expand Up @@ -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


Expand All @@ -36,13 +34,7 @@ def download(self) -> Tuple[BytesIO, bytes]:
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")))
Expand Down
Binary file modified cover.jpg 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hello.m4a 100644 → 100755
Binary file not shown.
Binary file added o.ipod
Binary file not shown.
Binary file added o.m4a
Binary file not shown.
Binary file added o.mp4
Binary file not shown.
Binary file added out.m4a
Binary file not shown.
30 changes: 30 additions & 0 deletions temp_f.py
@@ -0,0 +1,30 @@
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())

0 comments on commit d970ad3

Please sign in to comment.