我想使用字幕 API。它需要视频文件的第一个和最后一个 64kb 的 md5 哈希值。 我知道如何做 md5 部分只是想知道我将如何实现获取 128kb 的数据。
Python 给出了一个 API 示例,但遗憾的是我不理解它。
#this hash function receives the name of the file and returns the hash code
def get_hash(name):
readsize = 64 * 1024
with open(name, 'rb') as f:
size = os.path.getsize(name)
data = f.read(readsize)
f.seek(-readsize, os.SEEK_END)
data += f.read(readsize)
return hashlib.md5(data).hexdigest()
如有任何帮助,我们将不胜感激。
最佳答案
尝试这样的事情
FileInputStream in = new FileInputStream("d:/1.avi");
byte[] a = new byte[64 * 1024];
in.read(a); //head
long p = in.getChannel().size() - 64 * 1024;
in.getChannel().position(p);
in.read(a); //tail
关于java - 如何用Java读取视频文件的第一个和最后一个64kb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21714356/