Spaces:
Running
Running
File size: 8,273 Bytes
6b6d66f |
1 2 3 4 5 6 7 8 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 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 |
"""Module to change the configuration of FFmpeg libraries (such as libavformat).
It affects functionalities in :py:mod:`torio.io`.
"""
from typing import Dict, List, Tuple
import torio
ffmpeg_ext = torio._extension.lazy_import_ffmpeg_ext()
def get_versions() -> Dict[str, Tuple[int]]:
"""Get the versions of FFmpeg libraries
Returns:
dict: mapping from library names to version string,
i.e. `"libavutil": (56, 22, 100)`.
"""
return ffmpeg_ext.get_versions()
def get_log_level() -> int:
"""Get the log level of FFmpeg.
See :py:func:`set_log_level` for the detail.
"""
return ffmpeg_ext.get_log_level()
def set_log_level(level: int):
"""Set the log level of FFmpeg (libavformat etc)
Arguments:
level (int): Log level. The larger, the more verbose.
The following values are common values, the corresponding ``ffmpeg``'s
``-loglevel`` option value and desription.
* ``-8`` (``quiet``):
Print no output.
* ``0`` (``panic``):
Something went really wrong and we will crash now.
* ``8`` (``fatal``):
Something went wrong and recovery is not possible.
For example, no header was found for a format which depends
on headers or an illegal combination of parameters is used.
* ``16`` (``error``):
Something went wrong and cannot losslessly be recovered.
However, not all future data is affected.
* ``24`` (``warning``):
Something somehow does not look correct.
This may or may not lead to problems.
* ``32`` (``info``):
Standard information.
* ``40`` (``verbose``):
Detailed information.
* ``48`` (``debug``):
Stuff which is only useful for libav* developers.
* ``56`` (``trace``):
Extremely verbose debugging, useful for libav* development.
"""
ffmpeg_ext.set_log_level(level)
def get_demuxers() -> Dict[str, str]:
"""Get the available demuxers.
Returns:
Dict[str, str]: Mapping from demuxer (format) short name to long name.
Example
>>> for k, v in get_demuxers().items():
>>> print(f"{k}: {v}")
... aa: Audible AA format files
... aac: raw ADTS AAC (Advanced Audio Coding)
... aax: CRI AAX
... ac3: raw AC-3
"""
return ffmpeg_ext.get_demuxers()
def get_muxers() -> Dict[str, str]:
"""Get the available muxers.
Returns:
Dict[str, str]: Mapping from muxer (format) short name to long name.
Example
>>> for k, v in get_muxers().items():
>>> print(f"{k}: {v}")
... a64: a64 - video for Commodore 64
... ac3: raw AC-3
... adts: ADTS AAC (Advanced Audio Coding)
... adx: CRI ADX
... aiff: Audio IFF
"""
return ffmpeg_ext.get_muxers()
def get_audio_decoders() -> Dict[str, str]:
"""Get the available audio decoders.
Returns:
Dict[str, str]: Mapping from decoder short name to long name.
Example
>>> for k, v in get_audio_decoders().items():
>>> print(f"{k}: {v}")
... a64: a64 - video for Commodore 64
... ac3: raw AC-3
... adts: ADTS AAC (Advanced Audio Coding)
... adx: CRI ADX
... aiff: Audio IFF
"""
return ffmpeg_ext.get_audio_decoders()
def get_audio_encoders() -> Dict[str, str]:
"""Get the available audio encoders.
Returns:
Dict[str, str]: Mapping from encoder short name to long name.
Example
>>> for k, v in get_audio_encoders().items():
>>> print(f"{k}: {v}")
... comfortnoise: RFC 3389 comfort noise generator
... s302m: SMPTE 302M
... aac: AAC (Advanced Audio Coding)
... ac3: ATSC A/52A (AC-3)
... ac3_fixed: ATSC A/52A (AC-3)
... alac: ALAC (Apple Lossless Audio Codec)
"""
return ffmpeg_ext.get_audio_encoders()
def get_video_decoders() -> Dict[str, str]:
"""Get the available video decoders.
Returns:
Dict[str, str]: Mapping from decoder short name to long name.
Example
>>> for k, v in get_video_decoders().items():
>>> print(f"{k}: {v}")
... aasc: Autodesk RLE
... aic: Apple Intermediate Codec
... alias_pix: Alias/Wavefront PIX image
... agm: Amuse Graphics Movie
... amv: AMV Video
... anm: Deluxe Paint Animation
"""
return ffmpeg_ext.get_video_decoders()
def get_video_encoders() -> Dict[str, str]:
"""Get the available video encoders.
Returns:
Dict[str, str]: Mapping from encoder short name to long name.
Example
>>> for k, v in get_audio_encoders().items():
>>> print(f"{k}: {v}")
... a64multi: Multicolor charset for Commodore 64
... a64multi5: Multicolor charset for Commodore 64, extended with 5th color (colram)
... alias_pix: Alias/Wavefront PIX image
... amv: AMV Video
... apng: APNG (Animated Portable Network Graphics) image
... asv1: ASUS V1
... asv2: ASUS V2
"""
return ffmpeg_ext.get_video_encoders()
def get_input_devices() -> Dict[str, str]:
"""Get the available input devices.
Returns:
Dict[str, str]: Mapping from device short name to long name.
Example
>>> for k, v in get_input_devices().items():
>>> print(f"{k}: {v}")
... avfoundation: AVFoundation input device
... lavfi: Libavfilter virtual input device
"""
return ffmpeg_ext.get_input_devices()
def get_output_devices() -> Dict[str, str]:
"""Get the available output devices.
Returns:
Dict[str, str]: Mapping from device short name to long name.
Example
>>> for k, v in get_output_devices().items():
>>> print(f"{k}: {v}")
... audiotoolbox: AudioToolbox output device
"""
return ffmpeg_ext.get_output_devices()
def get_input_protocols() -> List[str]:
"""Get the supported input protocols.
Returns:
List[str]: The names of supported input protocols
Example
>>> print(get_input_protocols())
... ['file', 'ftp', 'hls', 'http','https', 'pipe', 'rtmp', 'tcp', 'tls', 'udp', 'unix']
"""
return ffmpeg_ext.get_input_protocols()
def get_output_protocols() -> List[str]:
"""Get the supported output protocols.
Returns:
list of str: The names of supported output protocols
Example
>>> print(get_output_protocols())
... ['file', 'ftp', 'http', 'https', 'md5', 'pipe', 'prompeg', 'rtmp', 'tee', 'tcp', 'tls', 'udp', 'unix']
"""
return ffmpeg_ext.get_output_protocols()
def get_build_config() -> str:
"""Get the FFmpeg build configuration
Returns:
str: Build configuration string.
Example
>>> print(get_build_config())
--prefix=/Users/runner/miniforge3 --cc=arm64-apple-darwin20.0.0-clang --enable-gpl --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-neon --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-libvpx --enable-pic --enable-pthreads --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libmp3lame --pkg-config=/Users/runner/miniforge3/conda-bld/ffmpeg_1646229390493/_build_env/bin/pkg-config --enable-cross-compile --arch=arm64 --target-os=darwin --cross-prefix=arm64-apple-darwin20.0.0- --host-cc=/Users/runner/miniforge3/conda-bld/ffmpeg_1646229390493/_build_env/bin/x86_64-apple-darwin13.4.0-clang # noqa
"""
return ffmpeg_ext.get_build_config()
def clear_cuda_context_cache():
"""Clear the CUDA context used by CUDA Hardware accelerated video decoding"""
ffmpeg_ext.clear_cuda_context_cache()
|