Merge branch 'debug_find_ffmpeg'
This commit is contained in:
commit
0f53cd86c8
3 changed files with 26 additions and 3 deletions
|
@ -7,6 +7,8 @@ import re
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
|
import lbry.utils
|
||||||
from lbry.conf import TranscodeConfig
|
from lbry.conf import TranscodeConfig
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -15,12 +17,22 @@ DISABLED = platform.system() == "Windows"
|
||||||
|
|
||||||
class VideoFileAnalyzer:
|
class VideoFileAnalyzer:
|
||||||
|
|
||||||
|
def _replace_or_pop_env(self, variable):
|
||||||
|
if variable + '_ORIG' in self._env_copy:
|
||||||
|
self._env_copy[variable] = self._env_copy[variable + '_ORIG']
|
||||||
|
else:
|
||||||
|
self._env_copy.pop(variable, None)
|
||||||
|
|
||||||
def __init__(self, conf: TranscodeConfig):
|
def __init__(self, conf: TranscodeConfig):
|
||||||
self._conf = conf
|
self._conf = conf
|
||||||
self._available_encoders = ""
|
self._available_encoders = ""
|
||||||
self._ffmpeg_installed = False
|
self._ffmpeg_installed = False
|
||||||
self._which = None
|
self._which = None
|
||||||
self._checked_ffmpeg = False
|
self._checked_ffmpeg = False
|
||||||
|
self._env_copy = dict(os.environ)
|
||||||
|
if lbry.utils.is_running_from_bundle():
|
||||||
|
# handle the situation where PyInstaller overrides our runtime environment:
|
||||||
|
self._replace_or_pop_env('LD_LIBRARY_PATH')
|
||||||
|
|
||||||
async def _execute(self, command, arguments):
|
async def _execute(self, command, arguments):
|
||||||
if DISABLED:
|
if DISABLED:
|
||||||
|
@ -28,7 +40,7 @@ class VideoFileAnalyzer:
|
||||||
args = shlex.split(arguments)
|
args = shlex.split(arguments)
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
os.path.join(self._conf.ffmpeg_folder, command), *args,
|
os.path.join(self._conf.ffmpeg_folder, command), *args,
|
||||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, env=self._env_copy
|
||||||
)
|
)
|
||||||
stdout, stderr = await process.communicate() # returns when the streams are closed
|
stdout, stderr = await process.communicate() # returns when the streams are closed
|
||||||
return stdout.decode(errors='replace') + stderr.decode(errors='replace'), process.returncode
|
return stdout.decode(errors='replace') + stderr.decode(errors='replace'), process.returncode
|
||||||
|
@ -37,10 +49,10 @@ class VideoFileAnalyzer:
|
||||||
try:
|
try:
|
||||||
version, code = await self._execute(name, "-version")
|
version, code = await self._execute(name, "-version")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning("Unable to run %s, but it was requested. Message: %s", name, str(e))
|
|
||||||
code = -1
|
code = -1
|
||||||
version = ""
|
version = str(e)
|
||||||
if code != 0 or not version.startswith(name):
|
if code != 0 or not version.startswith(name):
|
||||||
|
log.warning("Unable to run %s, but it was requested. Code: %d; Message: %s", name, code, version)
|
||||||
raise FileNotFoundError(f"Unable to locate or run {name}. Please install FFmpeg "
|
raise FileNotFoundError(f"Unable to locate or run {name}. Please install FFmpeg "
|
||||||
f"and ensure that it is callable via PATH or conf.ffmpeg_folder")
|
f"and ensure that it is callable via PATH or conf.ffmpeg_folder")
|
||||||
return version
|
return version
|
||||||
|
|
|
@ -4,6 +4,7 @@ import datetime
|
||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
import typing
|
import typing
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -276,3 +277,8 @@ async def get_external_ip() -> typing.Optional[str]: # used if upnp is disabled
|
||||||
return response['data']['ip']
|
return response['data']['ip']
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def is_running_from_bundle():
|
||||||
|
# see https://pyinstaller.readthedocs.io/en/stable/runtime-information.html
|
||||||
|
return getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')
|
||||||
|
|
|
@ -93,6 +93,11 @@ class TranscodeValidation(ClaimTestCase):
|
||||||
fixed_file = await self.analyzer.verify_or_repair(True, True, file_name)
|
fixed_file = await self.analyzer.verify_or_repair(True, True, file_name)
|
||||||
pathlib.Path(fixed_file).unlink()
|
pathlib.Path(fixed_file).unlink()
|
||||||
|
|
||||||
|
async def test_max_bit_rate(self):
|
||||||
|
self.conf.video_bitrate_maximum = 100
|
||||||
|
with self.assertRaisesRegex(Exception, "The bit rate is above the configured maximum"):
|
||||||
|
await self.analyzer.verify_or_repair(True, False, self.video_file_name)
|
||||||
|
|
||||||
async def test_video_format(self):
|
async def test_video_format(self):
|
||||||
file_name = self.make_name("bad_video_format_1")
|
file_name = self.make_name("bad_video_format_1")
|
||||||
if not file_name.exists():
|
if not file_name.exists():
|
||||||
|
|
Loading…
Add table
Reference in a new issue