better-ffmpeg-progress 2.1.3__tar.gz → 2.1.5__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.1.3
3
+ Version: 2.1.5
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
@@ -121,6 +121,14 @@ Description: <div align="center">
121
121
 
122
122
  - [v2.1.2] [Do not exit the Python interpreter after the FFmpeg process is complete](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/0a358810773835297faae688689c6e0d8a5859ae)
123
123
 
124
+ [22/04/2024]
125
+
126
+ - [v2.1.3] Fix issue [#20](https://github.com/CrypticSignal/better-ffmpeg-progress/issues/20)
127
+
128
+ [28/04/2024]
129
+
130
+ - [v2.1.4] Fix issue [#21](https://github.com/CrypticSignal/better-ffmpeg-progress/issues/21)
131
+
124
132
  Keywords: ffmpeg,progress
125
133
  Platform: UNKNOWN
126
134
  Classifier: Programming Language :: Python :: 3
@@ -112,3 +112,11 @@ The `run` method takes the following **optional** arguments:
112
112
  [05/11/2023]
113
113
 
114
114
  - [v2.1.2] [Do not exit the Python interpreter after the FFmpeg process is complete](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/0a358810773835297faae688689c6e0d8a5859ae)
115
+
116
+ [22/04/2024]
117
+
118
+ - [v2.1.3] Fix issue [#20](https://github.com/CrypticSignal/better-ffmpeg-progress/issues/20)
119
+
120
+ [28/04/2024]
121
+
122
+ - [v2.1.4] Fix issue [#21](https://github.com/CrypticSignal/better-ffmpeg-progress/issues/21)
@@ -72,52 +72,47 @@ class FfmpegProcess:
72
72
 
73
73
  return True
74
74
 
75
- def _update_progress(self, ffmpeg_output, progress_handler):
76
- if ffmpeg_output:
77
- value = ffmpeg_output.split("=")[1].strip()
75
+ def _update_progress(self, ffmpeg_output, metric_name, value, progress_handler):
76
+ if progress_handler is None:
77
+ if metric_name == "out_time_ms":
78
+ seconds_processed = round(int(value) / 1_000_000, 1)
79
+ seconds_increase = seconds_processed - self._previous_seconds_processed
80
+ self._progress_bar.update(seconds_increase)
81
+ self._previous_seconds_processed = seconds_processed
78
82
 
79
- if progress_handler is None:
80
- if "out_time_ms" in ffmpeg_output:
81
- seconds_processed = round(int(value) / 1_000_000, 1)
82
- seconds_increase = seconds_processed - self._previous_seconds_processed
83
- self._progress_bar.update(seconds_increase)
84
- self._previous_seconds_processed = seconds_processed
83
+ else:
84
+ if metric_name == "total_size":
85
+ self._current_size = int(value)
85
86
 
86
- else:
87
- if "total_size" in ffmpeg_output and "N/A" not in value:
88
- self._current_size = int(value)
87
+ elif metric_name == "out_time_ms":
88
+ self._seconds_processed = int(value) / 1_000_000
89
89
 
90
- elif "out_time_ms" in ffmpeg_output:
91
- self._seconds_processed = int(value) / 1_000_000
90
+ if self._can_get_duration:
91
+ self._percentage_progress = (
92
+ self._seconds_processed / self._duration_secs
93
+ ) * 100
92
94
 
93
- if self._can_get_duration:
94
- self._percentage_progress = (
95
- self._seconds_processed / self._duration_secs
96
- ) * 100
97
-
98
- if self._current_size is not None and self._percentage_progress != 0.0:
99
- self._estimated_size = self._current_size * (
100
- 100 / self._percentage_progress
101
- )
95
+ if self._current_size is not None and self._percentage_progress != 0.0:
96
+ self._estimated_size = self._current_size * (
97
+ 100 / self._percentage_progress
98
+ )
102
99
 
103
- elif "speed" in ffmpeg_output:
104
- speed_str = value[:-1]
100
+ elif metric_name == "speed":
101
+ speed_str = value[:-1]
105
102
 
106
- if speed_str != "0" and "N/A" not in speed_str:
107
- self._speed = float(speed_str)
103
+ if speed_str != "0":
104
+ self._speed = float(speed_str)
108
105
 
109
- if self._can_get_duration:
110
- self._eta = (
111
- self._duration_secs - self._seconds_processed
112
- ) / self._speed
106
+ if self._can_get_duration:
107
+ self._eta = (self._duration_secs - self._seconds_processed) / self._speed
113
108
 
114
- if ffmpeg_output == "progress=end":
115
- self._percentage_progress = 100
116
- self._eta = 0
109
+ if ffmpeg_output == "progress=end":
110
+ self._percentage_progress = 100
111
+ self._eta = 0
117
112
 
118
- progress_handler(
119
- self._percentage_progress, self._speed, self._eta, self._estimated_size
120
- )
113
+ progress_handler(
114
+ self._percentage_progress, self._speed, self._eta, self._estimated_size
115
+ )
121
116
 
122
117
  def run(
123
118
  self,
@@ -145,10 +140,34 @@ class FfmpegProcess:
145
140
  leave=False,
146
141
  )
147
142
 
148
- try:
149
143
  while process.poll() is None:
150
- ffmpeg_output = process.stdout.readline().decode().strip()
151
- self._update_progress(ffmpeg_output, progress_handler)
144
+ try:
145
+ ffmpeg_output = process.stdout.readline().decode().strip()
146
+
147
+ except KeyboardInterrupt:
148
+ self._progress_bar.close()
149
+ print("[KeyboardInterrupt] FFmpeg process killed.")
150
+ sys.exit()
151
+
152
+ except Exception as e:
153
+ print(f"Unable to read FFmpeg output:\n{e}")
154
+
155
+ else:
156
+ if not ffmpeg_output:
157
+ continue
158
+
159
+ metric_name = ffmpeg_output.split("=")[0]
160
+ wanted_metrics = ["out_time_ms", "total_size", "speed"]
161
+
162
+ if metric_name not in wanted_metrics:
163
+ continue
164
+
165
+ value = ffmpeg_output.split("=")[1].strip()
166
+
167
+ if not value or "N/A" in value:
168
+ continue
169
+
170
+ self._update_progress(ffmpeg_output, metric_name, value, progress_handler)
152
171
 
153
172
  if process.returncode != 0:
154
173
  if error_handler:
@@ -163,11 +182,3 @@ class FfmpegProcess:
163
182
  success_handler()
164
183
 
165
184
  print(f"\n\nDone! To see FFmpeg's output, check out {ffmpeg_output_file}")
166
-
167
- except KeyboardInterrupt:
168
- self._progress_bar.close()
169
- print("[KeyboardInterrupt] FFmpeg process killed.")
170
- sys.exit()
171
-
172
- except Exception as e:
173
- print(f"[Better FFmpeg Process] {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: better-ffmpeg-progress
3
- Version: 2.1.3
3
+ Version: 2.1.5
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
@@ -121,6 +121,14 @@ Description: <div align="center">
121
121
 
122
122
  - [v2.1.2] [Do not exit the Python interpreter after the FFmpeg process is complete](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/0a358810773835297faae688689c6e0d8a5859ae)
123
123
 
124
+ [22/04/2024]
125
+
126
+ - [v2.1.3] Fix issue [#20](https://github.com/CrypticSignal/better-ffmpeg-progress/issues/20)
127
+
128
+ [28/04/2024]
129
+
130
+ - [v2.1.4] Fix issue [#21](https://github.com/CrypticSignal/better-ffmpeg-progress/issues/21)
131
+
124
132
  Keywords: ffmpeg,progress
125
133
  Platform: UNKNOWN
126
134
  Classifier: Programming Language :: Python :: 3
@@ -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.1.3",
8
+ version="2.1.5",
9
9
  author="GitHub.com/CrypticSignal",
10
10
  author_email="theaudiophile@outlook.com",
11
11
  description="Run FFmpeg & see percentage progress + ETA.",