private void CacheTextureData(byte[] data, int textureId) { Log.Info("Font: Saving texture data to cache..."); string texturePath = Path.Combine(Program.cachePath, GetCacheFilename() + "_" + textureId.ToString() + ".png"); FFmpegHelper.SaveImagePNG(texturePath, data, textureSize, textureSize); }
private static async Task ReplaceBackgroundColorAsync() { var input = "/Users/colin/Downloads/macos64/src.mp4"; var output = "/Users/colin/Downloads/macos64/src-3.mp4"; await FFmpegHelper.ReplaceBackgroundAsync(input, output, "70de77", 0.1f, 0.2f, "000000", 640, 480, TimeSpan.FromSeconds(10)); }
/// <summary> /// 提取音频事件 /// </summary> private async void ExecuteExtractAudioCommand() { if (isExtracting) { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipWaitTaskFinished")); return; } if (VideoPath == "") { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipNoSeletedVideo")); return; } // 音频文件名 string audioFileName = VideoPath.Remove(VideoPath.Length - 4, 4) + ".aac"; Status = string.Empty; await Task.Run(() => { // 执行提取音频程序 isExtracting = true; FFmpegHelper.ExtractAudio(VideoPath, audioFileName, new Action <string>((output) => { Status += output + "\n"; })); isExtracting = false; }); }
private static async Task ConvertToAsync() { var input = "/Users/colin/Downloads/macos64/src.mp4"; var output = "/Users/colin/Downloads/macos64/src-1.mp4"; await FFmpegHelper.ConvertToAsync(input, output, TimeSpan.FromSeconds(5)); }
private static async Task ExtractVideoAsync() { var input = "/Users/colin/Downloads/input.mov"; var output = "/Users/colin/Downloads/output.mov"; await FFmpegHelper.ExtractVideoAsync(input, output, TimeSpan.Parse("00:01:00"), TimeSpan.Parse("00:01:30")); }
private static async Task ExtractVideoAsync() { var input = "/Users/zhangcheng/Desktop/macos64/src.mp4"; var output = "/Users/zhangcheng/Desktop/macos64/src-2.mp4"; await FFmpegHelper.ExtractVideoAsync(input, output, TimeSpan.Parse("00:01:04"), TimeSpan.Parse("00:01:13")); }
private byte[] getVideoThumbnail(FileAsset file) { var thumb_path = Path.Combine(MyFileFolder.Thumbs, file.file_id.ToString() + ".thumb.mp4"); if (File.Exists(thumb_path)) { File.Delete(thumb_path); } var file_path = Path.Combine(MyFileFolder.Photo, file.saved_path); var videoWidth = getVideoWidth(file_path); if (videoWidth <= 0) { return(null); } if (videoWidth > 720) { FFmpegHelper.MakeVideoThumbnail720(file_path, thumb_path); } else { FFmpegHelper.MakeVideoThumbnail(file_path, thumb_path); } return(File.ReadAllBytes(thumb_path)); }
public RecordingMetadata ConvertPreviewMedia(ConversionConfiguration config) { // generate output directory if (Directory.Exists(config.OutputDirectory)) { Directory.Delete(config.OutputDirectory, true); } Directory.CreateDirectory(config.OutputDirectory); // convert file ConvertVideoFiles(config, true); // generate recording object var finalRecording = new RecordingMetadata(); finalRecording.FileName = "slides.mp4"; finalRecording.PresenterFileName = "talkinghead.mp4"; finalRecording.StageVideo = "stage.mp4"; finalRecording.Slides = BuildThumbnails(config, "slides.mp4"); finalRecording.Duration = FFmpegHelper.GetMediaLength(config.SlideVideoPath).TotalSeconds; FFmpegHelper.ExportThumbnail(5f, Path.Combine(config.OutputDirectory, "stage.mp4"), config.OutputDirectory, "thumbnail"); return(finalRecording); }
private static async Task ConvertToAsync() { var input = "/Users/zhangcheng/Desktop/macos64/src.mp4"; var output = "/Users/zhangcheng/Desktop/macos64/src-1.mp4"; await FFmpegHelper.ConvertToAsync(input, output, TimeSpan.FromSeconds(5)); }
public static bool IsFFmpegExist() { if (FFMPEG_EXIST == null) { FFMPEG_EXIST = FFmpegHelper.IsExist() ? "True" : "False"; } return(FFMPEG_EXIST == "True"); }
private static async Task ReplaceBackgroundAsync() { var input = "/Users/zhangcheng/Desktop/macos64/src.mp4"; var output = "/Users/zhangcheng/Desktop/macos64/src-3.mp4"; var background = "/Users/zhangcheng/Desktop/macos64/bg.mp4"; await FFmpegHelper.ReplaceBackgroundAsync(input, output, "70de77", 0.1f, 0.2f, background, TimeSpan.FromSeconds(10)); }
public void DownloadVideo() { //GetStream Progress.StatusMsg = "GetStream..."; string Errlabel = ""; string[] TidalVideoUrls = TidalTool.getVideoDLUrls(TidalVideo.ID.ToString(), Resolution, out Errlabel); if (Errlabel.IsNotBlank()) { goto ERR_RETURN; } string TsFilePath = TidalTool.getVideoPath(OutputDir, TidalVideo, TidalAlbum, ".ts", hyphen: AddHyphen, plist: TidalPlaylist, artistBeforeTitle: ArtistBeforeTitle, addYear: AddYear); //Download Progress.StatusMsg = "Start..."; if (!(bool)M3u8Helper.Download(TidalVideoUrls, TsFilePath, ProgressNotify, Proxy: TidalTool.PROXY)) { Errlabel = "Download failed!"; goto ERR_RETURN; } //Convert FilePath = TidalTool.getVideoPath(OutputDir, TidalVideo, TidalAlbum, hyphen: AddHyphen, plist: TidalPlaylist, artistBeforeTitle: ArtistBeforeTitle, addYear: AddYear); if (!FFmpegHelper.IsExist()) { Errlabel = "FFmpeg is not exist!"; goto ERR_RETURN; } if (!FFmpegHelper.Convert(TsFilePath, FilePath)) { Errlabel = "Convert failed!"; goto ERR_RETURN; } System.IO.File.Delete(TsFilePath); //SetMetaData string sLabel = TidalTool.SetMetaData(FilePath, null, null, null, null, TidalVideo); if (sLabel.IsNotBlank()) { Errlabel = "Set metadata failed!"; goto ERR_RETURN; } Progress.SetStatus(ProgressHelper.STATUS.COMPLETE); return; ERR_RETURN: if (Progress.GetStatus() == ProgressHelper.STATUS.CANCLE) { return; } ErrlabelHeight = 15; Progress.SetStatus(ProgressHelper.STATUS.ERROR); Progress.Errmsg = Errlabel; }
public Texture2D(string path, TextureFlags flags = TextureFlags.None, TextureFormat format = TextureFormat.BGRA8) { #if DEBUG this.path = System.IO.Path.GetFileNameWithoutExtension(path); #endif int width, height, bytesPerPixel; byte[] data = FFmpegHelper.ImageFromFile(path, out width, out height, out bytesPerPixel); handle = Texture.Create2D(width, height, 0, format, flags, MemoryBlock.FromArray(data)); }
public RenderAudioScene(Game game, string inputPath, string outputPath) : base(game, false) { if (string.IsNullOrEmpty(outputPath)) { Log.Error("Output is missing"); return; } Chart chart = Chart.Load(inputPath); chart.GenerateEvents(); if (string.IsNullOrWhiteSpace(Path.GetExtension(outputPath))) { outputPath += ".wav"; } // preload all audio Loader loader = new Loader(chart, audio); loader.PreloadAll(true, false); songPlayer = new BGM(chart, audio); autoplay = new Player(chart, audio, null, null); songPlayer.realtime = false; autoplay.realtime = false; autoplay.autoplay = true; songPlayer.StartPlayer(); autoplay.StartPlayer(); songPlayer.Update(1.0f); autoplay.Update(1.0f); if (songPlayer.playing || autoplay.playing) { throw new ApplicationException("Players did not finish as expected"); } Log.Info("Rendering audio..."); byte[] audioData = audio.RenderAudio(); if (audioData.Length > 0) { Log.Info("Saving audio..."); FFmpegHelper.SaveSound(outputPath, audioData, audioData.Length / 4, audio.audioSpec.freq); } else { Log.Warning("No audio was rendered"); } }
/// <summary> /// 获取视频时长,格式(00:10) /// </summary> /// <returns></returns> private void GetVideoDuration() { App.Current.Dispatcher.Invoke(() => { this._duration = FFmpegHelper.GetVideoDuration(this.VideoPath); if (!_duration.Equals("on N-")) { this.tbDuration.Text = _duration; } }); }
public static async Task <int> Main(string[] args) { var path = Environment.GetEnvironmentVariable("PATH"); Environment.SetEnvironmentVariable("PATH", @"C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\inference_engine\bin\intel64\Release;C:\Program Files (x86)\IntelSWTools\openvino\opencv\bin;" + path); WindowsLibraryLoader.Instance.AdditionalPaths.Add(@"C:\Users\nick\Source\Repos\OpenVinoOpenCvSharp\install\bin"); if (args.Length != 4) { Console.WriteLine("Usage: PersonDetection <input format> <input camera> <model> <output>"); return(-1); } try { FFmpegHelper.Register(); var buildInfo = OpenCvSharp.Cv2.GetBuildInformation(); Console.WriteLine($"Build info: {buildInfo}"); var inputFormat = args[0]; var inputCamera = args[1]; var model = args[2]; var output = args[3]; var outputFolder = new DirectoryInfo(output); if (!outputFolder.Exists) { outputFolder.Create(); } var dataTransfer = new DataTransfer <MatAndBuffer>(); IDetector detector; if (model.EndsWith("bin", StringComparison.OrdinalIgnoreCase)) { detector = new InferenceEngineDetector(model); } else if (model.EndsWith("cfg", StringComparison.OrdinalIgnoreCase)) { detector = new TinyYoloV3Detector(model); } else if (model.EndsWith("caffemodel", StringComparison.OrdinalIgnoreCase)) { detector = new CaffeDnnFaceDetector(model); } else { throw new ArgumentException($"Unknown model type: {model}"); } ProcessStream(inputFormat, inputCamera, dataTransfer); var counter = 0; while (true) { using var data = await dataTransfer.GetNext(default);
private static Mat BgraToMat(MediaFrame frame) { Mat mat = new Mat(frame.AVFrame.height, frame.AVFrame.width, MatType.CV_8UC4); int stride = (int)(uint)mat.Step(); for (int i = 0; i < frame.AVFrame.height; i++) { FFmpegHelper.CopyMemory(mat.Data + i * stride, frame.Data[0] + i * frame.AVFrame.linesize[0], (uint)stride); } return(mat); }
private static Mat BgraToMat(MediaFrame frame) { Mat mat = new Mat(frame.AVFrame.height, frame.AVFrame.width, DepthType.Cv8U, 4); int stride = mat.Step; for (int i = 0; i < frame.AVFrame.height; i++) { FFmpegHelper.CopyMemory(mat.DataPointer + i * stride, frame.Data[0] + i * frame.AVFrame.linesize[0], (uint)stride); } return(mat); }
private void ConvertZoomVideoFile(ConversionConfiguration config, bool preview) { string args = "-i \"" + config.SlideVideoPath + "\" " + "-f mp4 -vcodec libx264 -crf 23 -preset veryfast -tune stillimage -profile:v baseline -level 3.0 -pix_fmt yuv420p -r 30 " + (preview ? " -t 10 " : "") + "\"" + Path.Combine(config.OutputDirectory, "slides.mp4") + "\" "; _logger.LogInformation("Execute ffmpeg: {0}", args); Process p = FFmpegHelper.FFmpeg(args, false); p.Start(); p.WaitForExit(); }
public void GetVideoDuration() { //File file = new File(); //// 多媒体信息 //MultimediaInfo info = encoder.getInfo(file); string mp4Url = "https://www.pic1.jzbl.com/buildingcircle/a092c1b7-f4c6-4d33-ac3b-7e3d534ed5b1/2020-03-03/v/1583240039140.mp4"; var datas = FFmpegHelper.GetVideoDuration(mp4Url); Console.WriteLine("111"); }
private static Mat AudioFrameToMat(AudioFrame frame) { int planar = ffmpeg.av_sample_fmt_is_planar((AVSampleFormat)frame.AVFrame.format); int planes = planar != 0 ? frame.AVFrame.channels : 1; int block_align = ffmpeg.av_get_bytes_per_sample((AVSampleFormat)frame.AVFrame.format) * (planar != 0 ? 1 : frame.AVFrame.channels); int stride = frame.AVFrame.nb_samples * block_align; int channels = planar != 0 ? 1 : frame.AVFrame.channels; MatType dstType; switch ((AVSampleFormat)frame.AVFrame.format) { case AVSampleFormat.AV_SAMPLE_FMT_U8: case AVSampleFormat.AV_SAMPLE_FMT_U8P: dstType = MatType.CV_8UC(channels); break; case AVSampleFormat.AV_SAMPLE_FMT_S16: case AVSampleFormat.AV_SAMPLE_FMT_S16P: dstType = MatType.CV_16SC(channels); break; case AVSampleFormat.AV_SAMPLE_FMT_S32: case AVSampleFormat.AV_SAMPLE_FMT_S32P: dstType = MatType.CV_32SC(channels); break; case AVSampleFormat.AV_SAMPLE_FMT_FLT: case AVSampleFormat.AV_SAMPLE_FMT_FLTP: dstType = MatType.CV_32FC(channels); break; case AVSampleFormat.AV_SAMPLE_FMT_DBL: case AVSampleFormat.AV_SAMPLE_FMT_DBLP: // opencv not have 64S, use 64F case AVSampleFormat.AV_SAMPLE_FMT_S64: case AVSampleFormat.AV_SAMPLE_FMT_S64P: dstType = MatType.CV_64FC(channels); break; default: throw new FFmpegException(FFmpegException.NotSupportFormat); } Mat mat = new Mat(planes, frame.AVFrame.nb_samples, dstType); for (int i = 0; i < planes; i++) { FFmpegHelper.CopyMemory(mat.Data + i * stride, frame.Data[i], (uint)stride); } return(mat); }
public static async Task <int> Main(string[] args) { if (args.Length < 4) { Console.WriteLine("usage: StandaloneFaceDetection <input format> <input camera> <model> <output>"); return(-1); } try { FFmpegHelper.Register(); var buildInfo = OpenCvSharp.Cv2.GetBuildInformation(); Console.WriteLine($"Build information: {buildInfo}"); var inputFormat = args[0]; var inputCamera = args[1]; var model = args[2]; var output = args[3]; var target = args.Length < 5 ? Net.Target.CPU : Enum.Parse <Net.Target>(args[4]); var backend = args.Length < 6 ? Net.Backend.OPENCV : Enum.Parse <Net.Backend>(args[5]); var outputFolder = new DirectoryInfo(output); if (!outputFolder.Exists) { outputFolder.Create(); } var dataTransfer = new DataTransfer <MatAndBuffer>(); IDetector detector; if (model.EndsWith("bin", StringComparison.OrdinalIgnoreCase)) { detector = new InferenceEngineDetector(model, backend, target); } else if (model.EndsWith("cfg", StringComparison.OrdinalIgnoreCase)) { detector = new TinyYoloV3Detector(model); } else if (model.EndsWith("caffemodel", StringComparison.OrdinalIgnoreCase)) { detector = new CaffeDnnFaceDetector(model); } else { throw new ArgumentException($"Unknown model type: {model}"); } ProcessStream(inputFormat, inputCamera, dataTransfer); var counter = 0; while (true) { using var data = await dataTransfer.GetNext(default);
private static VideoFrame MatToVideoFrame(Mat mat) { using (Image <Bgr, byte> image = mat.ToImage <Bgr, byte>()) { VideoFrame frame = new VideoFrame(AVPixelFormat.AV_PIX_FMT_BGR24, image.Width, image.Height); int stride = image.Width * image.NumberOfChannels; for (int i = 0; i < frame.AVFrame.height; i++) { FFmpegHelper.CopyMemory(frame.Data[0] + i * frame.AVFrame.linesize[0], image.Mat.DataPointer + i * stride, (uint)stride); } return(frame); } }
private static AudioFrame MatToAudioFrame(Mat mat, AVSampleFormat srctFormat, int sampleRate) { int channels = mat.Channels() > 1 ? mat.Channels() : mat.Height; AudioFrame frame = new AudioFrame(srctFormat, channels, mat.Width, sampleRate); bool isPlanar = ffmpeg.av_sample_fmt_is_planar(srctFormat) > 0; int stride = (int)mat.Step(); for (int i = 0; i < (isPlanar ? channels : 1); i++) { FFmpegHelper.CopyMemory(frame.Data[i], mat.Data + i * stride, (uint)stride); } return(frame); }
/// <summary> /// 去水印事件 /// </summary> private async void ExecuteDelogoCommand() { if (isDelogo) { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipWaitTaskFinished")); return; } if (VideoPath == "") { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipNoSeletedVideo")); return; } if (LogoWidth == -1) { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipInputRightLogoWidth")); return; } if (LogoHeight == -1) { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipInputRightLogoHeight")); return; } if (LogoX == -1) { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipInputRightLogoX")); return; } if (LogoY == -1) { eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("TipInputRightLogoY")); return; } // 新文件名 string newFileName = VideoPath.Insert(VideoPath.Length - 4, "_delogo"); Status = string.Empty; await Task.Run(() => { // 执行去水印程序 isDelogo = true; FFmpegHelper.Delogo(VideoPath, newFileName, LogoX, LogoY, LogoWidth, LogoHeight, new Action <string>((output) => { Status += output + "\n"; })); isDelogo = false; }); }
private void DownloaderForm_InstallRequested(string filePath) { string extractPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe"); bool result = FFmpegHelper.ExtractFFmpeg(filePath, extractPath); if (result) { MessageBox.Show(Resources.ScreenRecordForm_DownloaderForm_InstallRequested_FFmpeg_successfully_downloaded_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(Resources.ScreenRecordForm_DownloaderForm_InstallRequested_Download_of_FFmpeg_failed_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void DownloaderForm_InstallRequested(string filePath) { string extractPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe"); bool result = FFmpegHelper.ExtractFFmpeg(filePath, extractPath); if (result) { MessageBox.Show("FFmpeg successfully downloaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Download of FFmpeg failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ScreenRecorder(ScreencastOptions options) { if (string.IsNullOrEmpty(options.OutputPath)) { throw new Exception("Screen recorder cache path is empty."); } CachePath = options.OutputPath; Options = options; _ffmpegCli = new FFmpegHelper(Options); _ffmpegCli.RecordingStarted += OnRecordingStarted; }
private static VideoFrame MatToVideoFrame(Mat mat) { if (mat.Type() != MatType.CV_8UC3) { throw new FFmpegException(FFmpegException.NotSupportFormat); } VideoFrame frame = new VideoFrame(AVPixelFormat.AV_PIX_FMT_BGR24, mat.Width, mat.Height); int stride = (int)mat.Step(); for (int i = 0; i < frame.AVFrame.height; i++) { FFmpegHelper.CopyMemory(frame.Data[0] + i * frame.AVFrame.linesize[0], mat.Data + i * stride, (uint)stride); } return(frame); }
public static bool ConvertMp4ToM4a(string sFilePath, out string sNewFilePath) { sNewFilePath = sFilePath; if (Path.GetExtension(sFilePath).ToLower().IndexOf("mp4") < 0) { return(true); } sNewFilePath = sFilePath.Replace(".mp4", ".m4a"); if (FFmpegHelper.Convert(sFilePath, sNewFilePath)) { System.IO.File.Delete(sFilePath); return(true); } return(false); }