Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Suppose i have to select only .mp4 extension files from a file Open Dialog then i need to make a filter like this

C#
openFileDialog.Filter = "Media File MP4|*.mp4";


but what if i have a dump file with file extension .mp4 ??? say for example i create a new text file on desktop and make its extension .mp4 and then if i try to browse and select that file it comes under file filter but that's not a real mp4 file...

how to validate if selected file is correct and desired file or not???
Posted
Updated 11-Jun-13 10:26am
v2
Comments
joshrduncan2012 11-Jun-13 16:34pm    
You are going to get all mp4 files no matter if they are real mp4s or imposters.
Hitesh Rohilla 11-Jun-13 17:22pm    
That i already know that's why i raise this question...

In general case, there is no a way.

But this is not a problem: it won't play, that's all. Wouldn't that be a good validation? Well, get ready to process all exceptions, of course. Take any other player; or, why player? any good software having such dialog. Nothing will validate file content, for a good reason: even if the file has some signature, even if you know it and validate it, who will guarantee that it has no garbage?

By the way, media files are way more complex than that: the file have certain container format. And don't think that *.MP4 is used only by one container — there is a good number of different containers based on MPEG, and not only. Now, a container can combine one, two or more different compression algorithms in it, which all have their own signatures. This machinery is quite complex. That said, making it possible to play only one container of file type will have very little value.

[EDIT]

Please see all my comments in this discussion. If you really want to bite a bullet (which I still cannot seriously advise), you can try to use… some other available software. This could be ffMpeg or underlying libavcodec:
http://en.wikipedia.org/wiki/Ffmpeg[^],
http://ffmpeg.org/[^],
http://en.wikipedia.org/wiki/Libavcodec[^],
http://libav.org/[^].

First of all, run one already built utility to see how it works with your files. Its name is "ffprobe.EXE", and it is a part of ffmpeg; and the analogous application doing exactly the same is bundled with libavcodec. The quality of these open-source multiplatform library and utilities is very high; this is the main thing I use for all my media needs, and it almost never betrays me, getting sufficient access to most of the most rare or exotic formats and codecs.

It parses your media file and gives you information on it. It's really fast and would be enough for consistency.

You can use it as a library, but you should understand that it is written in C, so you would need to use P/Invoke. As a cheap alternative, you could simply execute the utility using System.Diagnostics.Process.Start, redirect its output and analyze the resulting output text. I hope you know how to do all that, it's simple enough.

Now, the problem is: ffMpeg (libav) is not relied on the codecs installed in the system, in contrast, it carries everything in the product itself. That said, the format/codec repertoire of ffMpeg (libav) could happen to be much wider than that of your codec set, so what might happen is: ffMpeg (libav) can cope with some file, but your player fails to play it. I observed it many times, when I compare "ffProbe.exe" (or "ffPlay.exe") with Windows Visual Studio (which is actually ridiculously weak in supported media features).

But this is better than nothing. Besides, you can analyze the output of "ffProbe.exe" and reject some formats/codecs which you know to be not supported by your player.

Alternatively, you can opt for a different player. VLC, for example, is based on ffMpeg and cab be embedded in your application as a component; and some .NET wrappers are also available; please see my past answers:
Streaming music files in vb.net without WMP[^],
need help in getting the streaming video from an other computer in C#[^].

—SA
 
Share this answer
 
v4
Comments
Hitesh Rohilla 11-Jun-13 17:19pm    
Thanks Sergey for your comment but here what i want here to do is to process a video file...

I am trying to import a video file and then apply some video processing on it... the process is too long [when processing happening] and also cover its path after many checks on checkboxes [which tell how to process]...

if it's a dump file with same extension then there is no way to stop it from processing if i didn't apply such validation... ultimately it may cause some bugs or error or malfunctioning of software. also it may happen that processing goes smoothly like encryption [as encryption didn't depend on file type] and so at the end of the day confuse user and consume valuable time.

and yes i have seen such validation in some software but don't remember its name to represent it as an example here...
Sergey Alexandrovich Kryukov 11-Jun-13 17:25pm    
No. There is no a problem of malfunctioning. All components behave well after such exception. You are trying to break through an open door. You really, should not worry about the validation of media file content, this is 1) not needed, 2) hard to do, nearly impossible in practice, 3) if you manage to do it 100% correctly, you will loose a lot of performance.
—SA
Hitesh Rohilla 11-Jun-13 17:37pm    
i understand that it may not malfunction but ultimately it cause confusion and loss of valuable time... secondly its possible as i already have experience in some software...

and i have to worry about that... and validation just took a few seconds after selecting file it gives message box within a second that's what i experience and looking for...

and yes... when you try to convert one form of video to another form it has to read codec and convert it into another... if codec signatures are not there then it may also malfunction...

It may happen that u don't have idea to do that but i know it can be done without the loss any performance.
Sergey Alexandrovich Kryukov 11-Jun-13 18:14pm    
Here is the problem: if you do the validation, you will waste even more valuable time, otherwise your validation it way too weak and not worthy.

You are right when you say that I have no idea on how to do it. Almost. I actually basically know what's involved, and I don't know how to accomplish it all during some reasonable time, which could be any better then the existing player component can do. More exactly, I know that the validation will actually be done pretty well with existing software. And this existing software is actually your player component (probably, because I don't know what exactly do you use). Do you see the point? The validation you want is already done.

Anyway, I don't see my mission on convincing you. I have yet another idea, but it is also based on using existing software...

—SA
Sergey Alexandrovich Kryukov 11-Jun-13 18:33pm    
OK, please see my updated answer, after [EDIT]. I'm still doubt it worth bothering, by the reasons I tried to explain.
—SA
This is the updated useful information on the VLC component binding for.NET:
http://sourceforge.net/projects/libvlcnet/[^],
https://wiki.videolan.org/C_Sharp/[^],
https://wiki.videolan.org/.Net_Interface_to_VLC/[^].

Notably, you can find material for using the component for both WPF and System.Windows.Forms.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900