better-ffmpeg-progress 2.3.1__tar.gz → 2.4.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.3.1
3
+ Version: 2.4.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
@@ -168,3 +168,7 @@ The `run` method takes the following **optional** arguments:
168
168
  [29/10/2024]
169
169
  - [v2.3.0] Set `shell=True` to support piping.
170
170
  - [v2.3.1] Kill FFmpeg process(es) on KeyboardInterrupt
171
+
172
+ [31/10/2024]
173
+ - [v2.4.0] Print FFmpeg stderr if better progress information cannot be shown.
174
+ - [v2.4.0] Flush the stream when printing FFmpeg stderr to ensure that it is printed immediately.
@@ -149,4 +149,8 @@ The `run` method takes the following **optional** arguments:
149
149
 
150
150
  [29/10/2024]
151
151
  - [v2.3.0] Set `shell=True` to support piping.
152
- - [v2.3.1] Kill FFmpeg process(es) on KeyboardInterrupt
152
+ - [v2.3.1] Kill FFmpeg process(es) on KeyboardInterrupt
153
+
154
+ [31/10/2024]
155
+ - [v2.4.0] Print FFmpeg stderr if better progress information cannot be shown.
156
+ - [v2.4.0] Flush the stream when printing FFmpeg stderr to ensure that it is printed immediately.
@@ -79,15 +79,11 @@ class FfmpegProcess:
79
79
  )
80
80
 
81
81
  # -progress pipe:1 sends progress metrics to stdout AND -stats_period sets the period at which encoding progress/statistics are updated
82
- # -nostats disables encoding progress/statistics in stderr
83
- self._ffmpeg_args.extend(
84
- ["-progress", "pipe:1", "-stats_period", "0.1", "-nostats"]
85
- )
82
+ self._ffmpeg_args.extend(["-progress", "pipe:1", "-stats_period", "0.1"])
86
83
  except Exception:
87
84
  print(
88
- f"Could not detect the duration of {self._input_filepath.name}. Percentage progress, ETA and estimated filesize will be unavailable."
85
+ f"Could not detect the duration of '{self._input_filepath.name}'. Percentage progress, ETA and estimated filesize will be unavailable.\n",
89
86
  )
90
- self._duration_secs = None
91
87
 
92
88
  def _check_output_exists(self) -> bool:
93
89
  """Check if output file exists and handle overwrite prompt."""
@@ -165,7 +161,9 @@ class FfmpegProcess:
165
161
  if is_error:
166
162
  return
167
163
 
168
- print(f"FFmpeg log written to: {log_file}")
164
+ print(
165
+ f"{"\n\n" if self._duration_secs is None else ""}FFmpeg log filename: {log_file}"
166
+ )
169
167
 
170
168
  def _start_process(
171
169
  self,
@@ -173,12 +171,7 @@ class FfmpegProcess:
173
171
  task_id: Optional[int],
174
172
  progress_handler: Optional[Callable],
175
173
  ) -> None:
176
- # Windows
177
- if os.name == "nt":
178
- creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
179
- # macOS and Linux
180
- else:
181
- creationflags = 0
174
+ creationflags = subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0
182
175
 
183
176
  process = subprocess.Popen(
184
177
  self._ffmpeg_args,
@@ -199,43 +192,50 @@ class FfmpegProcess:
199
192
 
200
193
  try:
201
194
  while process.poll() is None:
202
- try:
203
- stdout = stdout_queue.get_nowait()
195
+ if self._duration_secs is not None:
196
+ try:
197
+ stdout = stdout_queue.get_nowait()
204
198
 
205
- if stdout:
206
- metric, value = stdout.split("=")
207
-
208
- if (
209
- metric in self.WANTED_METRICS
210
- and value
211
- and "N/A" not in value
212
- ):
213
- self._update_metrics(
214
- stdout, metric, value, progress_handler
215
- )
199
+ if stdout:
200
+ metric, value = stdout.split("=")
216
201
 
217
202
  if (
218
- metric == "out_time_ms"
219
- and progress_bar
220
- and task_id is not None
203
+ metric in self.WANTED_METRICS
204
+ and value
205
+ and "N/A" not in value
221
206
  ):
222
- progress_bar.update(
223
- task_id,
224
- completed=self._metrics.seconds_processed,
225
- speed=self._metrics.speed,
207
+ self._update_metrics(
208
+ stdout, metric, value, progress_handler
226
209
  )
227
- except Empty:
228
- pass
210
+
211
+ if (
212
+ metric == "out_time_ms"
213
+ and progress_bar
214
+ and task_id is not None
215
+ ):
216
+ progress_bar.update(
217
+ task_id,
218
+ completed=self._metrics.seconds_processed,
219
+ speed=self._metrics.speed,
220
+ )
221
+ except Empty:
222
+ pass
229
223
 
230
224
  try:
231
225
  stderr = stderr_queue.get_nowait()
226
+
227
+ if self._duration_secs is None:
228
+ print(stderr, end="\r", flush=True)
229
+
232
230
  self._ffmpeg_stderr.append(stderr)
233
231
  except Empty:
234
232
  pass
235
233
 
236
234
  except KeyboardInterrupt:
237
235
  self._kill_process_and_children(process.pid)
238
- sys.exit("[KeyboardInterrupt] FFmpeg process(es) killed.")
236
+ sys.exit(
237
+ f"{"\n" if self._duration_secs is None else ""}[KeyboardInterrupt] FFmpeg process(es) killed."
238
+ )
239
239
 
240
240
  return process.returncode
241
241
 
@@ -258,7 +258,9 @@ class FfmpegProcess:
258
258
  if not self._check_output_exists():
259
259
  return
260
260
 
261
- print(f"Executing: {' '.join(self._ffmpeg_args)}")
261
+ print(
262
+ f"Executing: {' '.join(self._ffmpeg_args)}{"\n" if self._duration_secs is None else ""}"
263
+ )
262
264
 
263
265
  if self._duration_secs and not progress_handler:
264
266
  with Progress(
@@ -314,7 +316,9 @@ class FfmpegProcess:
314
316
  if success_handler:
315
317
  success_handler()
316
318
  else:
317
- print("FFmpeg process completed.")
319
+ print(
320
+ f"{"\n" if self._duration_secs is None else ""}FFmpeg process completed."
321
+ )
318
322
 
319
323
  def _kill_process_and_children(self, proc_pid):
320
324
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: better-ffmpeg-progress
3
- Version: 2.3.1
3
+ Version: 2.4.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
@@ -168,3 +168,7 @@ The `run` method takes the following **optional** arguments:
168
168
  [29/10/2024]
169
169
  - [v2.3.0] Set `shell=True` to support piping.
170
170
  - [v2.3.1] Kill FFmpeg process(es) on KeyboardInterrupt
171
+
172
+ [31/10/2024]
173
+ - [v2.4.0] Print FFmpeg stderr if better progress information cannot be shown.
174
+ - [v2.4.0] Flush the stream when printing FFmpeg stderr to ensure that it is printed immediately.
@@ -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.3.1",
8
+ version="2.4.1",
9
9
  author="GitHub.com/CrypticSignal",
10
10
  author_email="theaudiophile@outlook.com",
11
11
  description="Run FFmpeg & see percentage progress + ETA.",