From 8c25f6502488679412f2efa8c03e0b01e2cbc90d Mon Sep 17 00:00:00 2001 From: Trent Date: Thu, 25 Jun 2020 02:22:34 -0700 Subject: [PATCH 1/3] check sample rate and lower if too high --- lbry/file_analysis.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lbry/file_analysis.py b/lbry/file_analysis.py index 21dd8df61..af55d500e 100644 --- a/lbry/file_analysis.py +++ b/lbry/file_analysis.py @@ -195,10 +195,13 @@ class VideoFileAnalyzer: if stream["codec_type"] != "audio": continue codec = stream["codec_name"] + sample_rate = stream['sample_rate'] log.debug(" Detected audio codec is %s", codec) if not {"aac", "mp3", "flac", "vorbis", "opus"}.intersection(codec.split(",")): return "Audio codec is not in the approved list of AAC, FLAC, MP3, Vorbis, and Opus. " \ f"Actual: {codec} [{stream['codec_long_name']}]" + if sample_rate > "48000": + return "Sample rate out of range" return "" @@ -410,7 +413,7 @@ class VideoFileAnalyzer: # the plan for transcoding: # we have to re-encode the video if it is in a nonstandard format # we also re-encode if we are h264 but not yuv420p (both errors caught in video_msg) - # we also re-encode if our bitrate is too high + # we also re-encode if our bitrate or sample rate is too high try: transcode_command = [f'-i "{file_path}" -y -c:s copy -c:d copy -c:v'] @@ -433,6 +436,8 @@ class VideoFileAnalyzer: if volume_msg: volume_filter = await self._get_volume_filter() transcode_command.append(volume_filter) + if audio_msg == "Sample rate out of range": + transcode_command.append(" -ar 48000 ") else: transcode_command.append("copy") From 7b01dde0631e24995033d507d6d093ee265351a5 Mon Sep 17 00:00:00 2001 From: Trent N Date: Mon, 6 Jul 2020 16:06:43 -0700 Subject: [PATCH 2/3] convert sample_rate to integer and dont force a volume_filter added volume_filter example deleted _get_volume_filter --- .gitignore | 5 ++++- lbry/conf.py | 2 +- lbry/file_analysis.py | 11 +++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 36cb694de..ed178a1ed 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,7 @@ _trial_temp/ /tests/integration/blockchain/files /tests/.coverage.* -/lbry/wallet/bin \ No newline at end of file +/lbry/wallet/bin + +/.vscode +/.gitignore \ No newline at end of file diff --git a/lbry/conf.py b/lbry/conf.py index deb9222f2..d7cc8237b 100644 --- a/lbry/conf.py +++ b/lbry/conf.py @@ -487,7 +487,7 @@ class TranscodeConfig(BaseConfig): audio_encoder = String('FFmpeg codec and parameters for the audio encoding. ' 'Example: libopus -b:a 128k', 'aac -b:a 160k') - volume_filter = String('FFmpeg filter for audio normalization.', '-af loudnorm') + volume_filter = String('FFmpeg filter for audio normalization. Exmple: -af loudnorm', '') volume_analysis_time = Integer('Maximum seconds into the file that we examine audio volume (0 to disable).', 240) diff --git a/lbry/file_analysis.py b/lbry/file_analysis.py index af55d500e..179ffbfd6 100644 --- a/lbry/file_analysis.py +++ b/lbry/file_analysis.py @@ -195,12 +195,11 @@ class VideoFileAnalyzer: if stream["codec_type"] != "audio": continue codec = stream["codec_name"] - sample_rate = stream['sample_rate'] log.debug(" Detected audio codec is %s", codec) if not {"aac", "mp3", "flac", "vorbis", "opus"}.intersection(codec.split(",")): return "Audio codec is not in the approved list of AAC, FLAC, MP3, Vorbis, and Opus. " \ f"Actual: {codec} [{stream['codec_long_name']}]" - if sample_rate > "48000": + if int(stream['sample_rate']) > 48000: return "Sample rate out of range" return "" @@ -307,9 +306,6 @@ class VideoFileAnalyzer: raise Exception(f"The audio encoder is not available. Requested: {encoder or 'aac'}") - async def _get_volume_filter(self): - return self._conf.volume_filter if self._conf.volume_filter else "-af loudnorm" - @staticmethod def _get_best_container_extension(scan_data, video_encoder): # the container is chosen by the video format @@ -433,9 +429,8 @@ class VideoFileAnalyzer: if audio_msg or volume_msg: audio_encoder = await self._get_audio_encoder(extension) transcode_command.append(audio_encoder) - if volume_msg: - volume_filter = await self._get_volume_filter() - transcode_command.append(volume_filter) + if volume_msg and self._conf.volume_filter: + transcode_command.append(self._conf.volume_filter) if audio_msg == "Sample rate out of range": transcode_command.append(" -ar 48000 ") else: From c6c668676cc41110c2f986724aa0252cc3bc3700 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 14 Jul 2020 21:54:42 -0400 Subject: [PATCH 3/3] changed video_bitrate_maximum from 8.4MB to 5MB --- lbry/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbry/conf.py b/lbry/conf.py index d7cc8237b..cc1eaa98e 100644 --- a/lbry/conf.py +++ b/lbry/conf.py @@ -479,7 +479,7 @@ class TranscodeConfig(BaseConfig): video_encoder = String('FFmpeg codec and parameters for the video encoding. ' 'Example: libaom-av1 -crf 25 -b:v 0 -strict experimental', 'libx264 -crf 24 -preset faster -pix_fmt yuv420p') - video_bitrate_maximum = Integer('Maximum bits per second allowed for video streams (0 to disable).', 8400000) + video_bitrate_maximum = Integer('Maximum bits per second allowed for video streams (0 to disable).', 5_000_000) video_scaler = String('FFmpeg scaling parameters for reducing bitrate. ' 'Example: -vf "scale=-2:720,fps=24" -maxrate 5M -bufsize 3M', r'-vf "scale=if(gte(iw\,ih)\,min(1920\,iw)\,-2):if(lt(iw\,ih)\,min(1920\,ih)\,-2)" '