如何用Java读取第一个和最后一个64kb的视频文件? [英] How to read first and last 64kb of a video file in Java?

查看:76
本文介绍了如何用Java读取第一个和最后一个64kb的视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用字幕API。它需要md5哈希的第一个和最后64kb的视频文件。
我知道如何做md5部分只是想知道如何获得128kb数据。

I want to use a subtitle API. It requires a md5 hash of first and last 64kb of the video file. I know how to do the md5 part just want to know how will I achieve to get the 128kb of data.

Python中给出了一个API的例子但遗憾的是我不明白。

An example of API is given in Python but sadly I do not understand it.

    #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()

http://thesubdb.com/api/

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

尝试这样的事情

    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读取第一个和最后一个64kb的视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆