EDN Admin
Well-known member
<div style="color:black; background-color:white
<pre><span style="color:blue private <span style="color:blue void loadVideoToolStripMenuItem_Click(<span style="color:blue object sender, EventArgs e)
{
openFileDialog1.Title = <span style="color:#a31515 "Select a video file";
openFileDialog1.InitialDirectory = "c:\";
openFileDialog1.FileName = <span style="color:blue null;
openFileDialog1.Filter = <span style="color:#a31515 "Video Files|*.wmv;*.3gp;*.avi";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = <span style="color:blue true;
DialogResult result1 = openFileDialog1.ShowDialog();
<span style="color:blue string file1 = openFileDialog1.FileName;
<span style="color:blue if (result1 == DialogResult.OK)
{
strVideoFile = file1;
mdd.Filename = strVideoFile;
streamlength = mdd.StreamLength;
<span style="color:blue double dt = (<span style="color:blue double)1 / mdd.FrameRate;<span style="color:green //(double)20; //mdd.FrameRate;
<span style="color:blue int i = 0;
<span style="color:blue for (<span style="color:blue double x = 0; x < streamlength; x += dt)
{
streamDouble[0] = x;
SaveFramesFromVideo(strVideoFile, streamDouble, sf + i.ToString(<span style="color:#a31515 "D6") + <span style="color:#a31515 ".bmp");
i++;
}
fi = dir1.GetFiles(<span style="color:#a31515 "*.bmp");
<span style="color:blue if (fi.Length == 0)
{
trackBar1.Enabled = <span style="color:blue false;
}
<span style="color:blue else
{
trackBar1.Enabled = <span style="color:blue true;
trackBar1.Minimum = 0;
trackBar1.Maximum = fi.Length - 1;
trackBar1.Value = 0;<span style="color:green //fi.Length - 1;
Bitmap newImage;
newImage = <span style="color:blue new Bitmap(fi[0].FullName);
pictureBox1.Image = newImage;
}
}
<span style="color:blue if (result1 == DialogResult.Cancel)
{
<span style="color:blue if (file1 == <span style="color:#a31515 "")
{
}
}
}
[/code]
<br/>
The for loop is taking time and while its working the program is stuck hanging on. I want to release the program while its making the for loop.
Inside the for loop im using: SaveFramesFromvideo(...
<div style="color:black; background-color:white
<pre><span style="color:blue public <span style="color:blue static <span style="color:blue void SaveFramesFromVideo(<span style="color:blue string videoFile, <span style="color:blue double[] positions, <span style="color:blue string outputBitmapFiles)
{
<span style="color:blue if (videoFile == <span style="color:blue null)
<span style="color:blue throw <span style="color:blue new ArgumentNullException(<span style="color:#a31515 "videoFile");
<span style="color:blue double streamLength;
IMediaDet mediaDet = <span style="color:blue null;
<span style="color:blue try
{
_AMMediaType mediaType;
<span style="color:blue if (openVideoStream(videoFile, <span style="color:blue out mediaDet, <span style="color:blue out mediaType))
{
streamLength = mediaDet.StreamLength;
Size target = getVideoSize(mediaType);
<span style="color:blue int iteration = 0;
<span style="color:blue foreach (<span style="color:blue double position <span style="color:blue in positions)
{
iteration++;
<span style="color:blue string outputBitmapFile = <span style="color:blue string.Format(outputBitmapFiles, iteration);
mediaDet.WriteBitmapBits(position, target.Width, target.Height, outputBitmapFile);
}
}
}
<span style="color:blue catch (COMException)
{
<span style="color:blue throw <span style="color:blue new InvalidVideoFileException();
}
<span style="color:blue finally
{
<span style="color:blue if (mediaDet != <span style="color:blue null)
Marshal.ReleaseComObject(mediaDet);
}
<span style="color:blue return;
}
[/code]
And how can i add a cancel button and how can i cancel the operation of the frames saving ? If the user want to cancel the operation.
Thanks.
<
danieli<br/>
View the full article
<pre><span style="color:blue private <span style="color:blue void loadVideoToolStripMenuItem_Click(<span style="color:blue object sender, EventArgs e)
{
openFileDialog1.Title = <span style="color:#a31515 "Select a video file";
openFileDialog1.InitialDirectory = "c:\";
openFileDialog1.FileName = <span style="color:blue null;
openFileDialog1.Filter = <span style="color:#a31515 "Video Files|*.wmv;*.3gp;*.avi";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = <span style="color:blue true;
DialogResult result1 = openFileDialog1.ShowDialog();
<span style="color:blue string file1 = openFileDialog1.FileName;
<span style="color:blue if (result1 == DialogResult.OK)
{
strVideoFile = file1;
mdd.Filename = strVideoFile;
streamlength = mdd.StreamLength;
<span style="color:blue double dt = (<span style="color:blue double)1 / mdd.FrameRate;<span style="color:green //(double)20; //mdd.FrameRate;
<span style="color:blue int i = 0;
<span style="color:blue for (<span style="color:blue double x = 0; x < streamlength; x += dt)
{
streamDouble[0] = x;
SaveFramesFromVideo(strVideoFile, streamDouble, sf + i.ToString(<span style="color:#a31515 "D6") + <span style="color:#a31515 ".bmp");
i++;
}
fi = dir1.GetFiles(<span style="color:#a31515 "*.bmp");
<span style="color:blue if (fi.Length == 0)
{
trackBar1.Enabled = <span style="color:blue false;
}
<span style="color:blue else
{
trackBar1.Enabled = <span style="color:blue true;
trackBar1.Minimum = 0;
trackBar1.Maximum = fi.Length - 1;
trackBar1.Value = 0;<span style="color:green //fi.Length - 1;
Bitmap newImage;
newImage = <span style="color:blue new Bitmap(fi[0].FullName);
pictureBox1.Image = newImage;
}
}
<span style="color:blue if (result1 == DialogResult.Cancel)
{
<span style="color:blue if (file1 == <span style="color:#a31515 "")
{
}
}
}
[/code]
<br/>
The for loop is taking time and while its working the program is stuck hanging on. I want to release the program while its making the for loop.
Inside the for loop im using: SaveFramesFromvideo(...
<div style="color:black; background-color:white
<pre><span style="color:blue public <span style="color:blue static <span style="color:blue void SaveFramesFromVideo(<span style="color:blue string videoFile, <span style="color:blue double[] positions, <span style="color:blue string outputBitmapFiles)
{
<span style="color:blue if (videoFile == <span style="color:blue null)
<span style="color:blue throw <span style="color:blue new ArgumentNullException(<span style="color:#a31515 "videoFile");
<span style="color:blue double streamLength;
IMediaDet mediaDet = <span style="color:blue null;
<span style="color:blue try
{
_AMMediaType mediaType;
<span style="color:blue if (openVideoStream(videoFile, <span style="color:blue out mediaDet, <span style="color:blue out mediaType))
{
streamLength = mediaDet.StreamLength;
Size target = getVideoSize(mediaType);
<span style="color:blue int iteration = 0;
<span style="color:blue foreach (<span style="color:blue double position <span style="color:blue in positions)
{
iteration++;
<span style="color:blue string outputBitmapFile = <span style="color:blue string.Format(outputBitmapFiles, iteration);
mediaDet.WriteBitmapBits(position, target.Width, target.Height, outputBitmapFile);
}
}
}
<span style="color:blue catch (COMException)
{
<span style="color:blue throw <span style="color:blue new InvalidVideoFileException();
}
<span style="color:blue finally
{
<span style="color:blue if (mediaDet != <span style="color:blue null)
Marshal.ReleaseComObject(mediaDet);
}
<span style="color:blue return;
}
[/code]
And how can i add a cancel button and how can i cancel the operation of the frames saving ? If the user want to cancel the operation.
Thanks.
<
danieli<br/>
View the full article