How to read the first and last 64kb video file in Java?

I want to use the subtitle API. It requires an md5 hash of the first and last 64kb video file. I know how to make the md5 part, I just want to know how I can get 128 KB data.

An example API is given in Python, but unfortunately 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.

0
source share
1 answer

try something like this

    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
0
source

All Articles