better-ffmpeg-progress 2.1.1__tar.gz → 2.1.3__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.
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.1
2
+ Name: better-ffmpeg-progress
3
+ Version: 2.1.3
4
+ Summary: Run FFmpeg & see percentage progress + ETA.
5
+ Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
+ Author: GitHub.com/CrypticSignal
7
+ Author-email: theaudiophile@outlook.com
8
+ License: UNKNOWN
9
+ Description: <div align="center">
10
+
11
+ [![PyPI downloads](https://img.shields.io/pypi/dm/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
12
+ [![PyPI downloads](https://img.shields.io/pypi/dw/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
13
+ [![GitHub](https://img.shields.io/github/license/crypticsignal/better-ffmpeg-progress?label=License&color=blue)](LICENSE.txt)
14
+
15
+ # Better FFmpeg Progress
16
+
17
+ Runs an FFmpeg command and uses [tqdm](https://github.com/tqdm/tqdm) to show a progress bar.
18
+
19
+ </div>
20
+
21
+ ## Example:
22
+
23
+ ```
24
+ 39%|███████████████████████████████████████████ | 23.6/60.2 [00:19<00:34, 1.07s/s]
25
+ ```
26
+
27
+ Where:
28
+
29
+ - `39%` is the percentage progress.
30
+ - `23.6` seconds of the input file have been processed.
31
+ - `60.2` is the duration of the input file in seconds.
32
+ - `00:19` is the time elapsed since the FFmpeg process started.
33
+ - `00:34` is the estimated time required for the FFmpeg process to complete.
34
+ - `1.07` shows how many seconds of the input file are processed per second.
35
+
36
+ ## Installation:
37
+
38
+ `pip3 install better-ffmpeg-progress --upgrade`
39
+
40
+ ## Usage:
41
+
42
+ Create an instance of the `FfmpegProcess` class and supply a list of arguments like you would to `subprocess.run()`.
43
+
44
+ Simple Example:
45
+
46
+ ```py
47
+ from better_ffmpeg_progress import FfmpegProcess
48
+ # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
49
+ process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
50
+ # Use the run method to run the FFmpeg command.
51
+ process.run()
52
+ ```
53
+
54
+ Advanced Example:
55
+
56
+ ```py
57
+ from better_ffmpeg_progress import FfmpegProcess
58
+
59
+ def handle_progress_info(percentage, speed, eta, estimated_filesize):
60
+ print(f"Estimated Output Filesize: {estimated_filesize / 1_000_000} MB")
61
+
62
+ def handle_success():
63
+ # Code to run if the FFmpeg process completes successfully.
64
+ pass
65
+
66
+ def handle_error():
67
+ # Code to run if the FFmpeg process encounters an error.
68
+ pass
69
+
70
+ # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
71
+ process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
72
+
73
+ ffmpeg_output_path = 'ffmpeg_output.txt'
74
+
75
+ # Use the run method to run the FFmpeg command.
76
+ process.run(progress_handler=handle_progress_info, ffmpeg_output_file=ffmpeg_output_path, success_handler=handle_success, error_handler=handle_error)
77
+ ```
78
+
79
+ The `run` method takes the following **optional** arguments:
80
+
81
+ - `progress_handler`
82
+
83
+ - You can create a function if you would like to do something with the following values:
84
+
85
+ - Percentage progress. [float]
86
+ - Speed, e.g. `22.3x` which means that 22.3 seconds of the input are processed every second. [string]
87
+ - ETA in seconds. [float]
88
+ - Estimated output filesize in bytes. [float]
89
+ - _Note: This is not accurate. Please take the value with a grain of salt._
90
+
91
+ The values will be `None` if unknown. The function will receive the aforementioned metrics as arguments, about two times per second.
92
+
93
+ - `ffmpeg_output_file` - A string path to define where you want the output of FFmpeg to be saved. By default, this is saved in a folder named "ffmpeg_output", with the filename `[<input_filename>].txt`.
94
+
95
+ - `success_handler` - A function to run if the FFmpeg process completes successfully.
96
+
97
+ - `error_handler` - A function to run if the FFmpeg process encounters an error.
98
+
99
+ ## Changelog:
100
+
101
+ [19/09/2022]
102
+
103
+ - Add the ability to specify a `success_handler` argument, a function to run if the FFmpeg process completes successfully.
104
+ - Add 0.001 to tqdm's `total` parameter to prevent the chance of getting `TqdmWarning: clamping frac to range [0, 1]`
105
+
106
+ [21/12/2022]
107
+
108
+ - [v2.0.7] Fix `'estimated_size' referenced before assignment` error.
109
+ - [v2.0.7] The progress bar now uses 1 decimal place for seconds processed and total duration.
110
+
111
+ [22/12/2022]
112
+
113
+ - [v2.0.8] Add the ability to specify an `error_handler` argument, a function to run if the FFmpeg process encounters an error.
114
+ - [v2.0.9] Fix a typo (commit [da45a84](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/da45a8416856ab7d3c7b748db5703fa3dbc65f60))
115
+
116
+ [07/02/2022]
117
+
118
+ - [v2.1.0] [Update function name](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/572fe8a0d71957d00b833134a4d35170630203fa) to fix `'process_complete_handler' is not defined` error.
119
+
120
+ [05/11/2023]
121
+
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
+
124
+ Keywords: ffmpeg,progress
125
+ Platform: UNKNOWN
126
+ Classifier: Programming Language :: Python :: 3
127
+ Classifier: License :: OSI Approved :: MIT License
128
+ Classifier: Operating System :: OS Independent
129
+ Requires-Python: >=3.6
130
+ Description-Content-Type: text/markdown
@@ -108,3 +108,7 @@ The `run` method takes the following **optional** arguments:
108
108
  [07/02/2022]
109
109
 
110
110
  - [v2.1.0] [Update function name](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/572fe8a0d71957d00b833134a4d35170630203fa) to fix `'process_complete_handler' is not defined` error.
111
+
112
+ [05/11/2023]
113
+
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)
@@ -52,7 +52,7 @@ class FfmpegProcess:
52
52
  if self._can_get_duration:
53
53
  self._ffmpeg_args += ["-progress", "pipe:1", "-nostats"]
54
54
 
55
- def _check_if_overwrite(self):
55
+ def _should_run_ffmpeg(self):
56
56
  dirname = os.path.dirname(self._output_filepath)
57
57
  self._dir_files = (
58
58
  [file for file in os.listdir(dirname)] if dirname else [file for file in os.listdir()]
@@ -62,10 +62,15 @@ class FfmpegProcess:
62
62
  choice = input(f"{self._output_filepath} already exists. Overwrite? [Y/N]: ").lower()
63
63
 
64
64
  if choice != "y":
65
- print("Exiting Better FFmpeg Process.")
66
- sys.exit()
65
+ print(
66
+ "FFmpeg will not run as the output filename already exists, and you do not want it to be overwritten."
67
+ )
68
+ return False
67
69
 
68
70
  self._ffmpeg_args.insert(1, "-y")
71
+ return True
72
+
73
+ return True
69
74
 
70
75
  def _update_progress(self, ffmpeg_output, progress_handler):
71
76
  if ffmpeg_output:
@@ -121,7 +126,8 @@ class FfmpegProcess:
121
126
  success_handler=None,
122
127
  error_handler=None,
123
128
  ):
124
- self._check_if_overwrite()
129
+ if not self._should_run_ffmpeg():
130
+ return
125
131
 
126
132
  if ffmpeg_output_file is None:
127
133
  os.makedirs("ffmpeg_output", exist_ok=True)
@@ -157,12 +163,11 @@ class FfmpegProcess:
157
163
  success_handler()
158
164
 
159
165
  print(f"\n\nDone! To see FFmpeg's output, check out {ffmpeg_output_file}")
160
- sys.exit()
161
166
 
162
167
  except KeyboardInterrupt:
163
- print("[KeyboardInterrupt] FFmpeg process killed. Exiting Better FFmpeg Progress.")
168
+ self._progress_bar.close()
169
+ print("[KeyboardInterrupt] FFmpeg process killed.")
164
170
  sys.exit()
165
171
 
166
172
  except Exception as e:
167
- print(f"[Error] {e}\nExiting Better FFmpeg Progress.")
168
- sys.exit()
173
+ print(f"[Better FFmpeg Process] {e}")
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.1
2
+ Name: better-ffmpeg-progress
3
+ Version: 2.1.3
4
+ Summary: Run FFmpeg & see percentage progress + ETA.
5
+ Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
+ Author: GitHub.com/CrypticSignal
7
+ Author-email: theaudiophile@outlook.com
8
+ License: UNKNOWN
9
+ Description: <div align="center">
10
+
11
+ [![PyPI downloads](https://img.shields.io/pypi/dm/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
12
+ [![PyPI downloads](https://img.shields.io/pypi/dw/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
13
+ [![GitHub](https://img.shields.io/github/license/crypticsignal/better-ffmpeg-progress?label=License&color=blue)](LICENSE.txt)
14
+
15
+ # Better FFmpeg Progress
16
+
17
+ Runs an FFmpeg command and uses [tqdm](https://github.com/tqdm/tqdm) to show a progress bar.
18
+
19
+ </div>
20
+
21
+ ## Example:
22
+
23
+ ```
24
+ 39%|███████████████████████████████████████████ | 23.6/60.2 [00:19<00:34, 1.07s/s]
25
+ ```
26
+
27
+ Where:
28
+
29
+ - `39%` is the percentage progress.
30
+ - `23.6` seconds of the input file have been processed.
31
+ - `60.2` is the duration of the input file in seconds.
32
+ - `00:19` is the time elapsed since the FFmpeg process started.
33
+ - `00:34` is the estimated time required for the FFmpeg process to complete.
34
+ - `1.07` shows how many seconds of the input file are processed per second.
35
+
36
+ ## Installation:
37
+
38
+ `pip3 install better-ffmpeg-progress --upgrade`
39
+
40
+ ## Usage:
41
+
42
+ Create an instance of the `FfmpegProcess` class and supply a list of arguments like you would to `subprocess.run()`.
43
+
44
+ Simple Example:
45
+
46
+ ```py
47
+ from better_ffmpeg_progress import FfmpegProcess
48
+ # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
49
+ process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
50
+ # Use the run method to run the FFmpeg command.
51
+ process.run()
52
+ ```
53
+
54
+ Advanced Example:
55
+
56
+ ```py
57
+ from better_ffmpeg_progress import FfmpegProcess
58
+
59
+ def handle_progress_info(percentage, speed, eta, estimated_filesize):
60
+ print(f"Estimated Output Filesize: {estimated_filesize / 1_000_000} MB")
61
+
62
+ def handle_success():
63
+ # Code to run if the FFmpeg process completes successfully.
64
+ pass
65
+
66
+ def handle_error():
67
+ # Code to run if the FFmpeg process encounters an error.
68
+ pass
69
+
70
+ # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
71
+ process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
72
+
73
+ ffmpeg_output_path = 'ffmpeg_output.txt'
74
+
75
+ # Use the run method to run the FFmpeg command.
76
+ process.run(progress_handler=handle_progress_info, ffmpeg_output_file=ffmpeg_output_path, success_handler=handle_success, error_handler=handle_error)
77
+ ```
78
+
79
+ The `run` method takes the following **optional** arguments:
80
+
81
+ - `progress_handler`
82
+
83
+ - You can create a function if you would like to do something with the following values:
84
+
85
+ - Percentage progress. [float]
86
+ - Speed, e.g. `22.3x` which means that 22.3 seconds of the input are processed every second. [string]
87
+ - ETA in seconds. [float]
88
+ - Estimated output filesize in bytes. [float]
89
+ - _Note: This is not accurate. Please take the value with a grain of salt._
90
+
91
+ The values will be `None` if unknown. The function will receive the aforementioned metrics as arguments, about two times per second.
92
+
93
+ - `ffmpeg_output_file` - A string path to define where you want the output of FFmpeg to be saved. By default, this is saved in a folder named "ffmpeg_output", with the filename `[<input_filename>].txt`.
94
+
95
+ - `success_handler` - A function to run if the FFmpeg process completes successfully.
96
+
97
+ - `error_handler` - A function to run if the FFmpeg process encounters an error.
98
+
99
+ ## Changelog:
100
+
101
+ [19/09/2022]
102
+
103
+ - Add the ability to specify a `success_handler` argument, a function to run if the FFmpeg process completes successfully.
104
+ - Add 0.001 to tqdm's `total` parameter to prevent the chance of getting `TqdmWarning: clamping frac to range [0, 1]`
105
+
106
+ [21/12/2022]
107
+
108
+ - [v2.0.7] Fix `'estimated_size' referenced before assignment` error.
109
+ - [v2.0.7] The progress bar now uses 1 decimal place for seconds processed and total duration.
110
+
111
+ [22/12/2022]
112
+
113
+ - [v2.0.8] Add the ability to specify an `error_handler` argument, a function to run if the FFmpeg process encounters an error.
114
+ - [v2.0.9] Fix a typo (commit [da45a84](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/da45a8416856ab7d3c7b748db5703fa3dbc65f60))
115
+
116
+ [07/02/2022]
117
+
118
+ - [v2.1.0] [Update function name](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/572fe8a0d71957d00b833134a4d35170630203fa) to fix `'process_complete_handler' is not defined` error.
119
+
120
+ [05/11/2023]
121
+
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
+
124
+ Keywords: ffmpeg,progress
125
+ Platform: UNKNOWN
126
+ Classifier: Programming Language :: Python :: 3
127
+ Classifier: License :: OSI Approved :: MIT License
128
+ Classifier: Operating System :: OS Independent
129
+ Requires-Python: >=3.6
130
+ Description-Content-Type: text/markdown
@@ -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.1",
8
+ version="2.1.3",
9
9
  author="GitHub.com/CrypticSignal",
10
10
  author_email="theaudiophile@outlook.com",
11
11
  description="Run FFmpeg & see percentage progress + ETA.",
@@ -1,125 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: better-ffmpeg-progress
3
- Version: 2.1.1
4
- Summary: Run FFmpeg & see percentage progress + ETA.
5
- Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
- Author: GitHub.com/CrypticSignal
7
- Author-email: theaudiophile@outlook.com
8
- Keywords: ffmpeg,progress
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.6
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
-
16
- <div align="center">
17
-
18
- [![PyPI downloads](https://img.shields.io/pypi/dm/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
19
- [![PyPI downloads](https://img.shields.io/pypi/dw/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
20
- [![GitHub](https://img.shields.io/github/license/crypticsignal/better-ffmpeg-progress?label=License&color=blue)](LICENSE.txt)
21
-
22
- # Better FFmpeg Progress
23
-
24
- Runs an FFmpeg command and uses [tqdm](https://github.com/tqdm/tqdm) to show a progress bar.
25
-
26
- </div>
27
-
28
- ## Example:
29
-
30
- ```
31
- 39%|███████████████████████████████████████████ | 23.6/60.2 [00:19<00:34, 1.07s/s]
32
- ```
33
-
34
- Where:
35
-
36
- - `39%` is the percentage progress.
37
- - `23.6` seconds of the input file have been processed.
38
- - `60.2` is the duration of the input file in seconds.
39
- - `00:19` is the time elapsed since the FFmpeg process started.
40
- - `00:34` is the estimated time required for the FFmpeg process to complete.
41
- - `1.07` shows how many seconds of the input file are processed per second.
42
-
43
- ## Installation:
44
-
45
- `pip3 install better-ffmpeg-progress --upgrade`
46
-
47
- ## Usage:
48
-
49
- Create an instance of the `FfmpegProcess` class and supply a list of arguments like you would to `subprocess.run()`.
50
-
51
- Simple Example:
52
-
53
- ```py
54
- from better_ffmpeg_progress import FfmpegProcess
55
- # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
56
- process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
57
- # Use the run method to run the FFmpeg command.
58
- process.run()
59
- ```
60
-
61
- Advanced Example:
62
-
63
- ```py
64
- from better_ffmpeg_progress import FfmpegProcess
65
-
66
- def handle_progress_info(percentage, speed, eta, estimated_filesize):
67
- print(f"Estimated Output Filesize: {estimated_filesize / 1_000_000} MB")
68
-
69
- def handle_success():
70
- # Code to run if the FFmpeg process completes successfully.
71
- pass
72
-
73
- def handle_error():
74
- # Code to run if the FFmpeg process encounters an error.
75
- pass
76
-
77
- # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
78
- process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
79
-
80
- ffmpeg_output_path = 'ffmpeg_output.txt'
81
-
82
- # Use the run method to run the FFmpeg command.
83
- process.run(progress_handler=handle_progress_info, ffmpeg_output_file=ffmpeg_output_path, success_handler=handle_success, error_handler=handle_error)
84
- ```
85
-
86
- The `run` method takes the following **optional** arguments:
87
-
88
- - `progress_handler`
89
-
90
- - You can create a function if you would like to do something with the following values:
91
-
92
- - Percentage progress. [float]
93
- - Speed, e.g. `22.3x` which means that 22.3 seconds of the input are processed every second. [string]
94
- - ETA in seconds. [float]
95
- - Estimated output filesize in bytes. [float]
96
- - _Note: This is not accurate. Please take the value with a grain of salt._
97
-
98
- The values will be `None` if unknown. The function will receive the aforementioned metrics as arguments, about two times per second.
99
-
100
- - `ffmpeg_output_file` - A string path to define where you want the output of FFmpeg to be saved. By default, this is saved in a folder named "ffmpeg_output", with the filename `[<input_filename>].txt`.
101
-
102
- - `success_handler` - A function to run if the FFmpeg process completes successfully.
103
-
104
- - `error_handler` - A function to run if the FFmpeg process encounters an error.
105
-
106
- ## Changelog:
107
-
108
- [19/09/2022]
109
-
110
- - Add the ability to specify a `success_handler` argument, a function to run if the FFmpeg process completes successfully.
111
- - Add 0.001 to tqdm's `total` parameter to prevent the chance of getting `TqdmWarning: clamping frac to range [0, 1]`
112
-
113
- [21/12/2022]
114
-
115
- - [v2.0.7] Fix `'estimated_size' referenced before assignment` error.
116
- - [v2.0.7] The progress bar now uses 1 decimal place for seconds processed and total duration.
117
-
118
- [22/12/2022]
119
-
120
- - [v2.0.8] Add the ability to specify an `error_handler` argument, a function to run if the FFmpeg process encounters an error.
121
- - [v2.0.9] Fix a typo (commit [da45a84](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/da45a8416856ab7d3c7b748db5703fa3dbc65f60))
122
-
123
- [07/02/2022]
124
-
125
- - [v2.1.0] [Update function name](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/572fe8a0d71957d00b833134a4d35170630203fa) to fix `'process_complete_handler' is not defined` error.
@@ -1,125 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: better-ffmpeg-progress
3
- Version: 2.1.1
4
- Summary: Run FFmpeg & see percentage progress + ETA.
5
- Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
- Author: GitHub.com/CrypticSignal
7
- Author-email: theaudiophile@outlook.com
8
- Keywords: ffmpeg,progress
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.6
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
-
16
- <div align="center">
17
-
18
- [![PyPI downloads](https://img.shields.io/pypi/dm/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
19
- [![PyPI downloads](https://img.shields.io/pypi/dw/better-ffmpeg-progress?label=PyPI&color=blue)](https://pypistats.org/packages/pypistats)
20
- [![GitHub](https://img.shields.io/github/license/crypticsignal/better-ffmpeg-progress?label=License&color=blue)](LICENSE.txt)
21
-
22
- # Better FFmpeg Progress
23
-
24
- Runs an FFmpeg command and uses [tqdm](https://github.com/tqdm/tqdm) to show a progress bar.
25
-
26
- </div>
27
-
28
- ## Example:
29
-
30
- ```
31
- 39%|███████████████████████████████████████████ | 23.6/60.2 [00:19<00:34, 1.07s/s]
32
- ```
33
-
34
- Where:
35
-
36
- - `39%` is the percentage progress.
37
- - `23.6` seconds of the input file have been processed.
38
- - `60.2` is the duration of the input file in seconds.
39
- - `00:19` is the time elapsed since the FFmpeg process started.
40
- - `00:34` is the estimated time required for the FFmpeg process to complete.
41
- - `1.07` shows how many seconds of the input file are processed per second.
42
-
43
- ## Installation:
44
-
45
- `pip3 install better-ffmpeg-progress --upgrade`
46
-
47
- ## Usage:
48
-
49
- Create an instance of the `FfmpegProcess` class and supply a list of arguments like you would to `subprocess.run()`.
50
-
51
- Simple Example:
52
-
53
- ```py
54
- from better_ffmpeg_progress import FfmpegProcess
55
- # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
56
- process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
57
- # Use the run method to run the FFmpeg command.
58
- process.run()
59
- ```
60
-
61
- Advanced Example:
62
-
63
- ```py
64
- from better_ffmpeg_progress import FfmpegProcess
65
-
66
- def handle_progress_info(percentage, speed, eta, estimated_filesize):
67
- print(f"Estimated Output Filesize: {estimated_filesize / 1_000_000} MB")
68
-
69
- def handle_success():
70
- # Code to run if the FFmpeg process completes successfully.
71
- pass
72
-
73
- def handle_error():
74
- # Code to run if the FFmpeg process encounters an error.
75
- pass
76
-
77
- # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
78
- process = FfmpegProcess(["ffmpeg", "-i", "input.mp4", "-c:a", "libmp3lame", "output.mp3"])
79
-
80
- ffmpeg_output_path = 'ffmpeg_output.txt'
81
-
82
- # Use the run method to run the FFmpeg command.
83
- process.run(progress_handler=handle_progress_info, ffmpeg_output_file=ffmpeg_output_path, success_handler=handle_success, error_handler=handle_error)
84
- ```
85
-
86
- The `run` method takes the following **optional** arguments:
87
-
88
- - `progress_handler`
89
-
90
- - You can create a function if you would like to do something with the following values:
91
-
92
- - Percentage progress. [float]
93
- - Speed, e.g. `22.3x` which means that 22.3 seconds of the input are processed every second. [string]
94
- - ETA in seconds. [float]
95
- - Estimated output filesize in bytes. [float]
96
- - _Note: This is not accurate. Please take the value with a grain of salt._
97
-
98
- The values will be `None` if unknown. The function will receive the aforementioned metrics as arguments, about two times per second.
99
-
100
- - `ffmpeg_output_file` - A string path to define where you want the output of FFmpeg to be saved. By default, this is saved in a folder named "ffmpeg_output", with the filename `[<input_filename>].txt`.
101
-
102
- - `success_handler` - A function to run if the FFmpeg process completes successfully.
103
-
104
- - `error_handler` - A function to run if the FFmpeg process encounters an error.
105
-
106
- ## Changelog:
107
-
108
- [19/09/2022]
109
-
110
- - Add the ability to specify a `success_handler` argument, a function to run if the FFmpeg process completes successfully.
111
- - Add 0.001 to tqdm's `total` parameter to prevent the chance of getting `TqdmWarning: clamping frac to range [0, 1]`
112
-
113
- [21/12/2022]
114
-
115
- - [v2.0.7] Fix `'estimated_size' referenced before assignment` error.
116
- - [v2.0.7] The progress bar now uses 1 decimal place for seconds processed and total duration.
117
-
118
- [22/12/2022]
119
-
120
- - [v2.0.8] Add the ability to specify an `error_handler` argument, a function to run if the FFmpeg process encounters an error.
121
- - [v2.0.9] Fix a typo (commit [da45a84](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/da45a8416856ab7d3c7b748db5703fa3dbc65f60))
122
-
123
- [07/02/2022]
124
-
125
- - [v2.1.0] [Update function name](https://github.com/CrypticSignal/better-ffmpeg-progress/commit/572fe8a0d71957d00b833134a4d35170630203fa) to fix `'process_complete_handler' is not defined` error.