public static string getVideoExtString(EDanbiVideoExt vidType) { switch (vidType) { case EDanbiVideoExt.mp4: return(".mp4"); case EDanbiVideoExt.avi: return(".avi"); case EDanbiVideoExt.m4v: return(".m4v"); case EDanbiVideoExt.mov: return(".mov"); case EDanbiVideoExt.webm: return(".webm"); case EDanbiVideoExt.wmv: return(".wmv"); default: return(".error"); } }
void Awake() { Application.runInBackground = true; DanbiComputeShader.onSampleFinished += (RenderTexture converged_resultRT) => m_distortedRT = converged_resultRT; // Should it be also added in DanbiImageWriter.cs?? **MOON** DanbiUIVideoGeneratorGeneratePanel.onVideoSave += () => m_isSaving = true; DanbiUIVideoGeneratorVideoPanel.onVideoPathAndNameChange += (string videoName) => m_vidName = videoName; DanbiUIVideoGeneratorFileOptionPanel.onVideoExtChange += (EDanbiVideoExt ext) => m_videoExt = ext; DanbiUIVideoGeneratorFileOptionPanel.onVideoCodecChange += (EDanbiOpencvCodec_fourcc_ codec) => m_videoCodec = codec; DanbiUIVideoGeneratorFileOptionPanel.onTargetFrameRateChange += (int targetFrameRate) => m_targetFrameRate = targetFrameRate; DanbiUIVideoGeneratorFileOptionPanel.onSavedVideoPathAndNameChange += (string savedVideoPathAndName) => m_savedVideoPathAndName = savedVideoPathAndName; DanbiUIVideoGeneratorFileOptionPanel.onSavedVideoPathChange += (string videoPath) => m_savedVideoPath = videoPath; }
protected override void LoadPreviousValues(params Selectable[] uiElements) { // load previous video path string prevVidPathOnly = PlayerPrefs.GetString("VideoGeneratorFileOption-vidPath", default); if (!string.IsNullOrEmpty(prevVidPathOnly)) { m_videoPath = prevVidPathOnly; Panel.transform.GetChild(5).GetComponent <TMP_Text>().text = m_videoPath; onSavedVideoPathChange?.Invoke(m_videoPath); } // load previous video name string prevVidNameOnly = PlayerPrefs.GetString("VideoGeneratorFileOption-vidNameOnly", default); if (!string.IsNullOrEmpty(prevVidNameOnly)) { m_videoName = prevVidNameOnly; Panel.transform.GetChild(1).GetComponent <TMP_InputField>().text = m_videoName; } // load previous video (format)extension var prevVidExtOnly = (EDanbiVideoExt)PlayerPrefs.GetInt("VideoGeneratorFileOption-vidExtOnly", default); m_videoExt = prevVidExtOnly; Panel.transform.GetChild(2).GetComponent <TMP_Dropdown>().value = (int)m_videoExt; onVideoExtChange?.Invoke(m_videoExt); // load previous video codec. var prevVidCodec = (EDanbiOpencvCodec_fourcc_)PlayerPrefs.GetInt("VideoGeneratorFileOption-vidCodec", default); m_videoCodec = prevVidCodec; Panel.transform.GetChild(3).GetComponent <TMP_Dropdown>().value = (int)m_videoCodec; onVideoCodecChange?.Invoke(m_videoCodec); // load previous target frame rate. var prevTargetFrameRate = PlayerPrefs.GetInt("VideoGeneratorFileOption-targetFrameRate", default); m_targetFrameRate = prevTargetFrameRate; Panel.transform.GetChild(4).GetComponent <TMP_InputField>().text = m_targetFrameRate.ToString(); onTargetFrameRateChange?.Invoke(m_targetFrameRate); }
// References. // https://infodbbase.tistory.com/90 // https://trac.ffmpeg.org/wiki/Concatenate#differentcodec <- ffmpeg concat cmd arguments // http://mwultong.blogspot.com/2006/11/dos-file-copy-command.html <- copy/ move cmd arguments /// <summary> /// /// </summary> /// <param name="targetFileNames"></param> /// <param name="outputFileName"></param> /// <param name="ffmpegExecutableLocation"></param> public static System.Collections.IEnumerator ConcatVideoClips(string ffmpegExecutableLocation, string outputFileLocation, string outputFileName, string[] targetFileNames, EDanbiVideoExt ext) { // cmd argument "merging video with ffmpeg.exe" // ffmpeg -f concat -safe 0 -i VideoList.txt(target video clips names) -c copy output.mp4(output video file name) // string arg = $"ffmpeg -f concat -safe 0 -i {targetVideoClipFiles} -c copy {outputFileName}"; string extstr = DanbiFileExtensionHelper.getVideoExtString(ext); string outputFinal = $"{outputFileName}{extstr}"; DanbiUtils.Log(outputFinal, EDanbiStringColor.teal); // Write the target video clips. using (var writer = new System.IO.StreamWriter($"{outputFileLocation}/{outputFileName}.txt", true)) { for (var i = 0; i < targetFileNames.Length; ++i) { if (!string.IsNullOrEmpty(targetFileNames[i])) { writer.WriteLine($"file '{targetFileNames[i]}'"); } } writer.Close(); } if (new System.IO.FileInfo($"{outputFileLocation}/{outputFinal}").Exists) { System.IO.File.Delete($"{outputFileLocation}/{outputFinal}"); yield return(null); } string arg = $"ffmpeg -f concat -safe 0 -i {outputFileName}.txt -c copy {outputFinal}"; // DanbiUtils.Log(arg, EDanbiStringColor.teal); DanbiFileSys.OpenProcessWithArguments(outputFileLocation, arg); System.Diagnostics.Process.Start(@"" + outputFileLocation); }
protected override void AddListenerForPanelFields() { base.AddListenerForPanelFields(); var panel = Panel.transform; // bind video save location text var videoSaveLocationText = panel.GetChild(5).GetComponent <TMP_Text>(); // bind video save path button. var vidSavePathButton = panel.GetChild(0).GetComponent <Button>(); vidSavePathButton.onClick.AddListener(() => StartCoroutine(Coroutine_SaveFilePath(videoSaveLocationText))); // bind video name inputfield. var vidNameInputField = panel.GetChild(1).GetComponent <TMP_InputField>(); vidNameInputField.onValueChanged.AddListener( (string val) => { m_videoName = val; videoSaveLocationText.text = $"File Location : {m_savePathAndName}"; } ); // bind video extension dropdown var vidExtOptions = new List <string> { ".mp4", ".avi", "m4v", ".mov", ".webm", ".wmv" }; var vidExtDropdown = panel.GetChild(2).GetComponent <TMP_Dropdown>(); vidExtDropdown.AddOptions(vidExtOptions); vidExtDropdown.onValueChanged.AddListener( (int option) => { // vidExtOnly = vidExtOptions[option]; m_videoExt = (EDanbiVideoExt)option; onVideoExtChange?.Invoke(m_videoExt); videoSaveLocationText.text = $"File Location : {m_savePathAndName}"; } ); // bind video codect dropdown var vidCodecOptions = new List <string> { "h264", "h265", "divx", "mpeg4", "hevc" }; var vidCodecDropdown = panel.GetChild(3).GetComponent <TMP_Dropdown>(); vidCodecDropdown.AddOptions(vidCodecOptions); vidCodecDropdown.onValueChanged.AddListener( (int option) => { m_videoCodec = (EDanbiOpencvCodec_fourcc_)option; onVideoCodecChange?.Invoke(m_videoCodec); } ); // bind video target frame rate var vidTargetFrameRateInputField = panel.GetChild(4).GetComponent <TMP_InputField>(); vidTargetFrameRateInputField.onValueChanged.AddListener( (string val) => { if (int.TryParse(val, out var res)) { m_targetFrameRate = res; onTargetFrameRateChange?.Invoke(m_targetFrameRate); } } ); LoadPreviousValues(); }