Made it possible to switch streamer used codecs
This commit is contained in:
parent
1881df6c5c
commit
48ad232393
5 changed files with 19 additions and 21 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
|
@ -33,7 +33,7 @@
|
||||||
"YTP_DOWNLOAD_PATH": "${workspaceFolder}/var/downloads",
|
"YTP_DOWNLOAD_PATH": "${workspaceFolder}/var/downloads",
|
||||||
"YTP_TEMP_PATH": "${workspaceFolder}/var/tmp",
|
"YTP_TEMP_PATH": "${workspaceFolder}/var/tmp",
|
||||||
"YTP_URL_HOST": "http://localhost:8081",
|
"YTP_URL_HOST": "http://localhost:8081",
|
||||||
"YTP_LOG_LEVEL": "DEBUG"
|
"YTP_LOG_LEVEL": "DEBUG",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
"YTP_DOWNLOAD_PATH": "${workspaceFolder}/var/downloads",
|
"YTP_DOWNLOAD_PATH": "${workspaceFolder}/var/downloads",
|
||||||
"YTP_TEMP_PATH": "${workspaceFolder}/var/tmp",
|
"YTP_TEMP_PATH": "${workspaceFolder}/var/tmp",
|
||||||
"YTP_URL_HOST": "http://localhost:8081",
|
"YTP_URL_HOST": "http://localhost:8081",
|
||||||
"YTP_LOG_LEVEL": "DEBUG"
|
"YTP_LOG_LEVEL": "DEBUG",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -28,6 +28,7 @@
|
||||||
"preferredcodec",
|
"preferredcodec",
|
||||||
"preferredquality",
|
"preferredquality",
|
||||||
"tmpfilename",
|
"tmpfilename",
|
||||||
|
"vcodec",
|
||||||
"vconvert",
|
"vconvert",
|
||||||
"writedescription",
|
"writedescription",
|
||||||
"xerror"
|
"xerror"
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,9 @@ Certain values can be set via environment variables, using the `-e` parameter on
|
||||||
* __YTP_PORT__: Which port to bind to. Defaults to `8081`.
|
* __YTP_PORT__: Which port to bind to. Defaults to `8081`.
|
||||||
* __YTP_LOG_LEVEL__: Log level. Defaults to `info`.
|
* __YTP_LOG_LEVEL__: Log level. Defaults to `info`.
|
||||||
* __YTP_MAX_WORKERS__: How many works to use for downloads. Defaults to `1`.
|
* __YTP_MAX_WORKERS__: How many works to use for downloads. Defaults to `1`.
|
||||||
|
* __YTP_MAX_WORKERS__: How many works to use for downloads. Defaults to `1`.
|
||||||
|
* __YTP_STREAMER_VCODEC__: The video codec to use for in-browser streaming. Defaults to `libx264`.
|
||||||
|
* __YTP_STREAMER_ACODEC__: The audio codec to use for in-browser streaming. Defaults to `aac`.
|
||||||
|
|
||||||
## Running behind a reverse proxy
|
## Running behind a reverse proxy
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,9 @@ class Config:
|
||||||
|
|
||||||
started: int = 0
|
started: int = 0
|
||||||
|
|
||||||
|
streamer_vcodec = 'libx264'
|
||||||
|
streamer_acodec = 'aac'
|
||||||
|
|
||||||
ytdlp_version: str = YTDLP_VERSION
|
ytdlp_version: str = YTDLP_VERSION
|
||||||
|
|
||||||
_int_vars: tuple = ('port', 'max_workers', 'socket_timeout', 'extract_info_timeout',)
|
_int_vars: tuple = ('port', 'max_workers', 'socket_timeout', 'extract_info_timeout',)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
from Utils import calcDownloadPath
|
from Utils import calcDownloadPath
|
||||||
|
from Config import Config
|
||||||
|
|
||||||
LOG = logging.getLogger('segments')
|
LOG = logging.getLogger('segments')
|
||||||
|
|
||||||
|
|
@ -13,12 +14,18 @@ class Segments:
|
||||||
index: int
|
index: int
|
||||||
vconvert: bool
|
vconvert: bool
|
||||||
aconvert: bool
|
aconvert: bool
|
||||||
|
vcodec: str
|
||||||
|
acodec: str
|
||||||
|
|
||||||
def __init__(self, index: int, duration: float, vconvert: bool, aconvert: bool):
|
def __init__(self, index: int, duration: float, vconvert: bool, aconvert: bool):
|
||||||
|
config = Config.get_instance()
|
||||||
self.index = int(index)
|
self.index = int(index)
|
||||||
self.duration = float(duration)
|
self.duration = float(duration)
|
||||||
self.vconvert = bool(vconvert)
|
self.vconvert = bool(vconvert)
|
||||||
self.aconvert = bool(aconvert)
|
self.aconvert = bool(aconvert)
|
||||||
|
self.vcodec = config.streamer_vcodec
|
||||||
|
self.acodec = config.streamer_acodec
|
||||||
|
self.vconvert = True
|
||||||
|
|
||||||
async def stream(self, path: str, file: str) -> bytes:
|
async def stream(self, path: str, file: str) -> bytes:
|
||||||
realFile: str = calcDownloadPath(basePath=path, folder=file, createPath=False)
|
realFile: str = calcDownloadPath(basePath=path, folder=file, createPath=False)
|
||||||
|
|
@ -66,29 +73,13 @@ class Segments:
|
||||||
fargs.append('-2')
|
fargs.append('-2')
|
||||||
|
|
||||||
fargs.append('-codec:v')
|
fargs.append('-codec:v')
|
||||||
fargs.append('libx264' if self.vconvert else 'copy')
|
fargs.append(self.vcodec if self.vconvert else 'copy')
|
||||||
if self.vconvert:
|
|
||||||
fargs.append('-crf')
|
|
||||||
fargs.append('23')
|
|
||||||
fargs.append('-preset:v')
|
|
||||||
fargs.append('fast')
|
|
||||||
fargs.append('-level')
|
|
||||||
fargs.append('4.1')
|
|
||||||
fargs.append('-profile:v')
|
|
||||||
fargs.append('baseline')
|
|
||||||
|
|
||||||
# audio section.
|
# audio section.
|
||||||
fargs.append('-map')
|
fargs.append('-map')
|
||||||
fargs.append('0:a:0')
|
fargs.append('0:a:0')
|
||||||
fargs.append('-codec:a')
|
fargs.append('-codec:a')
|
||||||
fargs.append('aac' if self.aconvert else 'copy')
|
fargs.append(self.acodec if self.aconvert else 'copy')
|
||||||
if self.aconvert:
|
|
||||||
fargs.append('-b:a')
|
|
||||||
fargs.append('192k')
|
|
||||||
fargs.append('-ar')
|
|
||||||
fargs.append('22050')
|
|
||||||
fargs.append('-ac')
|
|
||||||
fargs.append('2')
|
|
||||||
|
|
||||||
fargs.append('-sn')
|
fargs.append('-sn')
|
||||||
|
|
||||||
|
|
@ -110,7 +101,7 @@ class Segments:
|
||||||
data, err = await proc.communicate()
|
data, err = await proc.communicate()
|
||||||
|
|
||||||
if 0 != proc.returncode:
|
if 0 != proc.returncode:
|
||||||
LOG.error(f'Failed to stream {realFile} segment {self.index}. {err.decode("utf-8")}')
|
LOG.error(f'Failed to stream {realFile} segment {self.index}. {err.decode("utf-8")}.')
|
||||||
raise Exception(f'Failed to stream {realFile} segment {self.index}.')
|
raise Exception(f'Failed to stream {realFile} segment {self.index}.')
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue