简体   繁体   English

如何将ffmpeg输出传递给C#中的其他子类?

[英]how to pass ffmpeg output to other sub-class in C#?

i want to pass the thumbnail generated by ffmpeg to save_FTPUpload where the save_FTPUpload function is to upload the image file to ftp server. 我想将ffmpeg生成的缩略图传递给save_FTPUpload,其中save_FTPUpload函数将图像文件上传到ftp服务器。 how can i do that? 我怎样才能做到这一点? here is my example code for thumbnail generation using ffmpeg and "fileupload" function for uploading files to ftp server: 这是我使用ffmpeg和“fileupload”函数生成缩略图的示例代码,用于将文件上传到ftp服务器:

public partial class testtttt : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        generateThumbnail();
        string fi_attachment = @"C:\2.jpg";//source image file
        save_FTPUpload(fi_attachment);
    }

    private void generateThumbnail()
    {
        string thumbpath, thumbname, videofile;

        videofile = "http://www.xxxx.com/video.Avi";
        thumbpath = @"C:\";
        thumbname = thumbpath + Path.GetFileNameWithoutExtension(videofile) + ".jpg";

        string thumbargs = "-i \"" + videofile + "\" -vframes 1 -s 60*30 -ss 00:00:00 -f image2 \"" + thumbname + "\"";

        Process process = new Process();

        process.StartInfo.FileName = Server.MapPath("~\\ffmpeg\\bin\\ffmpeg.exe");
        process.StartInfo.Arguments = thumbargs;

        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardInput = false;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.CreateNoWindow = false;
        process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

        try
        {
            process.Start();
            string output2 = process.StandardError.ReadToEnd();
            string output3 = process.StandardOutput.ReadToEnd();

            if (process != null)
            {
                process.Close();
            }
        }

        catch (Exception)
        {
            this.lblMessage.Text = "Thumbnail created successfuly";//ex.Message.ToString();
        }
    }

    public bool save_FTPUpload(string fi_attachment)
    {
        bool fileSaved = false;
        //string fi_attachment = @"C:\1.jpg";
        string filename = "3.jpg";//image name to be saved in ftp
        string ftp_user = "*****"; //username
        string ftp_pass = "*****"; //password
        string ftpURI = "ftp://www.xxxx.com/thumb/"; //ftp path where the image will be saved

        while (!fileSaved)
        {
            string file_ftpURI = string.Format("{0}/{1}", ftpURI, filename);
            FtpWebRequest file_exist_request = (FtpWebRequest)FtpWebRequest.Create(file_ftpURI);
            file_exist_request.Credentials = new NetworkCredential(ftp_user, ftp_pass);
            file_exist_request.Method = WebRequestMethods.Ftp.GetFileSize;
            try
            {
                FtpWebResponse response = (FtpWebResponse)file_exist_request.GetResponse();
            }
            catch (WebException ex)
            {
                FtpWebResponse response = (FtpWebResponse)ex.Response;
                if (response.StatusCode ==
                    FtpStatusCode.ActionNotTakenFileUnavailable)
                {
                    FtpWebRequest upload_request = (FtpWebRequest)FtpWebRequest.Create(file_ftpURI);
                    upload_request.Credentials = new NetworkCredential(ftp_user, ftp_pass);

                    upload_request.Method = WebRequestMethods.Ftp.UploadFile;
                    upload_request.UsePassive = true;
                    upload_request.UseBinary = true;
                    upload_request.KeepAlive = false;

                    using (var fs = File.OpenRead(fi_attachment))
                    using (Stream upload_request_stream = upload_request.GetRequestStream())
                    {
                        fs.CopyTo(upload_request_stream);
                    }
                    FtpWebResponse upload_response = (FtpWebResponse)upload_request.GetResponse();

                    fileSaved = true;
                    this.Label1.Text = "Upload Successful";
                }
            }
        }
        return fileSaved;
    }

You determine the output filename that ffmpeg will use, so why not use that? 您确定ffmpeg将使用的输出文件名,为什么不使用它?

The file name that is used can also appear in the standard output, but again you already know it because you chose it yourself. 使用的文件名也可以出现在标准输出中,但是您已经知道它了,因为您自己选择了它。

So if generateThumbnail would return thumbname you could pass that to FTPUpload. 因此,如果generateThumbnail将返回thumbname,您可以将其传递给FTPUpload。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM