/// ------------------------------------------------------------------------------------ public static IEnumerable <FFmpegConversionInfo> GetConversions(string fileToConvert) { var iniFile = FileLocator.GetFileDistributedWithApplication("FFmpegConversions.ini"); var ffmpegConversions = new IniDocument(iniFile); var typeToShow = string.Empty; if (FileUtils.AudioFileExtensions.Contains(Path.GetExtension(fileToConvert))) { typeToShow = "audio"; } else if (FileUtils.VideoFileExtensions.Contains(Path.GetExtension(fileToConvert))) { typeToShow = "video"; } for (int i = 0; i < ffmpegConversions.Sections.Count; i++) { var applicableFileType = ffmpegConversions.Sections[i].GetValue("applicableFileType"); if (applicableFileType != null && applicableFileType.Contains(typeToShow)) { yield return(new FFmpegConversionInfo { Name = ffmpegConversions.Sections[i].Name, OutputExtension = ffmpegConversions.Sections[i].GetValue("outputFileExtension"), CommandLine = ffmpegConversions.Sections[i].GetValue("commandLine"), Comments = ffmpegConversions.Sections[i].GetValue("comments"), ApplicableFileType = ffmpegConversions.Sections[i].GetValue("applicableFileType") }); } } if (typeToShow == "video") { yield return(new FFmpegConversionInfo { Name = ConvertMediaDlg.GetFactoryConvertToH263Mp4ConversionName(), OutputExtension = "mp4", CommandLine = "-vb {vb} -codec:v mpeg4 -ab {ab} -codec:a aac -strict -2", ApplicableFileType = "video" }); } yield return(new FFmpegConversionInfo { Name = ConvertMediaDlg.GetFactoryExtractToStandardPcmConversionName(), OutputExtension = "wav", CommandLine = "-vn -codec:a {pcm}", ApplicableFileType = "audio/video" }); yield return(new FFmpegConversionInfo { Name = ConvertMediaDlg.GetFactoryExtractToMp3AudioConversionName(), OutputExtension = "mp3", CommandLine = "-vn -codec:a libmp3lame -ac 1", ApplicableFileType = "audio/video" }); }
public void Setup() { _tempFolder = new TemporaryFolder("ConvertMediaDlgViewModelTests"); _testAudioFileName = MediaFileInfoTests.GetLongerTestAudioFile(); var destFile = Path.Combine(_tempFolder.Path, "test.wav"); File.Move(_testAudioFileName, destFile); _testAudioFileName = destFile; _model = new ConvertMediaDlgViewModel(_testAudioFileName, ConvertMediaDlg.GetFactoryExtractToMp3AudioConversionName()); }
/// ------------------------------------------------------------------------------------ private static bool DoPcmConversion(string inputMediaFile, string outputAudioFile, WaveFormat preferredOutputFormat) { string output; var result = MPlayerHelper.CreatePcmAudioFromMediaFile(inputMediaFile, outputAudioFile, preferredOutputFormat, out output); if ((result & MPlayerHelper.ConversionResult.FinishedConverting) != 0) { // Possibly succeeded if ((result & MPlayerHelper.ConversionResult.PossibleError) > 0) { ReportPossibleConversionProblem(output); } return(true); } // If ffmpeg is available, then try it as a fallback, since Mplayer had problems. if (!FFmpegDownloadHelper.DoesFFmpegForSayMoreExist) { return(false); } var model = new ConvertMediaDlgViewModel(inputMediaFile, ConvertMediaDlg.GetFactoryExtractToStandardPcmConversionName()); model.BeginConversion(null, outputAudioFile, preferredOutputFormat); var finishedState = model.ConversionState & ConvertMediaUIState.AllFinishedStates; if (finishedState == ConvertMediaUIState.FinishedConverting) { if ((model.ConversionState & ConvertMediaUIState.PossibleError) > 0) { ReportPossibleConversionProblem(model.ConversionOutput); } return(File.Exists(outputAudioFile)); } if (finishedState == ConvertMediaUIState.ConversionFailed) { var e = model.ConversionException; if (e != null) { throw e; } } return(false); }
public static void Export(string waveFileDirectoryName, string filenameFilter, string outputFilePath) { try { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; var files = Directory.GetFiles(waveFileDirectoryName, filenameFilter); // sort the files var sorted = new SortedList <float, string>(); foreach (var file in files) { var fileFloat = -1f; if (float.TryParse(Regex.Match(Path.GetFileName(file), @"^[0-9.]+").Value, out fileFloat)) { sorted.Add(fileFloat, file); } } // delete old version of the MP3 file if (File.Exists(outputFilePath)) { File.Delete(outputFilePath); } // if the file still exists, we can't continue if (File.Exists(outputFilePath)) { var msg = LocalizationManager.GetString( "SessionsView.Transcription.TextAnnotation.ExportMenu.AudioExportFileLocked", "Audio export failed because the selected output file already exists and is locked."); throw new Exception(msg); } using (var tempFile = TempFile.WithExtension(".wav")) { // combine the chunks into a single wave file CombineChunks(sorted.Values, tempFile.Path); // convert to MP3 ConvertMediaDlg.Show(tempFile.Path, "Extract audio to mono mp3 audio file (low quality)", outputFilePath); } } finally { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; } }
/// ------------------------------------------------------------------------------------ private void HandleConvertButtonClick(object sender, EventArgs e) { var index = _grid.CurrentCellAddress.Y; var file = (index >= 0 && index < _files.Count() ? _files.ElementAt(index) : null); if (file == null) { SystemSounds.Beep.Play(); return; } var outputFile = ConvertMediaDlg.Show(file.PathToAnnotatedFile, null); if (outputFile != null && PostMenuCommandRefreshAction != null) { PostMenuCommandRefreshAction(outputFile); } }