Try to fix stuttering (ep_3)

This commit is contained in:
Ghost 2024-04-28 15:19:47 +02:00
parent 3091eed167
commit 0df589600a
3 changed files with 14 additions and 48 deletions

View File

@ -230,7 +230,7 @@ def add_subtitle(input_video_path: str, input_subtitle_path: str, output_video_p
return output_video_path
def concatenate_and_save(file_list_path: str, output_filename: str, v_codec: str = None, a_codec: str = None, bandwidth: int = None, prefix: str = "segments", output_directory: str = None) -> str:
def concatenate_and_save(file_list_path: str, output_filename: str, v_codec: str = None, a_codec: str = None, bandwidth: int = None, prefix: str = "segments", output_directory: str = None):
"""
Concatenate input files and save the output with specified decoding parameters.
@ -249,70 +249,36 @@ def concatenate_and_save(file_list_path: str, output_filename: str, v_codec: str
"""
try:
# Input and output arguments
input_args = {
'format': 'concat',
'safe': 0
}
# Output arguments
output_args = {
#'preset': 'ultrafast',
'c': 'copy',
'loglevel': DEBUG_FFMPEG,
'y': None,
}
# Add BANDWIDTH and CODECS if provided
if bandwidth is not None:
output_args['b:v'] = str(bandwidth)
if USE_CODECS:
if v_codec is not None:
output_args['vcodec'] = v_codec
if a_codec is not None:
output_args['acodec'] = a_codec
# Set up the output file name by modifying the video file name
output_file_name = os.path.splitext(output_filename)[0] + f"_{prefix}.mp4"
output_file_name = output_filename
output_file_path = os.path.join(output_directory, output_file_name) if output_directory else output_file_name
# Determine output directory
if output_directory:
output_file_path = os.path.join(output_directory, output_file_name)
else:
output_file_path = output_file_name
# Concatenate input files and output
# Concatenate input file list and output
output = (
ffmpeg.input(
file_list_path,
**input_args
)
.output(
output_file_path,
**output_args
)
ffmpeg.input(file_list_path, safe=0, f='concat')
.output(output_file_path, **output_args)
)
# Overwrite output file if exists
output = ffmpeg.overwrite_output(output)
# Retrieve the command that will be executed
command = output.compile()
logging.info(f"Execute command: {command}")
# Execute the process
process = output.run()
except ffmpeg.Error as ffmpeg_error:
logging.error(f"Error saving MP4: {ffmpeg_error.stdout}")
logging.error(f"Error saving MP4: {ffmpeg_error.stderr.decode('utf-8')}")
return ""
# Remove the temporary file list and folder and completely remove tmp folder
logging.info("Cleanup...")
os.remove(file_list_path)
shutil.rmtree("tmp", ignore_errors=True)
# Return
return output_file_path

View File

@ -25,18 +25,18 @@ def update():
# Make the GitHub API requests and handle potential errors
try:
repo_info = requests.get(f"https://api.github.com/repos/{repo_user}/{repo_name}").json()
release_info = requests.get(f"https://api.github.com/repos/{repo_user}/{repo_name}/releases").json()[0]
response_reposity = requests.get(f"https://api.github.com/repos/{repo_user}/{repo_name}").json()
response_releases = requests.get(f"https://api.github.com/repos/{repo_user}/{repo_name}/releases").json()
except requests.RequestException as e:
console.print(f"[red]Error accessing GitHub API: {e}")
return
# Get start of the reposity
stargazers_count = repo_info['stargazers_count']
stargazers_count = response_reposity['stargazers_count']
# Find info about latest versione deploy and the donwload count
last_version = release_info['name']
down_count = release_info['assets'][0]['download_count']
last_version = response_releases[0]['name']
down_count = response_releases[0]['assets'][0]['download_count']
# Calculate percentual of start base on download count
if down_count > 0 and stargazers_count > 0: