hi
how to get video file duration(time ) using c#
Page 1 of 18 Replies - 39773 Views - Last Post: 20 August 2010 - 09:43 AM
Replies To: how to get video file duration(time ) using c#
#2
Re: how to get video file duration(time ) using c#
Posted 24 July 2008 - 08:22 AM
you could try checking the file properties for this info. Otherwise I think you'd have to come up with some kind of crazy formulas to calculate the time based on the file size, video resolution and sound resolution. Not really sure, never tried it?
#3
Re: how to get video file duration(time ) using c#
Posted 24 July 2008 - 08:47 AM
[rules][/rules]
#4
Re: how to get video file duration(time ) using c#
Posted 22 August 2008 - 03:52 AM
jayman9, on 24 Jul, 2008 - 08:47 AM, said:
[rules][/rules]
i want to convert .flv file into .wmv, for that i am using a thrid party tool
"flash to video console". its a command line.
through my .net code i am initiating its exe.this tool needs the maxtime. for that i need to know the duartion of my flv file.can you please help me to get the duration of flash file.
i am attaching my code here :
Const g_strV2FPath As String = "C:\Program Files\VidFilters\Flash to Video Console\FVEConsole.exe" Dim strSourceFile As String = "C:\Program Files\Adobe\Flash Media Server 3\applications\FlexWebCamCapture\streams\_definst_\CapturedVideoAudioFile.flv" Dim Process As New System.Diagnostics.Process Dim objPlayer As New WMPLib.WindowsMediaPlayer objPlayer.mediaCollection.add(strSourceFile) objPlayer.currentMedia = objPlayer.mediaCollection.getAll Dim sngDuration As Single = objPlayer.currentMedia.duration Process.Start(g_strV2FPath, "-Input " + """" + strSourceFile + """" + " -Output " + """" + "E:\converted wmv\CapturedVideoAudioFile.wmv" + """" + " -MaxTime ""600""" + """" + "")
i am using windows media player but this code is throwing an error.
any help is appriciated
kusum
#5
Re: how to get video file duration(time ) using c#
Posted 22 August 2008 - 12:14 PM
you could add a timer to your form and then just make it start (on the button that your video is supposed to start) and display the time it's counting
and kusumyadav first of all your code is in VB not C# second of all this is not your topic make your own and ask for help don't hijack other peoples
and kusumyadav first of all your code is in VB not C# second of all this is not your topic make your own and ask for help don't hijack other peoples
#6
Re: how to get video file duration(time ) using c#
Posted 22 August 2008 - 01:12 PM
Here is a link to a codeproject post that will read the flv header file. You should be able to calculate the duration from this info.
http://www.codeproje...;select=2417085
Hope this helps,
Kitt
http://www.codeproje...;select=2417085
Hope this helps,
Kitt
#7
Re: how to get video file duration(time ) using c#
Posted 25 October 2009 - 11:18 PM
How about using ffmpeg.exe as a process within your code?
Quick Edit:
you need to include System (of course...), System.Diagnostics (for Process support), and System.IO (for StreamReaders)
Quick Edit Again:
My fault, the Convert.ToDouble() doesn't change it into a double representing seconds xD. I was doing something else with that...
The conversion from HH:MM:SS to seconds is left as an exercise for the OP
I hope I'm not breaking the rules here. It looks like this topic was posted a long time ago, so I figured what the hey. If I'm in the wrong, someone let me know. I'm pretty new.
Hope that helps,
Stephen H
using(Process ffmpeg = new Process())
{
String duration; // soon will hold our video's duration in the form "HH:MM:SS.UU"
String result; // temp variable holding a string representation of our video's duration
StreamReader errorreader; // StringWriter to hold output from ffmpeg
// we want to execute the process without opening a shell
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.ErrorDialog = false;
// redirect StandardError so we can parse it
// for some reason the output comes through over StandardError
ffmpeg.StartInfo.RedirectStandardError = true;
// set the file name of our process, including the full path
// (as well as quotes, as if you were calling it from the command-line)
ffmpeg.StartInfo.FileName = "[directory of ffmpeg.exe]\ffmpeg.exe";
// set the command-line arguments of our process, including full paths of any files
// (as well as quotes, as if you were passing these arguments on the command-line)
ffmpeg.StartInfo.Arguments = "-i [directory of video file]\video_file";
// start the process
ffmpeg.Start();
// now that the process is started, we can redirect output to the StreamReader we defined
errorreader = ffmpeg.StandardError;
// wait until ffmpeg comes back
ffmpeg.WaitForExit([time_to_wait_in_milliseconds]);
// read the output from ffmpeg, which for some reason is found in Process.StandardError
result = errorreader.ReadToEnd();
// a little convoluded, this string manipulation...
// working from the inside out, it:
// takes a substring of result, starting from the end of the "Duration: " label contained within,
// (execute "ffmpeg.exe -i somevideofile" on the command-line to verify for yourself that it is there)
// and going the full length of the timestamp.
// The resulting substring is of the form "HH:MM:SS.UU"
duration = result.Substring(result.IndexOf("Duration: ") + ("Duration: ").Length, ("00:00:00.00").Length);
}
Quick Edit:
you need to include System (of course...), System.Diagnostics (for Process support), and System.IO (for StreamReaders)
Quick Edit Again:
My fault, the Convert.ToDouble() doesn't change it into a double representing seconds xD. I was doing something else with that...
The conversion from HH:MM:SS to seconds is left as an exercise for the OP
I hope I'm not breaking the rules here. It looks like this topic was posted a long time ago, so I figured what the hey. If I'm in the wrong, someone let me know. I'm pretty new.
Hope that helps,
Stephen H
This post has been edited by hardimon: 26 October 2009 - 12:32 AM
#8 Guest_bmmarko98@gmail.com*
Re: how to get video file duration(time ) using c#
Posted 20 August 2010 - 09:40 AM
hardimon, on 25 October 2009 - 10:18 PM, said:
How about using ffmpeg.exe as a process within your code?
Quick Edit:
you need to include System (of course...), System.Diagnostics (for Process support), and System.IO (for StreamReaders)
Quick Edit Again:
My fault, the Convert.ToDouble() doesn't change it into a double representing seconds xD. I was doing something else with that...
The conversion from HH:MM:SS to seconds is left as an exercise for the OP
I hope I'm not breaking the rules here. It looks like this topic was posted a long time ago, so I figured what the hey. If I'm in the wrong, someone let me know. I'm pretty new.
Hope that helps,
Stephen H
using(Process ffmpeg = new Process())
{
String duration; // soon will hold our video's duration in the form "HH:MM:SS.UU"
String result; // temp variable holding a string representation of our video's duration
StreamReader errorreader; // StringWriter to hold output from ffmpeg
// we want to execute the process without opening a shell
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.ErrorDialog = false;
// redirect StandardError so we can parse it
// for some reason the output comes through over StandardError
ffmpeg.StartInfo.RedirectStandardError = true;
// set the file name of our process, including the full path
// (as well as quotes, as if you were calling it from the command-line)
ffmpeg.StartInfo.FileName = "[directory of ffmpeg.exe]\ffmpeg.exe";
// set the command-line arguments of our process, including full paths of any files
// (as well as quotes, as if you were passing these arguments on the command-line)
ffmpeg.StartInfo.Arguments = "-i [directory of video file]\video_file";
// start the process
ffmpeg.Start();
// now that the process is started, we can redirect output to the StreamReader we defined
errorreader = ffmpeg.StandardError;
// wait until ffmpeg comes back
ffmpeg.WaitForExit([time_to_wait_in_milliseconds]);
// read the output from ffmpeg, which for some reason is found in Process.StandardError
result = errorreader.ReadToEnd();
// a little convoluded, this string manipulation...
// working from the inside out, it:
// takes a substring of result, starting from the end of the "Duration: " label contained within,
// (execute "ffmpeg.exe -i somevideofile" on the command-line to verify for yourself that it is there)
// and going the full length of the timestamp.
// The resulting substring is of the form "HH:MM:SS.UU"
duration = result.Substring(result.IndexOf("Duration: ") + ("Duration: ").Length, ("00:00:00.00").Length);
}
Quick Edit:
you need to include System (of course...), System.Diagnostics (for Process support), and System.IO (for StreamReaders)
Quick Edit Again:
My fault, the Convert.ToDouble() doesn't change it into a double representing seconds xD. I was doing something else with that...
The conversion from HH:MM:SS to seconds is left as an exercise for the OP
I hope I'm not breaking the rules here. It looks like this topic was posted a long time ago, so I figured what the hey. If I'm in the wrong, someone let me know. I'm pretty new.
Hope that helps,
Stephen H
Hi, i just want to comment your idea. It was my way to go in first project. I was writing ffmpeg wrapper for .NET and a was using string parsing from standardError that ffmpeg.exe generates to retrive duration of input media and the time based progress of a conversion progress. It worked fine with with most video and audio files, but not with all. When I tried to convert You Tube video ffmpeg couldn't read duration of input file. It generated string in format "Duration: N/A" but it done conversion process without any problems.
So, this way to read input file duration is good for most of media types, but not in all...
If you broke the rules I broke them too, by posting year after last replay, but I hope this was useful for further work, just to know
#9
Re: how to get video file duration(time ) using c#
Posted 20 August 2010 - 09:43 AM
I appreciate everyone's willingness to help, but please avoid necroposting in the future.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote









|