video-to-ascii:在命令行中看视频

最近GitHub上有个很好玩的项目,叫做video-to-ascii。这是一个简单的python包,可以使用字符作为像素在终端中播放视频。

安装:

pip3 install video-to-ascii

用法:

$ video-to-ascii -f myvideo.mp4

--strategy 可以通过增加参数选择不同的模式

-o --output将渲染输出导出到bash文件以与某人共享

作者也说了实现原理。大意如下:

每个视频由一组以特定帧速率播放的帧组成。

当选择一个字符来表示一个像素时,我们需要测量该像素在帧中的颜色的相关性,然后我们可以根据色度空间中的相对亮度选择最合适的字符,使用光度函数的简化版本。

绿光对人类感知的强度贡献最大,蓝光最少。

最后,当把它们放在一起时,我们将为每个像素和新颜色提供适当的字符。

一些参数

from . import player

def main():
    import argparse

    CLI_DESC = "It is a simple python package to play videos in the terminal using colored characters as pixels or other usefull outputs"
    EPILOG = ("\033[1;37mThanks for trying video-to-ascii!\033[0m")

    PARSER = argparse.ArgumentParser(prog='video-to-ascii', description=CLI_DESC, epilog=EPILOG)
    PARSER.add_argument('-f', '--file', type=str, dest='file', help='input video file', action='store', required=True)
    PARSER.add_argument('--strategy', default='ascii-color', type=str, dest='strategy', 
        choices=["ascii-color", "just-ascii", "filled-ascii"], help='choose an strategy to render the output', action='store')
    PARSER.add_argument('-o', '--output', type=str, dest='output', help='output file to export', action='store')
    PARSER.add_argument('-a','--with-audio', dest='with_audio', help='play audio track', action='store_true')

    ARGS = PARSER.parse_args()

    player.play(ARGS.file, strategy=ARGS.strategy, output=ARGS.output, play_audio=ARGS.with_audio)


if __name__ == '__main__':
    main()

下面是一部小视频,猜猜看是啥    

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值