better-ffmpeg-progress 2.6.0__tar.gz → 2.6.1__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.6.0
3
+ Version: 2.6.1
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
@@ -7,7 +7,7 @@ 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
10
+ from .utils import print_with_prefix
11
11
 
12
12
  from ffmpeg import probe
13
13
  import psutil
@@ -52,7 +52,7 @@ class FfmpegProcess:
52
52
  self,
53
53
  command: List[str],
54
54
  ffmpeg_loglevel: str = "verbose",
55
- print_detected_duration: bool = True,
55
+ print_detected_duration: bool = False,
56
56
  print_stderr_new_line: bool = False,
57
57
  ):
58
58
  if "-i" not in command:
@@ -60,17 +60,17 @@ class FfmpegProcess:
60
60
 
61
61
  # -progress pipe:1 sends progress metrics to stdout
62
62
  # -stats_period sets the period at which encoding progress/statistics are updated
63
- command.extend(
64
- [
65
- "-hide_banner",
66
- "-loglevel",
67
- ffmpeg_loglevel,
68
- "-progress",
69
- "pipe:1",
70
- "-stats_period",
71
- "0.1",
72
- ]
73
- )
63
+ extra_ffmpeg_options = [
64
+ "-hide_banner",
65
+ "-loglevel",
66
+ ffmpeg_loglevel,
67
+ "-progress",
68
+ "pipe:1",
69
+ "-stats_period",
70
+ "0.1",
71
+ ]
72
+
73
+ command[1:1] = extra_ffmpeg_options
74
74
 
75
75
  self._ffmpeg_command = command
76
76
  self._output_filepath = Path(command[-1])
@@ -94,33 +94,36 @@ class FfmpegProcess:
94
94
  )
95
95
 
96
96
  if self._print_detected_duration:
97
- line()
98
- print(
99
- f"The duration of {self._input_filepath.name} has been detected as {self._duration_secs} seconds"
97
+ print_with_prefix(
98
+ "[Better FFmpeg Progress] ",
99
+ f"The duration of {self._input_filepath.name} has been detected as {self._duration_secs} seconds",
100
100
  )
101
- line()
102
101
 
103
102
  # -nostats ensures that progress information is not sent to stderr as this info is not needed in the log file, e.g.
104
103
  # frame= 1381 fps=254 q=18.0 size= 46592KiB time=00:00:46.07 bitrate=8283.1kbits/s speed=8.47x
105
104
  self._ffmpeg_command.extend(["-nostats"])
106
105
  except Exception:
107
- print(
106
+ print_with_prefix(
107
+ "[Better FFmpeg Progress] ",
108
108
  f"Could not detect the duration of '{self._input_filepath.name}'. Percentage progress, ETA and estimated filesize will be unavailable.\n",
109
109
  )
110
110
  self._duration_secs = None
111
111
 
112
- def _check_output_exists(self) -> bool:
113
- """Check if output file exists and handle overwrite prompt."""
112
+ def _should_overwrite(self) -> bool:
114
113
  if self._output_filepath.exists() and "-y" not in self._ffmpeg_command:
115
114
  choice = input(
116
115
  f"{self._output_filepath} already exists. Overwrite? [Y/N]: "
117
116
  ).lower()
117
+
118
118
  if choice != "y":
119
- print(
120
- "FFmpeg process cancelled. Output file exists and overwrite declined."
119
+ print_with_prefix(
120
+ "[Better FFmpeg Progress] ",
121
+ "FFmpeg process cancelled. Output file exists and overwrite declined.",
121
122
  )
122
123
  return False
124
+
123
125
  self._ffmpeg_command.insert(1, "-y")
126
+
124
127
  return True
125
128
 
126
129
  def _update_metrics(
@@ -327,7 +330,7 @@ class FfmpegProcess:
327
330
  success_handler: Optional function to handle successful completion of the FFmpeg process
328
331
  error_handler: Optional function for FFmpeg process error handling
329
332
  """
330
- if not self._check_output_exists():
333
+ if not self._should_overwrite():
331
334
  return
332
335
 
333
336
  self._ffmpeg_log_file = Path(log_file)
@@ -336,8 +339,6 @@ class FfmpegProcess:
336
339
  pass
337
340
 
338
341
  if print_command:
339
- line()
340
-
341
342
  print(f"Executing: {' '.join(self._ffmpeg_command)}")
342
343
 
343
344
  if self._duration_secs and not progress_handler:
@@ -381,8 +382,8 @@ class FfmpegProcess:
381
382
 
382
383
  if return_code == 0:
383
384
  print_with_prefix(
384
- "FFmpeg process completed.",
385
385
  "\n" if self._duration_secs is None else "",
386
+ "FFmpeg process completed.",
386
387
  )
387
388
 
388
389
  self._handle_process_ended(return_code, error_handler, success_handler)
@@ -401,9 +402,17 @@ class FfmpegProcess:
401
402
  "\nThe FFmpeg process encounted an error. Custom error handler executed."
402
403
  )
403
404
 
404
- print(f"FFmpeg process failed with return code {return_code}.\nError(s):")
405
- print("\n".join(self._error_messages))
406
- print(f"Check out '{self._ffmpeg_log_file}' for more details.")
405
+ print_with_prefix(
406
+ "[Better FFmpeg Progress] ",
407
+ f"FFmpeg process failed with return code {return_code}.\nError(s):",
408
+ )
409
+ print_with_prefix(
410
+ "[Better FFmpeg Progress] ", "\n".join(self._error_messages)
411
+ )
412
+ print_with_prefix(
413
+ "[Better FFmpeg Progress] ",
414
+ f"Check out '{self._ffmpeg_log_file}' for more details.",
415
+ )
407
416
  sys.exit(1)
408
417
 
409
418
  if success_handler:
@@ -6,5 +6,5 @@ def line():
6
6
  print("-" * width)
7
7
 
8
8
 
9
- def print_with_prefix(message, prefix):
9
+ def print_with_prefix(prefix, message):
10
10
  print(f"{prefix}{message}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: better-ffmpeg-progress
3
- Version: 2.6.0
3
+ Version: 2.6.1
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
@@ -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.6.0",
8
+ version="2.6.1",
9
9
  author="GitHub.com/CrypticSignal",
10
10
  author_email="theaudiophile@outlook.com",
11
11
  description="Run FFmpeg & see percentage progress + ETA.",