问题描述
我想获取mp4文件的一些信息(例如持续时间,文件大小,标题等),我尝试使用Shell32,但它不支持mp4格式,我在网站上找到了一些dll,但是它们都不是COM组件,那么我尝试使用IBMToolkitForMpeg4SDK.jar,然后遇到一些问题线程主"中的异常java.net.MalformedURLException:无法识别的文件扩展名:
I want to get some information of an mp4 file(such as duration,file size,title and so on) , I try to use Shell32 , but it does not support mp4 format , I have found some dlls in the website , but all they are not COM component , then I try to use IBMToolkitForMpeg4SDK.jar , and then meets some problems 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)
所以我想获取mp4文件的信息,任何人都有任何方法,请帮忙!全部解决!
So I want to get the information of mp4 file , anyone have any methods , please help!Thsnks all!
推荐答案
using System.Runtime.InteropServices;
using DirectShowLib;
using DirectShowLib.DES;
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();
}
这篇关于如何获取mp4文件的信息(h.264标准)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!