0
我想下载视频文件作为blob存储在Mysql中。该文件下载得很好,但它被损坏我猜。下载的格式是ogg,webm n mp3。问题是,我试图使用ffmpeg转换任何视频,它说“在处理过程中发现无效数据”。从java中的数据库下载视频文件
我使用下面的代码
Blob image = null;
Connection con = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = MySqlConnect.getDBConnection();
String sql = "select videos, filename from sun.videostore where id ='"+fileID+"'";
Statement stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String filename = rs.getString("filename");
Blob video = rs.getBlob("videos");
File file1 = new File("C:\\DowloadFile\\" + filename);
FileOutputStream foStream = new FileOutputStream(file1);
if(video != null){
int length = (int) video.length();
InputStream is2 = video.getBinaryStream();
int b = 0;
while(b!=-1){
b=is2.read();
foStream.write(b);
}
}
}
}catch(Exception e){
System.out.println("Ecxeption in getting data from DB = "+e);
}'
我会检查一下,如果视频肯定没有在数据库中损坏。使用像MySQL Query Browser这样的工具,将blob下载到文件中,然后运行ffmpeg。 – 0xCAFEBABE 2012-04-19 06:12:32
Thanx的快速回复....我会检查tat ...是否有需要设置编解码器后,你写入字节文件在Java中。我在ogg上试过这段代码,视频播放的是Firefox。但是不在chrome上,这是我面临的另一个问题 – deepika 2012-04-19 06:15:48
编解码器通常包含在文件头中。我已经将视频,图片和音乐存储在mysql数据库中,然后直接将字节转储为文件和播放。一旦转储文件,应该不需要设置编解码器信息。听起来像文件在上传到数据库之前已损坏,如@ 0xCAFEBABE提及。 – Namphibian 2012-04-19 07:51:42