当前位置:   article > 正文

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

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

完整源码

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

欢迎 star & fork ,哈哈~~


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

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/485743
推荐阅读
相关标签
  

闽ICP备14008679号