同じコンテナ形式のビデオは、同じバイトで始まります。使用されるコーデックによって、実際のビデオ ファイルが決まります。
ビデオ アプリケーションの開発を計画している場合は、最初にコンテナ ファイル形式とコーデックについて詳しく読むことをお勧めします。
しかし、別の問題があります。Andrew Thompson が正しく指摘したように、ファイル名 stringのバイトを取得しています。
正しいアプローチは次のようになります。
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;
}