如何获取mp4文件的信息(h.264标准) [英] how to get the information of an mp4 file(h.264 standard)

查看:439
本文介绍了如何获取mp4文件的信息(h.264标准)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取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!

推荐答案


1.download DirectShowLib,我使用的是DirectShowLibV2-1版本.
其网站:

http://directshownet.sourceforge.net/
并下载页面:
http://sourceforge.net/projects/directshownet/files/
2.在c#中使用lib
3.使用MediaDet类进行编码

参考:



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();
            }


这篇关于如何获取mp4文件的信息(h.264标准)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆