ASCIIPlayer : Golang写的ASCII码播放器

栏目: Go · 发布时间: 7年前

内容简介:先上一个效果图

ASCIIPlayer : Golang写的ASCII码播放器

ASCIIPlayer 是一个基于 Image2ASCII 的ASCII码播放器,可以播放图片,gif动图,视屏(还在开发中)等,提供了类库和命令行 工具 方便使用。

先上一个效果图

ASCIIPlayer : Golang写的ASCII码播放器

特性

  • 支持在终端中播放一般的图片,比如PNG,JPEG,也支持播放GIF动图和视屏。
  • 支持将一个图片,PNG,JPEG类型和GIF动图和视屏直接编码成为一个ASCII码图片。
  • 支持搭建一个Http Server来分享ASCII图片到远程的一个客户端。

工作原理

  1. 首先将任何一个输入的文件通过解码器解码成个一个帧序列,不同的文件有不同的解码器,比如GIF文件有GifDecoder
  2. 然后将解码出来的帧序列通过Image2ASCII转换器转换成ASCII码图片
  3. 然后将转换以后的ASCII图片输出到不同的IO中去,其中包括:

    • 输出到一个一般文件中(Encode模式) : 这里我们只能逐帧,逐像素的将转化以后的ASCII图像写到文件中去。
    • 输出到终端(Play模式) : 直接将转换以后的图像按照一定的频率输出到终端即可。
    • 输出到远端客户端(Server模式) : 这里和输出到终端的原理类似,只是输出到了远端客户端所在的终端。
+---------------+                                                  +---------+
                 |               |                                                  |         |
          +------> Gif Decoder   |                                              +---> Encoder +---> file
          |      |               |                                              |   |         |
          |      +---------------+                                              |   +---------+
          |      +---------------+                +-------------+               |   +---------+
          |      |               |                |             |               |   |         |
Input File+------> Image Decoder +---> Frames +-->+ Image2ASCII +->ASCII Frames-+---> Player  +---> stdout
          |      |               |                |             |               |   |         |
          |      +---------------+                +-------------+               |   +---------+
          |      +---------------+                                              |   +---------+
          |      |               |                                              |   |         |
          +------> Video Decoder |                                              +---> Server  +---> socket
                 |               |                                                  |         |
                 +---------------+                                                  +---------+

安装

go get -u github.com/qeesung/asciiplayer

命令行使用

_    ____   ____ ___ ___ ____  _        _ __   _______ ____
   / \  / ___| / ___|_ _|_ _|  _ \| |      / \\ \ / / ____|  _ \
  / _ \ \___ \| |    | | | || |_) | |     / _ \\ V /|  _| | |_) |
 / ___ \ ___) | |___ | | | ||  __/| |___ / ___ \| | | |___|  _ <
/_/   \_\____/ \____|___|___|_|   |_____/_/   \_\_| |_____|_| \_\
>>>Version  : 1.0.0
>>>Author   : qeesung
>>>HomePage : https://github.com/qeesung/asciiplayer

asciiplayer is a library that can convert gif and video to ASCII image
and provide the cli for easy use.

Usage:
  asciiplayer [command]

Available Commands:
  encode      Encode gif or video to ascii gif or video
  help        Help about any command
  play        Play the gif and video in ASCII mode
  server      Server command setup a http share server
  version     Show the version

Flags:
  -D, --debug   Switch log level to DEBUG mode
  -h, --help    help for asciiplayer

Use "asciiplayer [command] --help" for more information about a command.

播放命令 play

播放命令直接在终端中播放对应的媒体,比如PNG和GIF图片。

可以通过 asciiplayer play -h 来获得更多细节

ASCIIPlayer : Golang写的ASCII码播放器

Play 例子

通过适配屏幕的方式播放GIF

asciiplayer play demo.gif

缩小为原来的十分之一,然后播放GIF

asciiplayer play demo.gif -r 0.1

缩放成固定的长和宽,然后播放GIF

asciiplayer play demo.gif -w 100 -h 40

播放一个PNG图片

asciiplayer play demo.png

编码命令 encode

编码命令可以将一个PNG图片或者是GIF动图,视屏文件转化成一个ASCII的文件

可以运行 asciiplayer encode -h 来获得更多细节

ASCIIPlayer : Golang写的ASCII码播放器

输入文件eye.gif

ASCIIPlayer : Golang写的ASCII码播放器

输出文件ascii_eye.gif

ASCIIPlayer : Golang写的ASCII码播放器

Encode 例子

讲一个GIF文件demo.gif编码为ASCII的Gif文件output.gif

asciiplayer encode demo.gif -o output.gif

指定输出ASCII字符大小的情况下,讲一个GIF文件demo.gif编码成ASCII的GIF动图文件output.gif

asciiplayer encode demo.gif -o output.gif --font_size=5

将GIF动图demo.gif缩放为原来的十分之一,然后编码成ASCII的GIF动图文件output.gif

asciiplayer encode demo.gif -o output.gif -r 0.1

编码一个jpeg文件,然后输出一个ASCII的output.png文件

asciiplayer encode demo.jpeg -o output.png

服务命令 server

可以搭建一个Http Server,然后将转换以后的图片分享到远端的客户端。

搭建服务

$ asciiplayer server demo.gif
# Server available on : http://0.0.0.0:8080

远端访问

$ curl http://hostname:8080
# play ascii image here

可以通过运行命令 asciiplayer server --help 来获得更多细节

ASCIIPlayer : Golang写的ASCII码播放器

Server 例子

输入demo.gif,并以默认端口8080启动一个http服务器

asciiplayer server demo.gif

输入demo.gif,并以自定义端口8888启动一个http服务器

asciiplayer server demo.gif --port 8888

输入一个demo.png图片,并且启动http 服务器

asciiplayer server demo.png

一些例子

Raw Image ASCII Image
ASCIIPlayer : Golang写的ASCII码播放器 ASCIIPlayer : Golang写的ASCII码播放器
ASCIIPlayer : Golang写的ASCII码播放器 ASCIIPlayer : Golang写的ASCII码播放器
ASCIIPlayer : Golang写的ASCII码播放器 ASCIIPlayer : Golang写的ASCII码播放器
ASCIIPlayer : Golang写的ASCII码播放器 ASCIIPlayer : Golang写的ASCII码播放器
ASCIIPlayer : Golang写的ASCII码播放器 ASCIIPlayer : Golang写的ASCII码播放器

以上所述就是小编给大家介绍的《ASCIIPlayer : Golang写的ASCII码播放器》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Designing Data-Intensive Applications

Designing Data-Intensive Applications

Martin Kleppmann / O'Reilly Media / 2017-4-2 / USD 44.99

Data is at the center of many challenges in system design today. Difficult issues need to be figured out, such as scalability, consistency, reliability, efficiency, and maintainability. In addition, w......一起来看看 《Designing Data-Intensive Applications》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具