private Task <Stream> ExtractAudio(Stream stream) { var flvFile = new FlvFile(stream); { flvFile.ConversionProgressChanged += (sender, args) => { AudioExtractionProgressChanged?.Invoke(this, args); }; return(flvFile.ExtractStreams()); } }
private async void button1_Click(object sender, EventArgs e) { //var videos = DownloadUrlResolver.GetDownloadUrls("https://www.youtube.com/watch?v=rTKHB_tVYpk"); //VideoInfo video = videos // .OrderByDescending(info => info.AudioBitrate) // .First(); //await Task.Factory.StartNew(() => //{ // var audioDownload = new AudioDownloader(video, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.mp3")); // audioDownload.DownloadProgressChanged += (s, args) => Console.WriteLine(args.ProgressPercentage * 0.85); // audioDownload.AudioExtractionProgressChanged += (s, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15); // audioDownload.Execute(); //}); string path = Path.Combine(@"D:\Recordings\Obs", "Haytam.flv"); FlvFile flvFile = new FlvFile(path, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.mp3")); flvFile.ConversionProgressChanged += (s, ea) => Console.WriteLine(ea.ProgressPercentage); flvFile.ExtractStreams(); flvFile.Dispose(); }
private Task SplitTaskDirectory(string inputVideoPath, string outputDirectoryPath, VideoConvertConfig config) { return(new Task(() => { var progress = 0; SetProgressBar(progress); var flvs = Util.GetAllFlvList(inputVideoPath); SetLabel4(flvs.Count); if (flvs.Count > 0) { var halfProgress = 50 / flvs.Count; using (var engine = new Engine()) { foreach (var flv in flvs) { var inputFile = new MediaFile(flv); var outputFile = new MediaFile(); if (config.OutputSameAsInput || string.IsNullOrWhiteSpace(outputDirectoryPath) || !Directory.Exists(outputDirectoryPath)) { outputDirectoryPath = Path.GetDirectoryName(flv); } var mp4File = new MediaFile(Path.Combine(outputDirectoryPath ?? throw new ArgumentNullException(nameof(outputDirectoryPath)), $@"{Path.GetFileNameWithoutExtension(flv)}.mp4")); //flv转封装成MP4 if (config.IsSkipSameMp4 && File.Exists(mp4File.Filename)) { //do nothing } else if (config.UseFlvFix) { using (var flvFile = new FlvFile(inputFile.Filename)) { flvFile.ExtractStreams(true, true, false, true); engine.CustomCommand(string.Format(MuxCommand, flvFile.VideoPath, flvFile.AudioPath, mp4File.Filename)); File.Delete(flvFile.VideoPath); File.Delete(flvFile.AudioPath); } } else { engine.CustomCommand(string.Format(ConvertCommand, inputFile.Filename, mp4File.Filename)); } progress += halfProgress; SetProgressBar(progress); if (!config.OnlyConvert) { //分段 if (Util.GetFileSize(mp4File.Filename) > Limit * 1024 / 8) { engine.GetMetadata(mp4File); var vb = mp4File.Metadata.VideoData.BitRateKbs ?? 0; var ab = mp4File.Metadata.AudioData.BitRateKbs; var maxDuration = TimeSpan.FromSeconds(Convert.ToDouble(Limit) / (vb + ab)); var duration = mp4File.Metadata.Duration; var now = TimeSpan.Zero; for (var i = 0; now < duration; ++i) { var t = Duration; if (now + maxDuration >= duration) { t = duration - now; } outputFile.Filename = Path.Combine(outputDirectoryPath, $@"{Path.GetFileNameWithoutExtension(mp4File.Filename)}_{i + 1}.mp4"); engine.CustomCommand(string.Format(SplitCommand, now, t, mp4File.Filename, outputFile.Filename)); engine.GetMetadata(outputFile); now += t; progress += Convert.ToInt32(Convert.ToDouble(now.Ticks) / duration.Ticks * halfProgress); SetProgressBar(progress); } } } else { progress += halfProgress; SetProgressBar(progress); } if (config.DeleteFlv && Util.IsFlv(inputFile.Filename)) { if (config.IsSendToRecycleBin) { FileSystem.DeleteFile(inputFile.Filename, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else { File.Delete(inputFile.Filename); } } } } } SetProgressBar(100); MessageBox.Show($@"{inputVideoPath} 完成!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information); })); }
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { if (radioButton1.Checked == true) { if (!viddling.Contains("flv")) { label1.Text = "Status: Ready"; File.Copy(viddling, mp4out); File.Delete(viddling); } else { this.Cursor = Cursors.WaitCursor; ProcessStartInfo psi = new ProcessStartInfo(); string startdir = Directory.GetCurrentDirectory(); if (Environment.Is64BitOperatingSystem) { psi.FileName = ffmpeg + @"\Data\ffmpeg-64.exe"; } else { psi.FileName = ffmpeg + @"\Data\ffmpeg-32.exe"; } string convert = viddling; psi.Arguments = string.Format("-i \"{0}\" -y -sameq -ar 22050 \"{1}\"", viddling, mp4out); psi.WindowStyle = ProcessWindowStyle.Normal; Process p = Process.Start(psi); p.WaitForExit(); if (p.HasExited == true) { this.Cursor = Cursors.Default; File.Delete(viddling); } } } else if (radioButton2.Checked == true) { if (RipLeech.Properties.Settings.Default.ffmpeg == true) { this.Cursor = Cursors.WaitCursor; Process proc = new Process(); string convert = viddling; string bitrate = RipLeech.Properties.Settings.Default.audioquality; if (Environment.Is64BitOperatingSystem) { proc.StartInfo.FileName = ffmpeg + @"\Data\ffmpeg-64.exe"; } else { proc.StartInfo.FileName = ffmpeg + @"\Data\ffmpeg-32.exe"; } proc.StartInfo.Arguments = string.Format("-i \"{0}\" -vn -y -f mp3 -ab 320k \"{1}\"", viddling, vidout); proc.StartInfo.RedirectStandardError = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; if (!proc.Start()) { listBox1.Items.Add("Error starting"); return; } StreamReader reader = proc.StandardError; string line; while ((line = reader.ReadLine()) != null) { listBox1.Items.Add(line); } proc.Close(); try { System.IO.StreamWriter sw = new System.IO.StreamWriter(Directory.GetCurrentDirectory() + @"\ffmpeg.log"); foreach (object item in listBox1.Items) { sw.WriteLine(item.ToString()); } sw.Close(); } catch { } button6.Visible = true; if (File.Exists(viddling)) { File.Delete(viddling); if (File.Exists(vidout)) { string mymusic = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\" + vidname; //MessageBox.Show(mymusic); if (!String.IsNullOrEmpty(RipLeech.Properties.Settings.Default.audiosavepath)) { File.Copy(vidout, RipLeech.Properties.Settings.Default.audiosavepath + @"\" + vidname); } else { if (!File.Exists(mymusic)) { File.Copy(vidout, mymusic); } } File.Delete(vidout); } } this.Cursor = Cursors.Default; } else { //non ffmpeg functions var flvFile = new FlvFile(viddling, root + @"\" + vidname); flvFile.ExtractStreams(); if (File.Exists(viddling)) { File.Delete(viddling); if (File.Exists(vidout)) { string mymusic = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\" + vidname; //MessageBox.Show(mymusic); if (!File.Exists(mymusic)) { File.Copy(vidout, mymusic); } File.Delete(vidout); } } } } else { } if (timer1.Enabled == true) { timer1.Stop(); timer1.Enabled = false; } label1.Text = "Status: Complete"; progressBar1.Value = 0; button4.Visible = true; button8.Visible = true; }