The current algorithm for uploading GIFs is the following:
Note: it's possible to encode MP4.H264 with a known size beforehand using two-pass algorithm of ffmpeg (docs).
Optimistically forward the image using .mp4 representation to telegram directly. Why optimistically? It's because we don't know the actual size of the .mp4 file beforehand. It's not mentioned in derpibooru API, and even if it would, derpibooru's API is still not very precise, it may report wrong file sizes. So we hope the GIF's MP4 representation is under 20MB.
If the prev. step fails, try downloading the .mp4 representation
If mp4 is available:
If the file is <= 50MB, then upload it to telegram directly
If the file is > 50MB, then compress it better so it fits into 50MB limit using two-pass (not implemented)
If mp4 is not available, then download the .webm representation and convert it to mp4 ffmpeg under 50MB using two-pass (not implemented)
TODO: also take care about aspect ratio and resolution limits
The current algorithm for uploading GIFs is the following:
Optimistically forward the image using
.mp4
representation to telegram directly. Why optimistically? It's because we don't know the actual size of the.mp4
file beforehand. It's not mentioned in derpibooru API, and even if it would, derpibooru's API is still not very precise, it may report wrong file sizes. So we hope the GIF's MP4 representation is under 20MB.If the prev. step fails, try downloading the
.mp4
representation<= 50MB
, then upload it to telegram directly> 50MB
, then compress it better so it fits into 50MB limit using two-pass (not implemented).webm
representation and convert it to mp4 ffmpeg under 50MB using two-pass (not implemented)TODO: also take care about aspect ratio and resolution limits