相同容器格式的視頻以相同的字節開頭。使用的編解碼器確定實際的視頻文件。
我建議你閱讀更多關於容器文件格式和編解碼器第一,如果你打算開發視頻應用。
但你有一個不同的問題。正如Andrew Thompson正確指出的那樣,您將獲得文件名字符串的字節。
正確的做法是:
private static File fl=new File("D:\video.avi");
byte[] myByteArray = getBytesFromFile(fl);
也請記住,終端通常有固定的緩衝區大小(在Windows上,它是幾行),所以輸出數據的很大一部分將僅顯示過去幾年它的線。
編輯:下面是getBytesFromFile的實現;一位java專家可能會提供更多的標準方法。
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = openFile(file.getPath());
// Get the size of the file
long length = file.length();
if (length > Integer.MAX_VALUE) {
// File is too large
Assert.assertExp(false);
logger.warn(file.getPath()+" is too big");
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// debug - init array
for (int i = 0; i < length; i++){
bytes[i] = 0x0;
}
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
你到底想幹什麼?將視頻內容轉換爲字節或文件名爲字節? – Drona
對視頻文件進行逐字節比較有什麼意義?我可以逐幀理解,但逐字節沒有多大意義。 –
我想將視頻內容轉換爲字節 – lama