2017-08-10 240 views
1

我需要能够将.mp4转换为纯文本。我不是指讲话,我的意思是将其转换为字符并将其转换回来。我看了几个节目,但他们只转换演讲,我需要把整个东西变成一个文本文件,或让这些字母可以复制到一个文本文件中,然后放回节目中制作一段视频。我确实看过其他讨论,他们似乎不适合。谢谢!如何将MP4转换为文本文件并返回

+4

您可以使用base64encode和base64decode为 – Dekel

+0

为什么你需要它是一个文本文件? – cmd

+0

根据你认为“文本”... https://ayende.com/blog/177729/emoji-encoding-a-new-style-for-binary-encoding-for-the-web – ephemient

回答

0

文件读入明文

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了解更多详情。

1

尝试uu库:

import uu 

uu.encode('video.mp4', 'video.txt') 
uu.decode('video.txt', 'video-copy.mp4') 
相关问题