better-ffmpeg-progress 2.5.7__tar.gz → 2.5.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: better-ffmpeg-progress
3
- Version: 2.5.7
3
+ Version: 2.5.8
4
4
  Summary: Run FFmpeg & see percentage progress + ETA.
5
5
  Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
6
  Author: GitHub.com/CrypticSignal
@@ -179,3 +179,6 @@ The `run` method takes the following **optional** arguments:
179
179
 
180
180
  [18/11/2024]
181
181
  - [v2.5.7] Fix syntax. Should fix issue #26
182
+
183
+ [19/11/2024]
184
+ - [v2.5.8] Remove `\n` from replacement fields in f-strings. Should fix issue #26
@@ -160,4 +160,7 @@ The `run` method takes the following **optional** arguments:
160
160
  - [v2.5.6] Detect a wider range of errors.
161
161
 
162
162
  [18/11/2024]
163
- - [v2.5.7] Fix syntax. Should fix issue #26
163
+ - [v2.5.7] Fix syntax. Should fix issue #26
164
+
165
+ [19/11/2024]
166
+ - [v2.5.8] Remove `\n` from replacement fields in f-strings. Should fix issue #26
@@ -7,6 +7,8 @@ import sys
7
7
  from threading import Thread
8
8
  from typing import Callable, List, Optional, Union
9
9
 
10
+ from .utils import line, print_with_prefix
11
+
10
12
  from ffmpeg import probe
11
13
  import psutil
12
14
  from rich.progress import (
@@ -60,6 +62,7 @@ class FfmpegProcess:
60
62
  # -stats_period sets the period at which encoding progress/statistics are updated
61
63
  command.extend(
62
64
  [
65
+ "-hide_banner",
63
66
  "-loglevel",
64
67
  ffmpeg_loglevel,
65
68
  "-progress",
@@ -74,11 +77,11 @@ class FfmpegProcess:
74
77
  self._print_detected_duration = print_detected_duration
75
78
  self._print_stderr_new_line = print_stderr_new_line
76
79
  self._metrics = Metrics()
77
- self._duration_secs: Optional[float] = None
80
+ self._duration_secs: Optional[float]
78
81
  self._current_size: int = 0
79
82
  self._ffmpeg_log_file: Optional[Path] = None
80
83
  self._error_messages: list[str] = []
81
-
84
+ line()
82
85
  self._get_input_file_duration()
83
86
 
84
87
  def _get_input_file_duration(self) -> None:
@@ -95,13 +98,15 @@ class FfmpegProcess:
95
98
  print(
96
99
  f"The duration of {self._input_filepath.name} has been detected as {self._duration_secs} seconds"
97
100
  )
98
- # -nostats ensures that progress information is not sent to stderr as this info is not needed in the log file, e.g.
99
- # frame= 1381 fps=254 q=18.0 size= 46592KiB time=00:00:46.07 bitrate=8283.1kbits/s speed=8.47x
100
- self._ffmpeg_command.extend(["-nostats"])
101
+
102
+ # -nostats ensures that progress information is not sent to stderr as this info is not needed in the log file, e.g.
103
+ # frame= 1381 fps=254 q=18.0 size= 46592KiB time=00:00:46.07 bitrate=8283.1kbits/s speed=8.47x
104
+ self._ffmpeg_command.extend(["-nostats"])
101
105
  except Exception:
102
106
  print(
103
107
  f"Could not detect the duration of '{self._input_filepath.name}'. Percentage progress, ETA and estimated filesize will be unavailable.\n",
104
108
  )
109
+ self._duration_secs = None
105
110
 
106
111
  def _check_output_exists(self) -> bool:
107
112
  """Check if output file exists and handle overwrite prompt."""
@@ -278,9 +283,7 @@ class FfmpegProcess:
278
283
  except KeyboardInterrupt:
279
284
  self._kill_process_and_children(process.pid)
280
285
  self._write_to_log_file("\n[KeyboardInterrupt] FFmpeg process(es) killed.")
281
- sys.exit(
282
- f"{'\n' if self._duration_secs is None else ''}[KeyboardInterrupt] FFmpeg process(es) killed."
283
- )
286
+ sys.exit("\n[KeyboardInterrupt] FFmpeg process(es) killed.")
284
287
 
285
288
  # After the process ends, drain any remaining stderr
286
289
  while True:
@@ -327,9 +330,8 @@ class FfmpegProcess:
327
330
  with open(self._ffmpeg_log_file, "w"):
328
331
  pass
329
332
 
330
- print(
331
- f"Executing: {' '.join(self._ffmpeg_command)}{'\n' if self._duration_secs is None else ''}"
332
- )
333
+ line()
334
+ print(f"Executing: {' '.join(self._ffmpeg_command)}")
333
335
 
334
336
  if self._duration_secs and not progress_handler:
335
337
  with Progress(
@@ -372,16 +374,20 @@ class FfmpegProcess:
372
374
  if return_code != 0:
373
375
  if error_handler:
374
376
  error_handler()
377
+ sys.exit(
378
+ "\nThe FFmpeg process encounted an error. Custom error handler executed."
379
+ )
375
380
 
376
- sys.exit(
377
- f"FFmpeg process failed with return code {return_code}.\nError(s):\n{'\n'.join(self._error_messages)}\nCheck out '{self._ffmpeg_log_file}' for more details."
378
- )
381
+ print(f"FFmpeg process failed with return code {return_code}.\nError(s):")
382
+ print("\n".join(self._error_messages))
383
+ print(f"Check out '{self._ffmpeg_log_file}' for more details.")
384
+ sys.exit(1)
379
385
 
380
386
  if success_handler:
381
387
  success_handler()
382
388
  else:
383
- print(
384
- f"{'\n' if self._duration_secs is None else ''}FFmpeg process completed."
389
+ print_with_prefix(
390
+ "FFmpeg process completed.", "\n" if self._duration_secs is None else ""
385
391
  )
386
392
 
387
393
  def _kill_process_and_children(self, proc_pid: int) -> None:
@@ -0,0 +1,10 @@
1
+ import os
2
+
3
+
4
+ def line():
5
+ width, _ = os.get_terminal_size()
6
+ print("-" * width)
7
+
8
+
9
+ def print_with_prefix(message, prefix):
10
+ print(f"{prefix}{message}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: better-ffmpeg-progress
3
- Version: 2.5.7
3
+ Version: 2.5.8
4
4
  Summary: Run FFmpeg & see percentage progress + ETA.
5
5
  Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
6
  Author: GitHub.com/CrypticSignal
@@ -179,3 +179,6 @@ The `run` method takes the following **optional** arguments:
179
179
 
180
180
  [18/11/2024]
181
181
  - [v2.5.7] Fix syntax. Should fix issue #26
182
+
183
+ [19/11/2024]
184
+ - [v2.5.8] Remove `\n` from replacement fields in f-strings. Should fix issue #26
@@ -3,6 +3,7 @@ README.md
3
3
  setup.py
4
4
  better_ffmpeg_progress/__init__.py
5
5
  better_ffmpeg_progress/better_ffmpeg_progress.py
6
+ better_ffmpeg_progress/utils.py
6
7
  better_ffmpeg_progress.egg-info/PKG-INFO
7
8
  better_ffmpeg_progress.egg-info/SOURCES.txt
8
9
  better_ffmpeg_progress.egg-info/dependency_links.txt
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as f:
5
5
 
6
6
  setuptools.setup(
7
7
  name="better-ffmpeg-progress",
8
- version="2.5.7",
8
+ version="2.5.8",
9
9
  author="GitHub.com/CrypticSignal",
10
10
  author_email="theaudiophile@outlook.com",
11
11
  description="Run FFmpeg & see percentage progress + ETA.",