API Reference
FFmpeg
Bases: EventEmitter
Source code in ffmpeg/ffmpeg.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
__init__(executable='ffmpeg')
Initialize an FFmpeg
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
executable |
str
|
The path to the ffmpeg executable. Defaults to "ffmpeg". |
'ffmpeg'
|
Source code in ffmpeg/ffmpeg.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
arguments: list[str]
property
Return a list of arguments to be used when executing FFmpeg.
Returns:
Type | Description |
---|---|
list[str]
|
A lit of arguments to be used when executing FFmpeg. |
option(key, value=None)
Add a global option -key
or -key value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
A key of the global option |
required |
value |
Optional[Option]
|
A value of the global option. If the option does not require a value, use None. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Self
|
An instance of |
Source code in ffmpeg/ffmpeg.py
47 48 49 50 51 52 53 54 55 56 57 58 |
|
input(url, options=None, **kwargs)
Add an input file with specified options. By calling this method multiple times, an arbitrary number of input files can be added.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
Union[str, PathLike]
|
URL for the input file. |
required |
options |
Optional[dict[str, Optional[Option]]]
|
Options for the input file. Defaults to None. |
None
|
kwargs |
Optional[Option]
|
Additional options for the input file. |
{}
|
Note
Options for an input file can be specified in two ways:
Using options
:
ffmpeg = FFmpeg().input("input.mp4", {"codec:v": "libx264"}).output("output.mp4")
# Corresponds to `ffmpeg -codec:v libx264 -i input.mp4 output.mp4`
Using **kwargs
:
ffmpeg = FFmpeg().input("input.mp4", vcodec="libx264").output("output.mp4")
# Corresponds to `ffmpeg -vcodec libx264 -i input.mp4 output.mp4`
Note
If an option does not require a value, use None
for its value.
ffmpeg = FFmpeg().input("input.mp4", ignore_unknown=None).output("output.mp4")
# Corresponds to `ffmpeg -ignore_unknown -i input.mp4 output.mp4`
Returns:
Type | Description |
---|---|
Self
|
An instance of |
Source code in ffmpeg/ffmpeg.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
output(url, options=None, **kwargs)
Add an output file with specified options. By calling this method multiple times, an arbitrary number of output files can be specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
Union[str, PathLike]
|
URL for the output file. |
required |
options |
Optional[dict[str, Optional[Option]]]
|
Options for the output file. Defaults to None. |
None
|
kwargs |
Optional[Option]
|
Additional options for the output file. |
{}
|
Note
Options for an output file can be specified in two ways:
Using options
:
ffmpeg = FFmpeg().input("input.mp4").output("output.mp4", {"codec:v": "libx264"})
# Corresponds to `ffmpeg -i input.mp4 -codec:v libx264 output.mp4`
Using **kwargs
:
ffmpeg = FFmpeg().input("input.mp4").output("output.mp4", vcodec="libx264")
# Corresponds to `ffmpeg -i input.mp4 -vcodec libx264 output.mp4`
Note
If an option does not require a value, use None
for its value.
ffmpeg = FFmpeg().input("input.mp4").output("output.mp4", ignore_unknown=None)
# Corresponds to `ffmpeg -i input.mp4 -ignore_unknown output.mp4`
Returns:
Type | Description |
---|---|
Self
|
An instance of |
Source code in ffmpeg/ffmpeg.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
execute(stream=None, timeout=None)
Execute FFmpeg using specified global options and files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream |
Optional[Union[bytes, IO[bytes]]]
|
A stream to input to the standard input. Defaults to None. |
None
|
timeout |
Optional[float]
|
The maximum number of seconds to wait before returning. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
FFmpegAlreadyExecuted
|
If FFmpeg is already executed. |
FFmpegError
|
If FFmpeg process returns non-zero exit status. |
TimeoutExpired
|
If FFmpeg process does not terminate after |
Returns:
Type | Description |
---|---|
bytes
|
The output to the standard output. |
Source code in ffmpeg/ffmpeg.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
terminate()
Gracefully terminate the running FFmpeg process.
Raises:
Type | Description |
---|---|
FFmpegError
|
If FFmpeg is not executed |
Source code in ffmpeg/ffmpeg.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
ffmpeg.asyncio
FFmpeg
Bases: AsyncIOEventEmitter
Source code in ffmpeg/asyncio/ffmpeg.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
__init__(executable='ffmpeg')
Initialize an FFmpeg
instance using asyncio
Parameters:
Name | Type | Description | Default |
---|---|---|---|
executable |
str
|
The path to the ffmpeg executable. Defaults to "ffmpeg". |
'ffmpeg'
|
Source code in ffmpeg/asyncio/ffmpeg.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
arguments: list[str]
property
Return a list of arguments to be used when executing FFmpeg.
Returns:
Type | Description |
---|---|
list[str]
|
A lit of arguments to be used when executing FFmpeg. |
option(key, value=None)
Add a global option -key
or -key value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
A key of the global option |
required |
value |
Optional[Option]
|
A value of the global option. If the option does not require a value, use None. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Self
|
An instance of |
Source code in ffmpeg/asyncio/ffmpeg.py
50 51 52 53 54 55 56 57 58 59 60 61 |
|
input(url, options=None, **kwargs)
Add an input file with specified options. By calling this method multiple times, an arbitrary number of input files can be added.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
Union[str, PathLike]
|
URL for the input file. |
required |
options |
Optional[dict[str, Optional[Option]]]
|
Options for the input file. Defaults to None. |
None
|
kwargs |
Optional[Option]
|
Additional options for the input file. |
{}
|
Note
Options for an input file can be specified in two ways:
Using options
:
ffmpeg = FFmpeg().input("input.mp4", {"codec:v": "libx264"}).output("output.mp4")
# Corresponds to `ffmpeg -codec:v libx264 -i input.mp4 output.mp4`
Using **kwargs
:
ffmpeg = FFmpeg().input("input.mp4", vcodec="libx264").output("output.mp4")
# Corresponds to `ffmpeg -vcodec libx264 -i input.mp4 output.mp4`
Note
If an option does not require a value, use None
for its value.
ffmpeg = FFmpeg().input("input.mp4", ignore_unknown=None).output("output.mp4")
# Corresponds to `ffmpeg -ignore_unknown -i input.mp4 output.mp4`
Returns:
Type | Description |
---|---|
Self
|
An instance of |
Source code in ffmpeg/asyncio/ffmpeg.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
output(url, options=None, **kwargs)
Add an output file with specified options. By calling this method multiple times, an arbitrary number of output files can be specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
Union[str, PathLike]
|
URL for the output file. |
required |
options |
Optional[dict[str, Optional[Option]]]
|
Options for the output file. Defaults to None. |
None
|
kwargs |
Optional[Option]
|
Additional options for the output file. |
{}
|
Note
Options for an output file can be specified in two ways:
Using options
:
ffmpeg = FFmpeg().input("input.mp4").output("output.mp4", {"codec:v": "libx264"})
# Corresponds to `ffmpeg -i input.mp4 -codec:v libx264 output.mp4`
Using **kwargs
:
ffmpeg = FFmpeg().input("input.mp4").output("output.mp4", vcodec="libx264")
# Corresponds to `ffmpeg -i input.mp4 -vcodec libx264 output.mp4`
Note
If an option does not require a value, use None
for its value.
ffmpeg = FFmpeg().input("input.mp4").output("output.mp4", ignore_unknown=None)
# Corresponds to `ffmpeg -i input.mp4 -ignore_unknown output.mp4`
Returns:
Type | Description |
---|---|
Self
|
An instance of |
Source code in ffmpeg/asyncio/ffmpeg.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
execute(stream=None, timeout=None)
async
Execute FFmpeg using specified global options and files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream |
Optional[Union[bytes, StreamReader]]
|
A stream to input to the standard input. Defaults to None. |
None
|
timeout |
Optional[float]
|
The maximum number of seconds to wait before returning. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
FFmpegAlreadyExecuted
|
If FFmpeg is already executed. |
FFmpegError
|
If FFmpeg process returns non-zero exit status. |
TimeoutError
|
If FFmpeg process does not terminate after |
Returns:
Type | Description |
---|---|
bytes
|
The output to the standard output. |
Source code in ffmpeg/asyncio/ffmpeg.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
terminate()
Gracefully terminate the running FFmpeg process.
Raises:
Type | Description |
---|---|
FFmpegError
|
If FFmpeg is not executed |
Source code in ffmpeg/asyncio/ffmpeg.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
Progress
dataclass
Represents a progress of FFmpeg
operation.
Attributes:
Name | Type | Description |
---|---|---|
frame |
int
|
The number of processed frames. |
fps |
float
|
The processing speed in frame per seconds. |
size |
int
|
The current size of the media in bytes. |
time |
timedelta
|
The current time of the media. |
bitrate |
float
|
The processing speed in kilobits per second. |
speed |
float
|
The processing speed |
Source code in ffmpeg/progress.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Exceptions
FFmpegError
Bases: Exception
Represents an error that has occurred during FFmpeg
operation.
Attributes:
Name | Type | Description |
---|---|---|
message |
An error message providing details about the error. |
|
arguments |
Arguments passed to FFmpeg. |
Source code in ffmpeg/errors.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
FFmpegAlreadyExecuted
Bases: FFmpegError
Represents FFmpeg is being executed
Source code in ffmpeg/errors.py
38 39 |
|
FFmpegFileNotFound
Bases: FFmpegError
Represents an input file was not found
Source code in ffmpeg/errors.py
42 43 44 45 46 47 |
|
FFmpegInvalidCommand
Bases: FFmpegError
Represents FFmpeg was passed invalid options or arguments
Source code in ffmpeg/errors.py
50 51 52 53 54 55 56 57 58 |
|
FFmpegUnsupportedCodec
Bases: FFmpegError
Represents FFmpeg attempted to use an unsupported codec
Source code in ffmpeg/errors.py
61 62 63 64 65 66 67 68 |
|
Events
start
This event is emitted just before FFmpeg
is executed.
Parameters:
Name | Type | Description |
---|---|---|
arguments |
list[str] |
A list of arguments to execute FFmpeg |
stderr
This event is emitted when a line is output to the standard error by FFmpeg
.
Parameters:
Name | Type | Description |
---|---|---|
line |
str |
A line from the standard error |
progress
This event is emitted when FFmpeg
reports progress.
Parameters:
Name | Type | Description |
---|---|---|
progress |
Progress |
A progress of FFmpeg operation |
completed
This event is emitted when FFmpeg
is successfully exited.
terminated
This event is emitted when FFmpeg
is gracefully terminated by calling FFmpeg.terminate()
.