Documentation
Audio
- mediaify.encode_audio(data: bytes, config: AudioEncodingType | None = None) AudioFile
Encodes an image using an audio config
- Returns:
The encoded image
- Return type:
ImageFile
- Raises:
ValueError – Image is too big to process
ValueError – Could not Load Image
- mediaify.batch_encode_audio(data: bytes, configs: List[AudioEncodingType]) List[AudioFile]
Encodes an image using a list of audio configs, more efficent than calling encode_audio multiple times
- Returns:
List of encoded audio files, guarenteed to be in the same order as the configs
- Return type:
List[AudioFile]
- Raises:
ValueError – Could Not Encode Audio
- class mediaify.AudioFile(data: bytes, mimetype: str)
- data: bytes
The file’s raw data, can be used to save to a file
- mimetype: str
The file’s mimetype E.g. ‘image/png’
- type: typing_extensions.Literal[audio, image, animation, video] = 'audio'
The media type, one of ‘image’, ‘animation’, ‘video’
- save(filepath: str) None
Saves the file to the given path
Image
- mediaify.encode_image(data: bytes, config: ImageEncodingType | None = None) ImageFile
Encodes an image using an image config
- Returns:
The encoded image
- Return type:
ImageFile
- Raises:
ValueError – Image is too big to process
ValueError – Could not Load Image
- mediaify.batch_encode_image(data: bytes, configs: List[ImageFormat | UnencodedEncoding | ThumbnailEncoding]) List[ImageFile]
Encodes an image using a list of image configs, more efficent than calling encode_image multiple times
- Returns:
List of encoded images, guarenteed to be in the same order as the configs
- Return type:
List[ImageFile]
- Raises:
ValueError – Image is too big to process
ValueError – Could not Load Image
- class mediaify.ImageFile(data: bytes, mimetype: str, height: int, width: int)
- data: bytes
The file’s raw data, can be used to save to a file
- mimetype: str
The file’s mimetype E.g. ‘image/png’
- height: int
- width: int
- property ext: str
The file extention for this file including the ‘.’. If the mimetype is unknown, ‘.bin’ is returned
- save(filepath: str) None
Saves the file to the given path
Animation
- mediaify.encode_animation(data: bytes, config: ThumbnailEncoding) ImageFile
- mediaify.encode_animation(data: bytes, config: AnimationFormat | UnencodedEncoding | None = None) AnimationFile
Encodes an animation using an animation config
- Returns:
The encoded output
- Return type:
AnimationFile|ImageFile
- Raises:
ValueError – Animation was too large
ValueError – Could not Load Animation
- mediaify.batch_encode_animation(data: bytes, configs: List[AnimationEncodingType]) List[AnimationFile | ImageFile]
Encodes an animation using a list of animation configs, more efficent than calling encode_animation multiple times
- Returns:
List of encoded output, guarenteed to be in the same order as the configs
- Return type:
List[AnimationFile|ImageFile]
- Raises:
ValueError – Animation is too big to process
ValueError – Could not Load Image
- class mediaify.AnimationFile(data: bytes, mimetype: str, height: int, width: int, frame_count: int, duration: float)
- data: bytes
The file’s raw data, can be used to save to a file
- mimetype: str
The file’s mimetype E.g. ‘image/png’
- height: int
- width: int
- frame_count: int
The number of frames in the animation
- duration: float
The duration of the animation in seconds
- property ext: str
The file extention for this file including the ‘.’. If the mimetype is unknown, ‘.bin’ is returned
- save(filepath: str) None
Saves the file to the given path
Video
- mediaify.encode_video(data: bytes, config: ThumbnailEncoding) ImageFile
- mediaify.encode_video(data: bytes, config: VideoPreviewAnimationEncoding) AnimationFile
- mediaify.encode_video(data: bytes, config: VideoFormat | UnencodedEncoding | None = None) VideoFile
Encodes a video using a video config
- Returns:
The encoded output
- Return type:
VideoFile|AnimationFile|ImageFile
- Raises:
ValueError – Video could not be encoded
- mediaify.batch_encode_video(data: bytes, configs: List[VideoEncodingType]) List[VideoFile | AnimationFile | ImageFile]
Encodes a video using a list of video configs, more efficent than calling encode_video multiple times
- Returns:
List of encoded output, guarenteed to be in the same order as the configs
- Return type:
List[VideoFile|AnimationFile|ImageFile]
- Raises:
ValueError – Video could not be encoded
- class mediaify.VideoFile(data: bytes, mimetype: str, height: int, width: int, duration: float, framerate: float, hasAudio: bool)
- data: bytes
The file’s raw data, can be used to save to a file
- mimetype: str
The file’s mimetype E.g. ‘image/png’
- height: int
- width: int
- duration: float
The duration of the video in seconds
- property ext: str
The file extention for this file including the ‘.’. If the mimetype is unknown, ‘.bin’ is returned
- save(filepath: str) None
Saves the file to the given path
- framerate: float
The framerate of the video in fps
- hasAudio: bool
Does this video contain audio?
Utils
- mediaify.guess_type(data: bytes) Literal['audio', 'image', 'video', 'animation']
Guesses the type of the file from it’s data
- Returns:
“audio” | “image” | “animaton” | “video”
- Raises:
ValueError – Filetype not supported
Configs
Audio Configs
- class mediaify.MP3Format(quality: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] = 6)
Encode as an .mp3 audio file
- quality: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] = 6
The quality preset to use for libmp3lame for average bitrate. 9 is the worst quality, 0 is the best quality. https://trac.ffmpeg.org/wiki/Encode/MP3#VBREncoding
- class mediaify.OpusFormat(bitrate: int = 128000)
Encode as a .opus audio file
- bitrate: int = 128000
The bitrate to encode the audio in bits per second, defaults to 128kbps
- class mediaify.FLACFormat
Encode as a .flac audio file
- class mediaify.WAVFormat
Encode as a .wav audio file
Image Configs
- class mediaify.WEBPImageFormat(resize: ResizeConfig | None = None, quality: int = 85, lossless: bool = False)
Encode as a .webp image
- resize: ResizeConfig | None = None
How to resize the image, None to disable resizing. Defaults to None.
- quality: int = 85
The webp quality
- lossless: bool = False
Should the image be lossless?
- class mediaify.JPEGFormat(resize: ResizeConfig | None = None, quality: int = 85, progressive: bool = True)
Encode as a .jpg image
- resize: ResizeConfig | None = None
How to resize the image, None to disable resizing. Defaults to None.
- quality: int = 85
The JPEG quality option
- progressive: bool = True
Encode in a way that allows it to be displayed in low quality before it is fully downloaded.
Animation Configs
- class mediaify.GIFFormat(resize: ResizeConfig | None = None)
Encode as a .gif animation
- resize: ResizeConfig | None = None
How to resize the animation, None to disable resizing. Defaults to None.
- class mediaify.WEBPAnimationFormat(resize: ResizeConfig | None = None, quality: int = 85, lossless: bool = False)
Encode as a .webp animation
- resize: ResizeConfig | None = None
How to resize the animation, None to disable resizing. Defaults to None.
- quality: int = 85
The webp quality
- lossless: bool = False
Should the image be lossless?
Video Configs
- class mediaify.WEBMFormat(resize: ResizeConfig | None = None, framerate: float|None = None, video_codec: VP9Codec|AV1Codec = <factory>, audio_codec: OpusCodec|None = <factory>)
Encode as a .webm video
- resize: ResizeConfig | None = None
How to resize the video, None to disable resizing. Defaults to None.
- framerate: float | None = None
The framerate to encode the video at, None to use the original framerate. Defaults to None.
- class mediaify.MP4Format(resize: ResizeConfig | None = None, framerate: float|None = None, video_codec: H264Codec|AV1Codec = <factory>, audio_codec: OpusCodec|None = <factory>)
Encode as a .mp4 video
- resize: ResizeConfig | None = None
How to resize the video, None to disable resizing. Defaults to None.
- framerate: float | None = None
The framerate to encode the video at, None to use the original framerate. Defaults to None.
- class mediaify.VideoPreviewAnimationEncoding(encoding: AnimationFormat | None = None, framerate: float = 15, frames: int = 45)
Encode a video as a short animation, useful for previews.
- encoding: AnimationFormat | None = None
- framerate: float = 15
What FPS should the output animation be
- frames: int = 45
How many frames to generate
Codecs
- class mediaify.H264Codec(crf: int = 21, preset: Literal['ultrafast', 'superfast', 'veryfast', 'faster', 'fast', 'medium', 'slow', 'slower', 'veryslow', 'placebo'] = 'fast')
The H264 video codec
- crf: int = 21
Constant Rate Factor. Lower is better quality, but larger file size.
0 is worst quality and 51 is best quality
- preset: Literal['ultrafast', 'superfast', 'veryfast', 'faster', 'fast', 'medium', 'slow', 'slower', 'veryslow', 'placebo'] = 'fast'
The speed to encode the video at, slower means lower filesize at same quality.
- From fastest to slowest:
ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
- class mediaify.VP9Codec(crf: int = 21, preset: Literal['good', 'best', 'realtime'] = 'good')
The VP9 video codec
- crf: int = 21
Constant Rate Factor. Lower is better quality, but larger file size.
0 is best quality and 63 is worst quality
- preset: Literal['good', 'best', 'realtime'] = 'good'
The speed to encode the video at, slower means lower filesize at same quality.
realtime is the fastest, worst quality
good is the default, a mix of speed and file size, default
best is the slowest, smallest file size
- class mediaify.AV1Codec(crf: int = 50, preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8] = 5)
The AV1 video codec
- crf: int = 50
Constant Rate Factor. Lower is better quality, but larger file size.
0 is best quality and 63 is worst quality
- preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8] = 5
- The speed to encode the video at,
slower means lower filesize at same quality.
0 is the slowest, best quality. 8 is the fastest, worst quality.
Resize Configs
- class mediaify.MaxResolutionResize(max_width: 'int | None' = None, max_height: 'int | None' = None)
- max_width: int | None = None
With maximum width before downscaling
- max_height: int | None = None
With maximum height before downscaling
- class mediaify.TargetResolutionResize(width: 'int | None' = None, height: 'int | None' = None, method: "Literal['stretch']" = 'stretch')
- width: int | None = None
The width to resize to
- height: int | None = None
The height to resize to
- method: Literal['stretch'] = 'stretch'
How to change the video aspect ratio, defaults to stretch