Example #1
0
        // convert directory of png images to video
        // overloaded for use with progress bar
        public static void png_to_mp4(string pngTempDir, string outFile, ProgressWindow progform, string fps = "4")
        {
            var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
            var outS   = new NReco.VideoConverter.ConvertSettings();

            outS.CustomInputArgs = "-framerate " + fps;
            outS.CustomInputArgs = "-y " + outS.CustomInputArgs;
            outS.VideoFrameSize  = sys.convsettings["size"];

            //outS.VideoFrameRate = 10;

            /* Got NReco to work a few notes:
             * 1) %05d is the bash syntax for a number that's padded with 0's for 5 digits. i.e. 00349
             * 2) ffmpeg only looks for stills with the file number of 0~4. ie. imagename000.png. If it doesn't find it, it gives "file not found" error.
             * 3) NReco can be found in the folder.
             * conv.convert(); in program to call.
             */

            ffMpeg.ConvertProgress += (o, args) => progHandler(o, args, progform);

            // actual conversion command
            ffMpeg.ConvertMedia(pngTempDir + @"%04d.png", "image2", outFile + @"." + sys.convsettings["format"], sys.convsettings["format"], outS);

            progform.setProgress(100);
            progform.Update();
        }
Example #2
0
        private void buttonConvert_Click(object sender, EventArgs e)
        {
            // make sure they selected a file for conversion
            if (selectListDicom.SelectedItem == null)
            {
                popup.msg("Select a file to be converted.");
                return;
            }


            if (selectListDicom.CheckedItems == null || selectListDicom.CheckedItems.Count <= 0)
            {
                popup.msg("No dicom files selected.");
                return;
            }

            string presetfile = sys.presetPath + dropdownProfiles.SelectedValue;
            IDictionary <string, string> presetsettings = sys.getPresets(presetfile + ".txt");

            buttonConvert.Text    = "Converting";
            buttonConvert.Enabled = false;
            Console.WriteLine(presetsettings.ToString());

            ProgressWindow form2 = new ProgressWindow(selectListDicom.CheckedItems);

            this.Enabled = false;
            foreach (object item in selectListDicom.CheckedItems)
            {
                string toPass = item.ToString();
                form2.textbox(toPass.Substring(toPass.LastIndexOf('|') + 1)); //filename
                form2.progressbar(0);

                form2.Show();
                Application.DoEvents();

                dcm temp = new dcm(sys.dicomsPath + toPass.Substring(toPass.LastIndexOf('|') + 1));

                gui.convert(toPass.Substring(toPass.LastIndexOf('|') + 1), form2, temp.frameRate);
            }
            form2.setProgress(100);
            form2.textbox("Done");
            form2.progtext("Done");
            form2.Update();
            Application.DoEvents();
            Thread.Sleep(2000);
            form2.Close();
            this.Enabled = true;
            this.Focus();
            buttonConvert.Text    = "Convert";
            buttonConvert.Enabled = true;


            initMovList(); //update mov list
        }
Example #3
0
        // progress bar handler to update percentages
        static void progHandler(object o, ConvertProgressEventArgs args, ProgressWindow progform)
        {
            int prog = (int)(100 * (args.Processed.TotalSeconds / args.TotalDuration.TotalSeconds));

            progform.BeginInvoke(new Action(() => {
                //you might think this is a bug. No, this is intentional. Due to the way MS implemented events and progressbar class
                //if the events and/or update goes too fast, the bar not draw the updates. Even after you've slept the process.
                // so this is set as is to make sure that the process *ends* with 100 for the end user. If you want to be a purist
                //prog is set to the proper percentage.
                // *note* --- args.Processed= 00:00:22.7500000/22.75, args.TotalDuration= 00:00:22.7500000/22.75, ((processed*100)/totalduration)=103 ---
                //--- args.Processed= 00:00:22.7500000/22.75, args.TotalDuration= 00:00:22.7500000/22.75, 100 *(processed/totalduration)=100 ---
                //because microsoft.
                progform.setProgress(100);

                progform.Update();
            }));

            Console.WriteLine(String.Format("--- args.Processed= " + args.Processed + "/" + args.Processed.TotalSeconds + ", args.TotalDuration= " + args.TotalDuration + "/" + args.TotalDuration.TotalSeconds.ToString() + ", ((processed*100)/totalduraction)=" + prog + " ---"));
        }
Example #4
0
        // extract all frames from a .dcm file
        // overloaded for use with progress bar
        public static void dcm_to_png(string dcmFile, string pngTempDir, ProgressWindow progform)
        {
            var image  = new DicomImage(dcmFile);
            int frames = image.NumberOfFrames;

            // number format, making sure its prefixed with appropriate number of zeros
            // currently guarantees a four digit number
            // (dont think ive see dicom files with thousands of frames?)
            string fmt = "0000";

            for (int i = 0; i < frames; i++)
            {
                // render each frame as png
                image.RenderImage(i).Save(pngTempDir + i.ToString(fmt) + ".png");

                int iout = (((i + 1) * 100) / frames);

                progform.setProgress(iout);
            }
        }