/// <summary> /// Class constructor, extract the selected data from the interface and store in class members. /// </summary> ConvertVideo(IScripting scripting) { m_scripting = scripting; ISelection selection = m_scripting.GetSelection(); var catalog = m_scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); if (selected.Count == 1) { long video = selected[0]; var entry = catalog.GetVideoFileEntry(video); IUtilities utilities = m_scripting.GetUtilities(); m_SelectedVideoPath = utilities.ConvertToLocalPath(entry.FilePath); m_SelectedVideoTitle = entry.Title; byte[] image_data = catalog.GetVideoFileImage(video); if (image_data == null) { return; } MemoryStream stream = new MemoryStream(image_data); m_VideoImage = System.Drawing.Bitmap.FromStream(stream); } }
/// <summary> /// Call the cmd line tool. The sample just use -i that goes on the file extensions. /// Use the conversion_parameters for more advanced conversions. /// </summary> private void Concat(string out_file, string conversion_parameters) { string tool_path = GetFFMPEGPath(); string tmp_file_path = System.IO.Path.GetTempFileName(); var stream_writer = System.IO.File.CreateText(tmp_file_path); if (stream_writer == null) { System.Windows.MessageBox.Show(tool_path, "Failed to write temporary text file"); return; } ISelection selection = m_scripting.GetSelection(); IUtilities utilities = m_scripting.GetUtilities(); var catalog = m_scripting.GetVideoCatalogService(); string extension = null; string video_format = null; string video_width = null; string video_height = null; string audio_format = null; List <long> selected = selection.GetSelectedVideos(); bool can_do_pure_concat = true; foreach (long video_id in selected) { var entry = catalog.GetVideoFileEntry(video_id); string video_path = utilities.ConvertToLocalPath(entry.FilePath); var extended = catalog.GetVideoFileExtendedProperty((int)video_id); foreach (var prop in extended) { if (prop.Property == "video_Format") { if (video_format == null) { video_format = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video format is " + video_format); } else if (video_format != prop.Value) { string msg = "Aborting. All videos must be in the same video format.\n'"; msg += video_path + "' is in " + prop.Value + "\n"; msg += " previous was in " + video_format + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } else if (prop.Property == "video_Width") { if (video_width == null) { video_width = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video width is " + video_width); } else if (video_width != prop.Value) { string msg = "Aborting. All videos must be in the same dimension.\n'"; msg += video_path + "' width is " + prop.Value + "\n"; msg += " previous was in " + video_width + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } if (prop.Property == "video_Height") { if (video_height == null) { video_height = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video height is " + video_height); } else if (video_height != prop.Value) { string msg = "Aborting. All videos must be in the same dimension.\n'"; msg += video_path + "' height is " + prop.Value + "\n"; msg += " previous was in " + video_height + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } if (prop.Property == "audio_Format") { if (audio_format == null) { audio_format = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Audio format is " + audio_format); } else if (audio_format != prop.Value) { string msg = "Aborting. All videos must be in the same audio format.\n"; msg += video_path + "is in " + prop.Value + "\n"; msg += " previous was in " + audio_format + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } } stream_writer.Write("file '" + video_path + "'"); stream_writer.WriteLine(); // if we can not do a pure concat we abort here. To continue we would need to re-encode the file and that // takes a bit more care and user intervention if (!can_do_pure_concat) { return; } if (extension == null) { int extension_start = video_path.LastIndexOf("."); extension = video_path.Substring(extension_start); } } stream_writer.Close(); if (out_file == null) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "concat" + extension; dlg.DefaultExt = extension; dlg.Filter = "All files|*.*"; Nullable <bool> result = dlg.ShowDialog(); if (result == false) { return; } out_file = dlg.FileName; } // // do concatination // System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = "cmd.exe"; string cmd_line = " -f concat -safe 0 -i " + tmp_file_path + conversion_parameters + " -c copy \"" + out_file + "\""; startInfo.Arguments = "/C " + tool_path + " " + cmd_line; // use /K instead of /C to keep the cmd window up process.StartInfo = startInfo; m_scripting.GetConsole().WriteLine("Running " + startInfo.Arguments); process.Start(); process.WaitForExit(); File.Delete(tmp_file_path); // // Show video in shell player // System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { FileName = out_file, UseShellExecute = true, Verb = "open" }); }
/// <summary> /// Call the cmd line tool. The sample just use -i that goes on the file extensions. /// Use the conversion_parameters for more advanced conversions. /// </summary> public void Concat(string out_file, string conversion_parameters) { string tool_path = GetFFMPEGPath(); string tmp_file_path = System.IO.Path.GetTempFileName(); m_FilesToDelete.Add(tmp_file_path); var stream_writer = System.IO.File.CreateText(tmp_file_path); if (stream_writer == null) { System.Windows.MessageBox.Show(tool_path, "Failed to write temporary text file"); return; } ISelection selection = m_scripting.GetSelection(); IUtilities utilities = m_scripting.GetUtilities(); var catalog = m_scripting.GetVideoCatalogService(); string extension = null; string video_format = null; string video_width = null; string video_height = null; string audio_format = null; var playlist = selection.GetSelectedPlaylist(); int[] all_clip_ids = catalog.GetPlaylistClipIDs(playlist.ID); int part = 1; bool can_do_pure_concat = true; foreach (int clip_id in all_clip_ids) { var clip = catalog.GetVideoClip(clip_id); var video_entry = catalog.GetVideoFileEntry(clip.VideoFileID); string video_path = utilities.ConvertToLocalPath(video_entry.FilePath); var extended = catalog.GetVideoFileExtendedProperty((int)clip.VideoFileID); foreach (var prop in extended) { if (prop.Property == "video_Format") { if (video_format == null) { video_format = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video format is " + video_format); } else if (video_format != prop.Value) { string msg = "Aborting. All videos must be in the same video format.\n'"; msg += video_path + "' is in " + prop.Value + "\n"; msg += " previous was in " + video_format + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } else if (prop.Property == "video_Width") { if (video_width == null) { video_width = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video width is " + video_width); } else if (video_width != prop.Value) { string msg = "Aborting. All videos must be in the same dimension.\n'"; msg += video_path + "' width is " + prop.Value + "\n"; msg += " previous was in " + video_width + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } if (prop.Property == "video_Height") { if (video_height == null) { video_height = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video height is " + video_height); } else if (video_height != prop.Value) { string msg = "Aborting. All videos must be in the same dimension.\n'"; msg += video_path + "' height is " + prop.Value + "\n"; msg += " previous was in " + video_height + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } if (prop.Property == "audio_Format") { if (audio_format == null) { audio_format = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Audio format is " + audio_format); } else if (audio_format != prop.Value) { string msg = "Aborting. All videos must be in the same audio format.\n"; msg += video_path + "is in " + prop.Value + "\n"; msg += " previous was in " + audio_format + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } } if (extension == null) { int extension_start = video_path.LastIndexOf("."); extension = video_path.Substring(extension_start); } if (can_do_pure_concat) { string out_path = GetTempFolder() + "clip_" + part + extension; part = part + 1; SaveClip(video_path, clip.StartTime, clip.EndTime, out_path); stream_writer.Write("file '" + out_path + "'"); stream_writer.WriteLine(); } else { selection.SetSelectedPlaylistClip(clip_id); // select the offending clip // if we can not do a pure concat we abort here. To continue we would need to re-encode the file and that // takes a bit more care and user intervention return; } } stream_writer.Close(); if (out_file == null) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "concat" + extension; dlg.DefaultExt = extension; dlg.Filter = "All files|*.*"; Nullable <bool> result = dlg.ShowDialog(); if (result == false) { return; } out_file = dlg.FileName; } RunFFMPEG("-f concat - safe 0 - i " + tmp_file_path + conversion_parameters + " - c copy \"" + out_file + "\""); PlayVideo(out_file); }
static public void Run(IScripting scripting, string argument) { scripting.GetConsole().Clear(); var catalog = scripting.GetVideoCatalogService(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { try { var entry = catalog.GetVideoFileEntry(video); IUtilities utilities = scripting.GetUtilities(); var selected_path = utilities.ConvertToLocalPath(entry.FilePath); var file = ShellFile.FromFilePath(selected_path); var selected_videos = new long[1]; selected_videos[0] = video; var TagInstances = catalog.GetTagsForVideos(selected_videos); List <string> tag_list = new List <string>(); foreach (var tag in TagInstances) { tag_list.Add(tag.Name); } scripting.GetConsole().Write("Tagging : " + selected_path + " ..."); ShellPropertyWriter propertyWriter = file.Properties.GetPropertyWriter(); propertyWriter.WriteProperty(SystemProperties.System.Keywords, tag_list.ToArray()); int Rating = 0; if (entry.Rating == 1) { Rating = 1; } if (entry.Rating == 2) { Rating = 25; } if (entry.Rating == 3) { Rating = 50; } if (entry.Rating == 4) { Rating = 75; } if (entry.Rating == 5) { Rating = 99; } propertyWriter.WriteProperty(SystemProperties.System.Rating, Rating); propertyWriter.WriteProperty(SystemProperties.System.Comment, entry.Description); propertyWriter.Close(); scripting.GetConsole().WriteLine("Done "); } catch (Exception ex) { scripting.GetConsole().WriteLine(ex.Message); } } }