forked from LBRYCommunity/lbry-sdk
Merge pull request #2986 from Death916/master
check sample rate and lower if too high
This commit is contained in:
commit
383f0ce450
3 changed files with 13 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -15,3 +15,6 @@ _trial_temp/
|
||||||
/tests/.coverage.*
|
/tests/.coverage.*
|
||||||
|
|
||||||
/lbry/wallet/bin
|
/lbry/wallet/bin
|
||||||
|
|
||||||
|
/.vscode
|
||||||
|
/.gitignore
|
|
@ -479,7 +479,7 @@ class TranscodeConfig(BaseConfig):
|
||||||
video_encoder = String('FFmpeg codec and parameters for the video encoding. '
|
video_encoder = String('FFmpeg codec and parameters for the video encoding. '
|
||||||
'Example: libaom-av1 -crf 25 -b:v 0 -strict experimental',
|
'Example: libaom-av1 -crf 25 -b:v 0 -strict experimental',
|
||||||
'libx264 -crf 24 -preset faster -pix_fmt yuv420p')
|
'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. '
|
video_scaler = String('FFmpeg scaling parameters for reducing bitrate. '
|
||||||
'Example: -vf "scale=-2:720,fps=24" -maxrate 5M -bufsize 3M',
|
'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)" '
|
r'-vf "scale=if(gte(iw\,ih)\,min(1920\,iw)\,-2):if(lt(iw\,ih)\,min(1920\,ih)\,-2)" '
|
||||||
|
@ -487,7 +487,7 @@ class TranscodeConfig(BaseConfig):
|
||||||
audio_encoder = String('FFmpeg codec and parameters for the audio encoding. '
|
audio_encoder = String('FFmpeg codec and parameters for the audio encoding. '
|
||||||
'Example: libopus -b:a 128k',
|
'Example: libopus -b:a 128k',
|
||||||
'aac -b:a 160k')
|
'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)
|
volume_analysis_time = Integer('Maximum seconds into the file that we examine audio volume (0 to disable).', 240)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,8 @@ class VideoFileAnalyzer:
|
||||||
if not {"aac", "mp3", "flac", "vorbis", "opus"}.intersection(codec.split(",")):
|
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. " \
|
return "Audio codec is not in the approved list of AAC, FLAC, MP3, Vorbis, and Opus. " \
|
||||||
f"Actual: {codec} [{stream['codec_long_name']}]"
|
f"Actual: {codec} [{stream['codec_long_name']}]"
|
||||||
|
if int(stream['sample_rate']) > 48000:
|
||||||
|
return "Sample rate out of range"
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -304,9 +306,6 @@ class VideoFileAnalyzer:
|
||||||
|
|
||||||
raise Exception(f"The audio encoder is not available. Requested: {encoder or 'aac'}")
|
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
|
@staticmethod
|
||||||
def _get_best_container_extension(scan_data, video_encoder):
|
def _get_best_container_extension(scan_data, video_encoder):
|
||||||
# the container is chosen by the video format
|
# the container is chosen by the video format
|
||||||
|
@ -410,7 +409,7 @@ class VideoFileAnalyzer:
|
||||||
# the plan for transcoding:
|
# the plan for transcoding:
|
||||||
# we have to re-encode the video if it is in a nonstandard format
|
# 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 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:
|
try:
|
||||||
transcode_command = [f'-i "{file_path}" -y -c:s copy -c:d copy -c:v']
|
transcode_command = [f'-i "{file_path}" -y -c:s copy -c:d copy -c:v']
|
||||||
|
@ -430,9 +429,10 @@ class VideoFileAnalyzer:
|
||||||
if audio_msg or volume_msg:
|
if audio_msg or volume_msg:
|
||||||
audio_encoder = await self._get_audio_encoder(extension)
|
audio_encoder = await self._get_audio_encoder(extension)
|
||||||
transcode_command.append(audio_encoder)
|
transcode_command.append(audio_encoder)
|
||||||
if volume_msg:
|
if volume_msg and self._conf.volume_filter:
|
||||||
volume_filter = await self._get_volume_filter()
|
transcode_command.append(self._conf.volume_filter)
|
||||||
transcode_command.append(volume_filter)
|
if audio_msg == "Sample rate out of range":
|
||||||
|
transcode_command.append(" -ar 48000 ")
|
||||||
else:
|
else:
|
||||||
transcode_command.append("copy")
|
transcode_command.append("copy")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue