How to get mp4 video file sizes?

I have a form that will accept and save an MP4 video file. I also need to have video sizes. This will be performed on the server running ASP.NET 2.0, so any external libraries should be placed in the Bin folder, since they cannot be installed on the server.

Any ideas on how to get the information? If the same lib allowed me to transcode the video to flv, that would be a huge bonus.

Update: XP Server Service Pack 2 with .NET Framework (2.0 50727.0)

+4
source share
2 answers

There are several ways to do this, but without a library that will work with C # for any / all .mp4 video files. It's nothing that is 100% more reliable.

Both command line options (in a way). Basically, what you will do is start the process from your ASP.NET application using System.Diagnostics.Process.

Of these, ffmpeg should be used. With ffmpeg, if you just pass the file to it (as a command line argument, if different file metadata is returned. This information can be analyzed to extract the dimensions.

Another is to use MediaInfo . This is a great tool for this. But again, you have to use the command line version (CLI version) and pretty much give it the file name as a command line argument. It has otion to create and xml response, so you can easily analyze this and other information if you can provide.

ffmpeg can also transcode your video. Although I do not see the transcoding point with mp4. Flv?

+2
source

Alturos.VideoInfo is a shell for ffprobe that makes it pretty easy to integrate into a C # project.

It can be installed from NuGet as follows:

PM> Install-Package Alturos.VideoInfo 

To use it, you need ffprobe.exe. If it is not in your project, you can run this code to download it:

 var ffmpegDownloader = new FileDownloader(); var ffmpegUrl = ffmpegDownloader.GetFfmpegPackageUrl(); var ffmpegDownloadResult = await ffmpegDownloader.DownloadAsync(ffmpegUrl, @"ffprobe\ffprobe.exe"); var ffprobePath = ffmpegDownloadResult.FfprobePath; 

Video sizes can be easily found by receiving a video stream:

 var videoAnalyzer = new VideoAnalyzer(ffprobePath); var analyzeResult = videoAnalyzer.GetVideoInfo(/* your video file path here */); if (analyzeResult.Successful) { var videoStream = analyzeResult.VideoInfo.Streams.Single(o => o.CodecType == "video"); var width = videoStream.Width; var height = videoStream.Height; } 
0
source

All Articles