从ffmpeg保存后无法打开jpg图像 [英] opening jpg image after saving from ffmpeg not working

查看:333
本文介绍了从ffmpeg保存后无法打开jpg图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我正在保存视频,使用ffmpeg将格式转换为.swf。转换和保存视频工作正常,但我在创建缩略图时遇到问题。它保存了picture.jpg,但没有图像。看着缩略图它只有正常的photoviewer标志,这很好,但当我尝试打开图像时,它会给出一条消息

Windows照片查看器:Windows照片查看器无法打开此图片因为文件似乎已损坏,损坏或太大。 (这个图像是2.7MB) - 从我的相机拍摄的照片大约是5MB并打开。



PictureViewer:无法显示image.jpg因为a找不到合适的图形导入器。



画图:画图无法读取此文件。这不是一个有效的位图文件,或者目前不支持它的格式。

图像不会在我保存图像时打开:



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:

tring 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 -ss 1.000 -vframes 1 " + thumbName;
                Process thumbproc = new 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''ve tried these arguments as well, still can''t get the image to work...
It saves, just can''t open it...

//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;







EDIT:







I tried adding the argument to the command prompt to see if it works there but it gave me a message of : [NULL @ 000000000025f7a0] Unable to find a suitable output format for &#39;vframes&#39; vframes: invalid argument The line I used:

<pre lang="c#">>
ffmpeg -i VID2012.3GP vframes 1 VID2012.jpg





编辑:

我改变了一些代码。通过我的代码进行调试没有抛出异常,但是如果我将鼠标指向进程(在它启动之后)它显示类型System.InvalidOperationException的异常






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();
                }

推荐答案

这很简单,但你真正需要的是阅读FFmpeg命令行帮助更多关注。它并不像第一眼看到的那么简单:

http://www.ffmpeg.org /ffmpeg.html [ ^ ]。



-SA
This is simple, but what you really need to is read FFmpeg command-line help paying more attention. It is not as simple as it may look at first glance:
http://www.ffmpeg.org/ffmpeg.html[^].

—SA


这篇关于从ffmpeg保存后无法打开jpg图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆