Sorry,有钱真的可以为所欲为 ~

sorry,有钱真的可以为所欲为 ~

源起

sorry是一款很有意思的应用,源自于sorry,有钱真的可以为所欲为这个梗。
亮点是可以换自己的梗生成gif。
可惜部署环境是ubuntu+ruby,我就重制了个全平台的python重置版sorrypy(
Github & 码云)博大家一笑。
荣誉首先属于xtyxtyx

Hardy兄弟NodeJs版:node-sorry也非常好用,有DEMO为证,嘎嘎。

sorry 原版网站 生成的样例:

大

python版关键点

1. jinja2模板渲染自定义ass

def render_ass(template_name, sentences, filename):
    output_file_path = "static/cache/%s.ass" % filename
    template = ass_text(template_name)
    rendered_ass_text = Template(template).render(sentences=sentences)
    with open(output_file_path, "w", encoding="utf8") as fp:
        fp.write(rendered_ass_text)
    return output_file_path

2. ffmpeg根据MP4和ass生成gif

def make_gif_with_ffmpeg(template_name, sentences, filename):
    ass_path = render_ass(template_name, sentences, filename)
    gif_path = "static/cache/" + filename
    video_path = "static/" + template_name + "/template.mp4"
    print(ass_path, gif_path, video_path)
    cmd = "ffmpeg -i {video_path} -r 8 -vf ass={ass_path},scale=300:-1 -y {gif_path}" \
        .format(video_path=video_path, ass_path=ass_path, gif_path=gif_path)
    print(cmd)
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    p.wait()
    if p.returncode != 0:
        print("Error.")
    return -1

完整源码

Ruby原版:sorry Github
Python版:sorrypy Github & 码云

欢迎 star & fork ,哈哈~~


版权声明:转载必须注明本文转自 East196 的博客:http://blog.csdn.net/east196

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI原吾

你的鼓励是我创作最大的动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值