In my project I am saving videos, converting formats to .swf using ffmpeg. Converting and saving the videos is working fine, but I have a problem with creating the thumbnails. It saves a "picture.jpg" but there is no image. looking at the thumbnail its only got the normal photoviewer sign which is fine, but when I try to open the image it gives a message of Windows photo viewer: Windows photo viewer cant open this picture because the file appears to be damaged, corrupted, or is too large. (this image is 2.7MB) - Photos taken from my camera is about 5MB and that opens.
PictureViewer: couldn't display "image.jpg" because a suitable graphics importer could not be found.
Paint: Paint cannot read this file. This is not a valid bitmap file or its format is currently not supported. The images won't open in any I done to save the image:
string thumbpath, thumbname; string thumbargs; string thumbre; thumbpath = Server.MapPath("~\\uploads\\" + dtYear + "\\" + dtMonth + "\\Thumb\\"); CreateDirectoryIfNotExists(thumbpath); // Create the path and file name to check for duplicates. pathToCheck = thumbpath; // Create a temporary file name to use for checking duplicates. tempfileName = ""; // Check to see if a file already exists with the // same name as the file to upload. if (System.IO.File.Exists(pathToCheck)) { int counter = 2; while (System.IO.File.Exists(pathToCheck)) { // if a file with this name already exists, // prefix the filename with a number. tempfileName = thumbpath + counter.ToString() + withoutext + ".jpg"; pathToCheck = tempfileName; counter++; } outputfile = tempfileName; // Notify the user that the file name was changed. lblMsg.Text = "A file with the same name already exists." +"<br />Your file was saved as " + counter.ToString() + withoutext + ".jpg"; } thumbname = thumbpath + withoutext + "%d" + ".jpg"; Session["thumbname"] = withoutext + "1" + ".jpg"; // thumbargs = "-i {0} -f image2 frame-%1d.png -y {1}; thumbargs = "-i " + inputfile + " -f image2 frame-%1d.jpg -y " + thumbname; Process thumbproc = new Process(); thumbproc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe"; thumbproc.StartInfo.Arguments = thumbargs; thumbproc.StartInfo.UseShellExecute = false; thumbproc.StartInfo.CreateNoWindow = false; thumbproc.StartInfo.RedirectStandardOutput = false; try { thumbproc.Start(); fuPath.PostedFile.SaveAs(thumbname); } catch (Exception ex) { Response.Write(ex.Message); } thumbproc.WaitForExit(); thumbproc.Close();
I have tried a few ways with the arguments, but with no success:
//thumbargs = "-i " + inputfile + " -an -ss 00:00:03 -s 120×90 -vframes 1 -f mjpeg " + thumbName; // thumbargs = "-i " + inputfile + "-f image2 -ss 1.000 -vframes 1 " + thumbName; thumbargs = "-i " + inputfile + " -vframes 1 -ss 00:00:10 -s 150x150 " + thumbName; // thumbargs = "ffmpeg -i" + inputfile + " -ss 0:00:01.000 -sameq -vframes 1 " + withoutext + ".jpg"; // thumbargs = "-i " + inputfile + " -vframes 1 -ss 00:00:07 -s 150x150 " + thumbName; Process thumbproc = new Process();
This is how it looks like when I want to open the image: (it may be that it is saving an empty image?)
EDIT:
I changed a bit of my code. Debugging through my code there is no exception that is thrown, but if I point the mouse over the process (after it started) it "shows an exception of type System.InvalidOperationException"
thumbargs = "-i "+ postedfilename +" vframes 1"+ thumbName;
ProcessStartInfo thumbProcstartIfo =new ProcessStartInfo();
thumbProcstartIfo.FileName =@"\ffmpeg\ffmpeg.exe";
thumbProcstartIfo.Arguments = thumbargs;
thumbProcstartIfo.UseShellExecute =false;
thumbProcstartIfo.CreateNoWindow =true;
thumbProcstartIfo.RedirectStandardOutput =false;
try
{
using (var process =new Process())
{
process.StartInfo = thumbProcstartIfo;
process.Start();
process.WaitForExit();
}
}
catch (InvalidOperationException ex)
{
lblMsg.Text = ex.ToString();
}
Rising Storm Technologies