2017-08-10 75 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') 
相關問題