Should Discourse convert GIFs to mp4 video files?

然后在每个下方放置以下通知:

:mega: 要使其全屏显示,请右键单击(或点住并按住)并在新标签页中打开。

如果我知道 Ruby,我会提交更正式的东西,可惜 Python 和 C 是我的主要语言。

我可能会编写一个定期运行的 Python 脚本,识别新帖子,识别新帖子中的 GIF,将它们放入转换文件夹,然后用新的 webm 文件的路径更新帖子。

我发现下面的配置非常适合转换。此脚本会将 ConvertToWebm 文件夹中的每个 gif 文件转换为 webm,同时保留原始 gif。对我们的用例来说,损失是可以接受的(小文本仍然可读),并且在某些情况下文件大小会减小多达 20 倍。

import glob, os
os.chdir("C:/Users/username/Videos/ConvertToWebm")
for file in glob.glob("*.gif"):
    print(file)
    filename = str(file[:-4])
    command = 'ffmpeg -i  "'+ str(file) +  '" -c vp9 -b:v 0 -crf 41 -strict experimental "' + filename + '.webm"'
    print(command)
    os.system(command)
4 个赞