【问题标题】:How to convert an MP4 to a text file and back [closed]如何将 MP4 转换为文本文件并返回 [关闭]
【发布时间】:2017-08-10 21:43:40
【问题描述】:

我需要能够将 .mp4 转换为纯文本。我不是指语音,我是指将其转换为字符并将其转换回来。我看过几个程序,但它们只转换语音,我需要将整个内容转换为文本文件,或者将字符复制到文本文件中,然后放回程序中以使其成为视频。我确实看过其他讨论,但它们似乎不适合。谢谢!

【问题讨论】:

  • 你可以使用 base64encode 和 base64decode
  • 为什么需要它是一个文本文件?
  • 取决于你认为的“文本”...ayende.com/blog/177729/…
  • “要变成文本文件的东西”:见上文关于 base64 编码/解码的内容。 “或者让字符可以复制到文本文件中”:所以你的意思是,如果这是一个带有文本的视频,则获取该文本并将它们转换为 txt? OCR(光学字符识别)之类的东西?
  • 在重新发明轮子之前先看看uuencode

标签: python linux python-2.7 python-3.x mp4


【解决方案1】:

试试uu 库:

import uu

uu.encode('video.mp4', 'video.txt')
uu.decode('video.txt', 'video-copy.mp4')

【讨论】:

    【解决方案2】:

    将文件读成明文

    import base64
    
    # Load this source file and strip the header. You can try removing .split('#end_pymotw_header')[1] from end.
    initial_data = open("video.mp4", 'rt').read().split('#end_pymotw_header')[1]
    
    encoded_data = base64.b64encode(initial_data)
    
    num_initial = len(initial_data)
    padding = { 0:0, 1:2, 2:1 }[num_initial % 3]
    
    print '%d bytes before encoding' % num_initial
    print 'Expect %d padding bytes' % padding
    print '%d bytes after encoding' % len(encoded_data)
    print
    #print encoded_data
    for i in xrange((len(encoded_data)/40)+1):
        print encoded_data[i*40:(i+1)*40]
    

    写回 mp4 文件。

    temp_path = tempfile.gettempdir()
    video_binary_string = 'AAAAIGZ0eXBpc29tAAACAGlzb21p...' #it's base64.b64encode text
    decoded_string = base64.b64decode(video_binary_string) 
    
    with open(temp_path+'/video.mp4', 'wb') as wfile:
       wfile.write(decoded_string)
    

    点击here了解更多详情。

    【讨论】:

      猜你喜欢
      • 2012-08-15
      • 2013-03-09
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 2023-03-15
      • 2019-01-06
      • 2015-02-21
      • 2021-03-25
      相关资源
      最近更新 更多