Using FFMpeg to determine video-type, converting afterwards?
I'm trying to determine the real type of a file programmatically. It seems I have to use for example FFMPeg for that.
I want to determine if an uploaded file is in fact a MP4 or FLV (for flash videos) [or WebM (for HTML5)]. I know the -i operator in FFMPeg but I don't know what to check for.
For example:
Input #0, flv, from 'c:\www\data.aspbooru\image\0\40c24ba424d1334ef81c88c416ce794e.flv':
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'c:\www\data.aspbooru\image\0\8c1a747b5188349d92cca17a502d2d57.mp4':
Those are FFMPeg outputs. Is this all I have to check for when filtering videos for flash?
So, if none of those apply. How do I check for a swf file?
Input #0, swf, from 'c:\www\data.aspbooru\image\0\90447bd30d30ccb1474c0433e948d438.swf':
Duration: 00:07:16.08, start: 0.000000, bitrate: 63 kb/s
Stream #0.0: Audio: mp3, 44100 Hz, 2 channels, s16, 64 kb/s
Stream #0.1: Video: flv, yuv420p, 320x240, 25 fps, 25 tbr, 25 tbn, 25 tbc
Is checking for Input #0, swf,
enough? It extracts an included flv which I dont want.
Now I also need to check for file types which are completely NOT videos and filetypes which are videos, but could be converted to a mp4 with h.264 (Or Webm?) I have completely no clue how to do this.
The conversion thing can be managed, but hints on that would be very cool too (converting h.264 and webm?).
I input a random file. Is this it?
c:\web.config: Invalid data found when processing input
EDIT: No programming language specified because it is independent of any programming language. But I would be grateful for language specific input: VB.NET. You can assume I already have the process logic and the output i开发者_Python百科s there as a string! Regex would be cool too :)
Determining Types
You might have better luck with MediaInfo.
Grab the command line version and use it like this:
mediainfo --full --language=raw --output=xml
This gives XML output, you can then use XPath to grab the Codec field. Or if XML is not your thing drop the '--output=xml' then write a regex to parse the text output.
For non recognised files it looks like it gives some output but certainly won't have a Codec field.
Converting videos
For actually converting videos FFmpeg is the Swiss Army Knife of video encoding and is probably your best option.
You don't need to know the input really as long as you know what output codecs you want.
Something like this can get you started:
ffmpeg -i input.mov -vcodec libx264 -acodec libfaac -f mov out.mp4
That will give you a MPEG-4 with H.264 video and AAC audio. Although there are many options available to tune this to get what you want.
This site is useful for tuning H.264 options.
Good luck!
I would give some libraries a try as you're going to get better results than Regex and determining such for yourself:
Solid FFmpeg wrapper for C#/.NET
精彩评论