私は現在、学校のプロジェクトに取り組んでおり、MPEG ファイルでいくつかの問題が発生しているようです。私のプロジェクトの範囲は次のとおりです。
1) MPEG ファイルを多くの固定サイズのチャンクに分割します。
2) 特定のチャンクを省略しながら、それらのいくつかを組み立てます。
問題 1:
メディアプレーヤーでファイルを再生すると、省略したチャンクに到達するまでビデオが再生されます。
例:
chunk = ["yui_1", "yui_2", "yui_3", "yui_5", "yui_6"]
Duration of each chunk: 1 second
*気がつけば「yui_4」チャンクを抜けていました*
「yui_4」以外のすべてのチャンクを組み立てると、ビデオは最初の 2 秒間再生されてから、最後までハングします。
問題 2:
最初のチャンクを省略してチャンクをアセンブルすると、mpeg ファイル全体が再生できなくなります。
例:
chunk = ["yui_2", "yui_3", "yui_4", "yui_5", "yui_6"]
Duration of each chunk: 1 second
以下は私のコードの一部です(ハードコード):
def splitFile(inputFile,chunkSize):
splittext = string.split(filename, ".")
name = splittext[0]
extension = splittext[1]
os.chdir("./" + media_dir)
#read the contents of the file
f = open(inputFile, 'rb')
data = f.read() # read the entire content of the file
f.close()
# get the length of data, ie size of the input file in bytes
bytes = len(data)
#calculate the number of chunks to be created
noOfChunks= bytes/chunkSize
if(bytes%chunkSize):
noOfChunks+=1
#create a info.txt file for writing metadata
f = open('info.txt', 'w')
f.write(inputFile+','+'chunk,'+str(noOfChunks)+','+str(chunkSize))
f.close()
chunkNames = []
count = 1
for i in range(0, bytes+1, chunkSize):
fn1 = name + "_%s" % count
chunkNames.append(fn1)
f = open(fn1, 'wb')
f.write(data[i:i+ chunkSize])
count += 1
f.close()
以下は、チャンクを組み立てる方法の一部です。
def assemble():
data = ["yui_1", "yui_2", "yui_3", "yui_4", "yui_5", "yui_6", "yui_7"]
output = open("output.mpeg", "wb")
for item in datafile:
data = open(item, "rb"). read()
output.write(data)
output.close()