首页 新闻 搜索 专区 学院

如何获取mp4(H.264)的文件信息

0
[已关闭问题] 关闭于 2012-07-31 11:09

如何获取mp4(H.264)的文件信息,我尝试过shell,但不支持mp4格式的,之后还用过IBMToolkitForMpeg4SDK,但遇到问题:

Exception in thread "main" java.net.MalformedURLException: Unrecognized extension of file: e:\1.mpeg
at I4g.d(Unknown Source)
at I4g.a(Unknown Source)
at I4i.a(Unknown Source)
at I4b.a(Unknown Source)
at I4b.open(Unknown Source)
at AVgenSample.getMp4Duration(AVgenSample.java:48)
at AVgenSample.main(AVgenSample.java:36)

微小的主页 微小 | 菜鸟二级 | 园豆:201
提问于:2012-05-18 10:50
< >
分享
所有回答(1)
0

1.download DirectShowLib,I use the version DirectShowLibV2-1
its website: http://directshownet.sourceforge.net/
and download page:http://sourceforge.net/projects/directshownet/files/ 2.using the lib in c#
3.code using MediaDet class
reference:

using System.Runtime.InteropServices;
using DirectShowLib;
using DirectShowLib.DES;

code:

public static string GetDuration(string fileName)
{
var mediaDet = (IMediaDet)new MediaDet();
DsError.ThrowExceptionForHR(mediaDet.put_Filename(fileName));

// find the video stream in the file
int index;
var type = Guid.Empty;
for (index = 0; index < 1000 && type != MediaType.Video; index++)
{
mediaDet.put_CurrentStream(index);
mediaDet.get_StreamType(out type);
}

// retrieve some measurements from the video
double frameRate;
mediaDet.get_FrameRate(out frameRate);

var mediaType = new AMMediaType();
mediaDet.get_StreamMediaType(mediaType);
var videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader));
DsUtils.FreeAMMediaType(mediaType);
var width = videoInfo.BmiHeader.Width;
var height = videoInfo.BmiHeader.Height;

double mediaLength;
mediaDet.get_StreamLength(out mediaLength);
//var frameCount = (int)(frameRate * mediaLength);
//var duration = frameCount / frameRate;

return mediaLength.ToString();
}

微小 | 园豆:201 (菜鸟二级) | 2012-05-18 13:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册