New paste Repaste Download
def compress(src, fmt="png"):
fmt = fmt or "png"
cmd = {
"bmp": [ "ffmpeg", "-i", "pipe:0", "-f", "image2", "-codec:v",   "bmp", "pipe:1" ],
"tga": [ "ffmpeg", "-i", "pipe:0", "-f", "image2", "-codec:v", "targa", "pipe:1" ],
"png": [ "ffmpeg", "-i", "pipe:0", "-f", "image2", "-codec:v",   "png", "-compression_level", "9", "-pred", "mixed", "pipe:1" ],
"jpg": [ "ffmpeg", "-i", "pipe:0", "-f", "image2", "-codec:v", "mjpeg", "-global_quality", "75", "pipe:1" ]
}
cmd = cmd[fmt] if fmt in cmd else cmd["png"]
try:
proc = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=PIPE)
res = proc.communicate(input = src)
out = res[0] ; err = res[1] ; msg = err.decode("ascii")
if proc.returncode != 0:
raise Exception(f"ffmpeg: {msg}")
except Exception as e:
out = src
print(f"Error: {str(e)}")
# raise e
return out
Filename: None. Size: 891b. View raw, , hex, or download this file.

This paste expires on 2025-02-22 23:46:56.359526. Pasted through web.