Closed laggykiller closed 1 year ago
Added function for quickly handling static images, as well as allowing different size limit for static and animated file (Useful for WhatsApp sticker making) (Default size limit is unchanged)
Hey thanks a lot, give me some time to review it, I have been trying to solve this issue!!!
@laggykiller This looks promising, I just don't wanna make it into ./script_v3 , could you copy all your changes to ./script_v4 folder, I know this might sound stupid but i like to do versioning like this, this makes it easy for me to compare if something goes wrong in future. I hope you wouldn't mind
Bumped to v4 and changed README
Thanks a lot, I will review it in next 2 days. This looks like great work. Although am not quite sure but all video stickers of telegrams are vp9 codec, Right?
Although am not quite sure but all video stickers of telegrams are vp9 codec, Right?
webm also supports AV1 codec as shown here: https://en.wikipedia.org/wiki/WebM
However, according to here: https://core.telegram.org/stickers/webm-vp9-encoding
Video must be encoded with the VP9 codec.
Is there any way we can implement transparency instead of changing it to color black? https://t.me/addstickers/Minecraft
Seems like specifying decoder libvpx-vp9
for webm file input is needed to achieve this
ffmpeg -y -c:v libvpx-vp9 -i .\in.webm -r 30 -loop 0 .\out.apng
This pull request will make change to the script_v3 but not the rust program.
Support for webm and webp stickers
Not all telegram stickers are in tgs format. Take a look at this webm example and webp example. This pull request will add support to those formats.
Support for non-square stickers
Not all telegram stickers are downloaded as square. Examples could be found in the webm example given up there. The solution is to pad original video with transparent space using ffmpeg:
ffmpeg -r $_FPS -i "$thedir/frame/%d.png" -vcodec apng -pix_fmt rgba -vf "scale=$RES:-1:flags=neighbor:sws_dither=none" -vf "scale=$RES:$RES:force_original_aspect_ratio=decrease,pad=$RES:$RES:(ow-iw)/2:(oh-ih)/2:color=black@0,setsar=1" -r $GFRAMES -plays 0 "$thedir/output.apng" &>/dev/null
Fix bug which cause pngquant to fail
Example using webm example 10th sticker (output_strip.1.png can be downloaded here)
Using
--quality 0-85
solved the problemBetter zero-padding with the file name
It is not safe to assume there is only 10 frames in a sticker. Moreover this does not work if there is only 1 frame, and throws errors if there is no exactly 10 frames. To make it more robust, the code is changed to
Better handling of static stickers
If the sticker is static, then only $thedir/final/this.png exists An explicit check (
if [[ ! -f $thedir/final/this.png ]]
) is added so that it will not fail to handle static stickersAllow lower res and fps
For example, the 25th sticker of the webm example given above is too chaotic that the resolution needs to be further down Hence, res 200 is added and minimum fps could go down to 3 (
if [[ $GFRAMES -gt "3" ]]
)Bug fix in core-hybrid shouldwait
On line
shouldwait=$(python -c "print($f%5)")
,$f
should be$ff
Python open file using with
Files should be closed using
f.close()
. Usingwith open()
ensuresf
still get closed if exception occurs. For more info, read this: https://stackoverflow.com/questions/2738365/whats-the-advantage-of-using-with-as-statement-in-pythonCode identation cleanup
The original code identation is quite messy, which this pull request will also fix