Ejemplo n.º 1
0
 public void button3_Click(object sender, EventArgs e)
 {
     if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
     {
         Save_Gif S = new Save_Gif();
         S.trackBar1.Visible = false;
         //S.label1.Visible = false;
         S.label1.Text   = "Choose a target framerate.";
         S.textBox2.Text = "30";
         S.Text          = "Frame sequence framerate";
         S.ShowDialog();
         if (S.OK)
         {
             ExportSequence(folderBrowserDialog1.SelectedPath, (int)float.Parse(S.textBox1.Text));
         }
     }
 }
Ejemplo n.º 2
0
        public void SaveVideo(bool preparevideo = true)
        {
            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string file = saveFileDialog1.FileName;

            /*Save_Gif S = new Save_Gif();
             * S.trackBar1.Visible = false;
             * //S.label1.Visible = false;
             * S.label1.Text = "Choose a target framerate.";
             * S.textBox2.Text = "30";
             * S.Text = "Frame sequence framerate(Video)";
             * S.ShowDialog();
             * if (!S.OK)
             * {
             *  return;
             * }*/

            UseWaitCursor         = true;
            advmenu.UseWaitCursor = true;

            int delay = GetFramedelay();
            int fps   = (int)(1000f / delay);

            if (fps > 30)
            {
                Save_Gif S = new Save_Gif();
                S.trackBar1.Visible = false;
                //S.label1.Visible = false;
                S.label1.Text   = "Choose a target framerate.";
                S.textBox2.Text = "" + fps;
                S.Text          = "Frame sequence framerate(Video)";
                S.ShowDialog();
                if (!S.OK)
                {
                    return;
                }
                delay = (int)float.Parse(S.textBox1.Text);
                fps   = (int)float.Parse(S.textBox2.Text);
            }
            //int delay = (int)float.Parse(S.textBox1.Text);
            //int fps = (int)float.Parse(S.textBox2.Text);
            if (preparevideo)
            {
                if (!Directory.Exists("Fseq"))
                {
                    Directory.CreateDirectory("Fseq");
                }
                else
                {
                    string[] f = Directory.GetFiles("Fseq");
                    int      i = 0;
                    while (i < f.Length)
                    {
                        File.Delete(f[i]);
                        i++;
                    }
                }
                //gif does not work with variable image sizes.
                ExportSequence("Fseq\\", delay, file.EndsWith(".gif"));
            }

            /*if (File.Exists(file))
             * {
             *  File.Delete(file);
             * }*/
            string Acmd = "";

            if (/*audioenabled*/ advmenu.checkBox1.Checked && advmenu.label1.Text != "")
            {
                //-q:a 3
                //Acmd = "-i \"" + advmenu.label1.Text + "\" "+ "-b:a 192k ";
                Acmd = "-i \"" + advmenu.label1.Text + "\" " + "-b:a 160k ";
            }

            string video_args = VideoArg;
            string vinput     = "-framerate " + fps + "/1 -i Fseq/frame%05d.png ";

            if (file.EndsWith(".png"))
            {
                //tell ffmpeg to produce an animated png.
                video_args = VideoArg + "-f apng ";
            }
            if (file.EndsWith(".gif"))
            {
                string command = "ffmpeg " + vinput + " -vf \"fps=" + fps + ",scale=" + F.img[0].Width + ":-1:flags=lanczos, palettegen\" -y /tmp/palette.png";
                Process.Start("CMD.exe", "/C " + command).WaitForExit();

                command = "ffmpeg " + vinput + " -i /tmp/palette.png -lavfi \"fps=" + fps + ",scale=" + F.img[0].Width + ":-1:flags=lanczos [x]; [x][1:v] paletteuse\" -y \"" + file + "\"";
                Process.Start("CMD.exe", "/C " + command);
            }
            else
            {
                string strCmdText;
                //string command = "ffmpeg -loop 1 -framerate 1/5 -i img%%03d.png -i music.mp3 -c:v libx264 -r 30 -pix_fmt yuv420p -shortest out.mp4";
                //string command = "ffmpeg -framerate 1/"+fps+" -i img%%03d.png -i music.mp3 -c:v libx264 -r 30 -pix_fmt yuv420p -shortest out.mp4";
                //string command = "ffmpeg -framerate 1/" + fps + " -i Fseq/frame%%05d.png -i music.mp3 -c:v libx264 -r 30 -pix_fmt yuv420p -shortest \""+saveFileDialog1.FileName+"\"";
                //string command = "ffmpeg -framerate 1/" + fps + " -i Fseq/frame%%05d.png "+Acmd+"-r 30 -pix_fmt yuv420p \"" + saveFileDialog1.FileName + "\"";
                //string command = "ffmpeg -framerate 1/" + fps + " -i Fseq/frame%05d.png " + Acmd + "-c:v libx264 -r 30 -pix_fmt yuv420p \"" + saveFileDialog1.FileName + "\"";
                //string command = "ffmpeg -framerate " + fps + "/1 -i Fseq/frame%05d.png " + Acmd + "-c:v libx264 -r 30 -pix_fmt yuv420p -shortest \"" + saveFileDialog1.FileName + "\"";
                //string command = "ffmpeg " + PreArg + "-framerate " + fps + "/1 -i Fseq/frame%05d.png " + video_args + Acmd + "-r 30 -pix_fmt yuv420p -shortest \"" + saveFileDialog1.FileName + "\"";
                string command = "ffmpeg " + PreArg + vinput + video_args + Acmd + "-r " + fps + " -pix_fmt yuv420p -shortest -y \"" + saveFileDialog1.FileName + "\"";
                strCmdText = /*"/C " + */ command;
                //strCmdText = "/C copy /b Image1.jpg + Archive.rar Image2.jpg";
                System.Diagnostics.Process.Start("CMD.exe", "/C " + strCmdText);
            }

            /*Process cmd = new Process();
             * cmd.StartInfo.FileName = "cmd.exe";
             * //cmd.StartInfo.RedirectStandardInput = true;
             * cmd.StartInfo.RedirectStandardOutput = true;
             * //cmd.StartInfo.CreateNoWindow = true;
             * cmd.StartInfo.UseShellExecute = false;
             * cmd.Start();
             *
             * cmd.StandardInput.WriteLine(command);
             * cmd.StandardInput.Flush();*/
            UseWaitCursor         = false;
            advmenu.UseWaitCursor = false;
        }