public void AddMediaInfo(string fName) { var sourceMovie = new MediaInfo(); if (sourceMovie.OpenFromFile(fName)) { var firstVideoTrack = sourceMovie.FirstVideoTrack; if (sourceMovie.AudioTracks.Count > 0 || firstVideoTrack != null) { var targetMovie = new MediaInfo(); sourceMovie.Copyto(targetMovie, false); if (firstVideoTrack != null) { targetMovie.TargetContainer = MediaConvertGUIConfiguration.DefaultContainer; targetMovie.TargetVideoCodec = MediaConvertGUIConfiguration.GetVideoCodecByName("copy"); } // leaving only first audio track while (targetMovie.AudioTracks.Count > 1) { TrackInfo lastAudioTrack = null; foreach (var track in targetMovie.Tracks) { if (track.TrackType == "Audio") { lastAudioTrack = track; } } if (targetMovie.Tracks.Contains(lastAudioTrack)) { targetMovie.Tracks.Remove(lastAudioTrack); } else { break; } } if (targetMovie.AudioTracks.Count > 0) { if (firstVideoTrack != null) { targetMovie.FirstAudioTrack.TargetAudioCodec = MediaConvertGUIConfiguration.GetAudioCodecByName("copy"); } else { targetMovie.FirstAudioTrack.TargetAudioCodec = MediaConvertGUIConfiguration.GetAudioCodecByName("mp3"); } } MoviesInfo.Add(sourceMovie, targetMovie); FillTree(); } } }
private void ThreadMethod() { _currentFileListCount = MoviesInfo.Count; _currentFileListNumber = -1; foreach (var kvp in MoviesInfo) { if (kvp.Value == null) { break; } _currentConvertingMovie = kvp.Value; var info = _currentConvertingMovie.FirstVideoTrack; _currentFileListNumber++; _currentPass = 1; if (_processAbortRequest) { break; } var cmd1 = MediaInfoBase.MakeFFMpegCommand(kvp.Key, kvp.Value, 1); ExecutFFMpegCommand(cmd1, kvp.Value.FFMPEGOutputFileName); if (info != null && _currentConvertingMovie.TargetVideoCodec != MediaConvertGUIConfiguration.GetVideoCodecByName("none")) { // converting 2 pass video var cmd2 = MediaInfoBase.MakeFFMpegCommand(kvp.Key, kvp.Value, 2); if (_processAbortRequest) { break; } _currentPass = 2; if (!String.IsNullOrEmpty(cmd2)) { ExecutFFMpegCommand(cmd2, kvp.Value.FFMPEGOutputFileName); } } } Application.Invoke((_, __) => { applyAction.Sensitive = true; widgetTargetMovieTrack.Editable = true; widgetTargetContainer.Editable = true; widgetSourceContainer.Editable = true; _processthread.Join(); _processthread = null; }); }