converting byte array to video file

2019-06-03 16:42发布

问题:

How can I convert a byte array to a video file? like mp4 Given the following code

dbConnection connection=new dbConnection(getApplicationContext());
                    SQLiteDatabase db=connection.getReadableDatabase();
                    unhideCursor=db.query(dbConnection.TABLE_VIDEOS, new String[]{dbConnection.VIDEO_DATA}, dbConnection.VIDEO_TITLE+"=?", new String[]{videoTitle}, null, null,null);
                    byte[]videoData=unhideCursor.getBlob(unhideCursor.getColumnIndex(dbConnection.VIDEO_DATA));

回答1:

If the byte array is already a video stream, simply serialize it to the disk with the extension mp4. (If it's an MP4 encoded stream).

Java

FileOutputStream out = new FileOutputStream("video.mp4");
out.write(videoData);
out.close();

C#

Stream t = new FileStream("video.mp4", FileMode.Create);
BinaryWriter b = new BinaryWriter(t);
b.Write(videoData);
t.Close();

Hope this helps!

Jeffrey Kevin Pry