// 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(); }
private void button2_Click(object sender, EventArgs e) { string input = @"C:\Users\a\Videos\Debut\Untitled 7.avi"; string output = "C:\\test3.avi"; var setting = new NReco.VideoConverter.ConvertSettings(); setting.SetVideoFrameSize(1280, 720); setting.CustomInputArgs = "-ss 00:00:00 -t 00:00:10"; // setting.CustomOutputArgs = "-vf vflip"; setting.CustomOutputArgs = "-vf \"movie=logo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\""; // Top left corner //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:10 [out]" outputvideo.flv //Top right corner //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]" outputvideo.flv //Bottom left corner //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:main_h-overlay_h-10 [out]" outputvideo.flv //Bottom right corner //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]" outputvideo.flv var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); ffMpeg.ConvertProgress += FfMpeg_ConvertProgress; ffMpeg.GetVideoThumbnail(input, "temp.jpg", 10.0f); System.IO.FileStream hStream = new System.IO.FileStream("temp.jpg", System.IO.FileMode.Open); this.pictureBox1.Image = Image.FromStream(hStream); // FileStream を閉じる (正しくは オブジェクトの破棄を保証する を参照) hStream.Close(); return; //ffMpeg.ConvertMedia(input, null, output, null, setting); ffMpeg.ConvertMedia(input, null, output, NReco.VideoConverter.Format.mp4, setting); // NReco.VideoConverter.ConcatSettings set = new NReco.VideoConverter.ConcatSettings(); set.SetVideoFrameSize(640, 480); //ffMpeg.ConcatMedia(_fileNames, videoRootPath + tobename + ".mp4", NReco.VideoConverter.Format.mp4, set); this.Text = "FINISH"; }
public void Create(string input) { if (File.Exists(output)) { File.Delete(output); } transparent.Save("logo.png", System.Drawing.Imaging.ImageFormat.Png); var setting = new NReco.VideoConverter.ConvertSettings(); setting.SetVideoFrameSize(1280, 720); setting.CustomInputArgs = "-ss 00:00:00 -t 00:00:05"; // setting.CustomOutputArgs = "-vf vflip"; setting.CustomOutputArgs = "-vf \"movie=logo.png [watermark]; [in][watermark] overlay=10:10 [out]\""; //setting.CustomOutputArgs = "-vf \"setsar=sar=1/1\""; var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); ffMpeg.ConvertMedia(input, null, tempout, NReco.VideoConverter.Format.mp4, setting); string cmdParams = "-i opening.mp4 -i temp.mp4 -filter_complex \"[0:0] [1:0] concat=n=2:v=1:a=0:unsafe=1\" " + output; try { Execute("ffmpeg.exe", cmdParams); MessageBox.Show("FINISHED"); } catch { MessageBox.Show("結合失敗。"); } //NReco.VideoConverter.ConcatSettings set = new NReco.VideoConverter.ConcatSettings(); //set.ConcatAudioStream = false; ////set.SetVideoFrameSize(640, 480); //string[] inputfiles = { "opening.mp4", tempout }; //ffMpeg.ConcatMedia(inputfiles, output, NReco.VideoConverter.Format.mp4, set); //this.Text = "FINISH"; }
// convert directory of png images to video public static Boolean png_to_mp4(string pngTempDir, string outFile, 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"]; /* 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.ConvertMedia(pngTempDir + @"%04d.png", "image2", outFile + @"." + sys.convsettings["format"], sys.convsettings["format"], outS); return(false); }
/// <summary> /// Converts the video in mp4 format with normalized settings. /// </summary> public void convertVideo(int width, int height, int frameRate) { var setting = new NReco.VideoConverter.ConvertSettings(); setting.SetVideoFrameSize(width, height); setting.VideoFrameRate = frameRate; setting.VideoCodec = "h264"; setting.AudioCodec = "ac3"; var converter = new NReco.VideoConverter.FFMpegConverter(); ffMpegConverter.ConvertMedia(filePath, null, // autodetect by input file extension filePath + ".mp4", null, // autodetect by output file extension setting ); this.filePath = this.filePath + ".mp4"; this.converted = true; }
public void ExportVideo(ProgressDialogController progress) { string inputFile = @Manager.Match.VideoFile; string videoName = Manager.Match.VideoFile.Split('\\').Last(); videoName = videoName.Split('.').First(); Directory.CreateDirectory(@Location); string collectionName = @Location + @"\" + Manager.ActivePlaylist.Name + "_collection.mp4"; int rallyCount = Manager.ActivePlaylist.Rallies.Count(); int sum = 0; for (int s = 1; s <= rallyCount; s++) { sum = sum + s; } if (rallyCollection) { progressBar = sum * 2; } else { progressBar = sum; } currentProgress = 0; string[] RallyCollection = new string[rallyCount]; string[] ConcatRally = new string[2]; progress.Minimum = 0; progress.Maximum = progressBar; progress.SetProgress(0); for (int i = 0; i < rallyCount; i++) { progress.SetMessage("Export Playlist '" + Manager.ActivePlaylist.Name + "': \n\nRally " + (i + 1) + " is being created..."); Rally curRally = Manager.ActivePlaylist.Rallies[i]; string RallyNumber = curRally.Number.ToString(); string RallyScore = curRally.CurrentRallyScore.ToString(); RallyScore = RallyScore.Replace(":", "-"); string SetScore = curRally.CurrentSetScore.ToString(); SetScore = SetScore.Replace(":", "-"); string fileName = @Location + @"\#" + RallyNumber + "_" + RallyScore + " (" + SetScore + ").mp4"; RallyCollection[i] = fileName; var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); NReco.VideoConverter.ConvertSettings settings = new NReco.VideoConverter.ConvertSettings() { Seek = Convert.ToSingle(curRally.Start / 1000), MaxDuration = Convert.ToSingle((curRally.End - curRally.Start) / 1000), //VideoFrameSize = NReco.VideoConverter.FrameSize.hd720, AudioCodec = "copy", VideoCodec = "copy" }; ffMpeg.ConvertMedia(@Manager.Match.VideoFile, null, fileName, null, settings); currentProgress = currentProgress + (i + 1); progress.SetProgress(currentProgress); } if (rallyCollection) { progress.SetMessage("\n Collection is currently being created! \n\nIt may take a while..."); var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); ffMpeg.ConvertProgress += UpdateProgress; NReco.VideoConverter.ConcatSettings settings = new NReco.VideoConverter.ConcatSettings(); ffMpeg.ConcatMedia(RallyCollection, @Location + @"\" + Manager.ActivePlaylist.Name + "_collection(" + rallyCount + ").mp4", NReco.VideoConverter.Format.mp4, settings); progress.SetProgress(progressBar); } if (!singleRallies) { for (int i = 0; i < rallyCount; i++) { File.Delete(RallyCollection[i]); } } }
void job(object sender, DoWorkEventArgs e) { // The sender is the BackgroundWorker object we need it to // report progress and check for cancellation. //NOTE : Never play with the UI thread here... CheckedListBox.CheckedItemCollection checklist = (CheckedListBox.CheckedItemCollection)e.Argument; foreach (object file in checklist) { string toPass = file.ToString(); string dicomScan = toPass.Substring(toPass.LastIndexOf('|') + 1); string tempScanDirectory = sys.stillsPath + dicomScan + @"\"; if (!Directory.Exists(tempScanDirectory)) { Directory.CreateDirectory(tempScanDirectory); } string pngTempDir = tempScanDirectory; var image = new DicomImage(sys.dicomsPath + dicomScan); 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 a jpg image.RenderImage(i).Save(pngTempDir + i.ToString(fmt) + ".png"); bgWorker.ReportProgress((int)i * 50 / frames); } int fps = 4; string outFile = sys.outPath + dicomScan.Replace(@"\", ""); var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); var outS = new NReco.VideoConverter.ConvertSettings(); outS.CustomInputArgs = "-framerate " + fps; outS.VideoFrameSize = sys.convsettings["size"]; ffMpeg.ConvertProgress += (o, args) => { bgWorker.ReportProgress((int)(args.Processed.Seconds / (args.TotalDuration.Seconds * 100))); }; // just need to make this less hardcoded ffMpeg.ConvertMedia(pngTempDir + @"%04d.png", "image2", outFile + @"." + sys.convsettings["format"], sys.convsettings["format"], outS); if (bgWorker.CancellationPending) { // Set the e.Cancel flag so that the WorkerCompleted event // knows that the process was cancelled. e.Cancel = true; bgWorker.ReportProgress(0); return; } } //Report 100% completion on operation completed bgWorker.ReportProgress(100); }