public static string RemuxVideoToMp4(string filePath, bool convertAudioToAcc = false, bool convertAudioFast = false) { if (filePath.EndsWith(".mp4")) return null; var filename = Path.ChangeExtension(filePath, ".mp4"); var arguments = "-i " + '"' + filePath + '"' + " -codec copy "; if (convertAudioToAcc) arguments = arguments + "-c:a aac "; arguments = arguments + '"' + filename + '"'; var ffMpeg = new FFMpegConverter(); ffMpeg.Invoke(arguments); return filename; }
// encode using ffmpeg internal void Encode(string v) { FFMpegConverter c = new FFMpegConverter(); Random rnd = new Random(); c.Invoke(string.Format("-f concat -safe 0 -i " + v + ".txt -c copy " + v + rnd.Next(100) + ".mp4")); }
public async Task <IFile> ExtractAsync(IFile videoFile) { if (videoFile == null) { throw new ArgumentNullException(nameof(videoFile)); } if (videoFile.StorageType != StorageType.FileSystem) { throw new Exception("FFMpeg can work only with file on FileSystem"); } //get full path for audio string audioFullpath = Path.Combine( _fileResolver.GetAudioFolderPath(StorageType.FileSystem), videoFile.Filename + "." + _audioOptions.Value.DefaultFormat); //get video string videofilePath = _fileResolver.VideoFilePath(videoFile.Filename, videoFile.Extension, StorageType.FileSystem); if (File.Exists(audioFullpath)) { File.Delete(audioFullpath); } //extract audio from video var ffMpeg = new FFMpegConverter(); ffMpeg.LogReceived += FfMpeg_LogReceived; ffMpeg.Invoke( string.Format(FFMpegExtractAudioFormat, videofilePath, _audioOptions.Value.DefaultFormat, _audioOptions.Value.BitRate, audioFullpath)); var cancellationTokenSource = new CancellationTokenSource(); //delete video File.Delete(videofilePath); try { await Task.Delay(10000, _cancellationTokenSource.Token); } catch (TaskCanceledException) { //do nothing cancel it okey } //return info about audio file return(new PCFile() { Filename = videoFile.Filename, Extension = "." + _audioOptions.Value.DefaultFormat, Duration = _duration, StorageType = StorageType.FileSystem, }); }
static async Task MainAsync(string[] args) { string dir = "envivio"; string mpdUrl = "http://10.5.5.7/q/p/userapi/streams/32/mpd"; //"http://10.5.7.207/userapi/streams/30/mpd"; //"http://10.5.7.207/userapi/streams/11/mpd?start_time=1458816642&stop_time=1458819642"; //"http://dash.edgesuite.net/envivio/EnvivioDash3/manifest.mpd"; //"http://dash.edgesuite.net/dash264/TestCases/1a/netflix/exMPD_BIP_TC1.mpd"; var stopwatch = Stopwatch.StartNew(); var downloader = new MpdDownloader(new Uri(mpdUrl), dir); var trackRepresentation = downloader.GetTracksFor(TrackContentType.Video).First().TrackRepresentations.OrderByDescending(r => r.Bandwidth).First(); var prepareTime = stopwatch.Elapsed; var chunks = //Directory.GetFiles(@"C:\Users\Alexander\Work\Github\qoollo\SharpDashTools\DashTools.Samples\bin\Debug\envivio", "*.mp4") //.Select(f => Path.GetFileName(f) == "make_chunk_path_longer_32.mp4" // ? new Mp4InitFile(Path.Combine("envivio", Path.GetFileName(f))) // : new Mp4File(Path.Combine("envivio", Path.GetFileName(f)))) // .ToArray(); await downloader.Download(trackRepresentation, TimeSpan.FromMinutes(60), TimeSpan.FromMinutes(60 + 60 * 6 / 6)); var downloadTime = stopwatch.Elapsed - prepareTime; var ffmpeg = new FFMpegConverter(); ffmpeg.LogReceived += (s, e) => Console.WriteLine(e.Data); var combined = downloader.CombineChunksFast(chunks, s => ffmpeg.Invoke(s)); //downloader.CombineChunks(chunks, s => ffmpeg.Invoke(s)); var combineTime = stopwatch.Elapsed - prepareTime - downloadTime; if (!ffmpeg.Stop()) { ffmpeg.Abort(); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("================================================================"); Console.WriteLine("Prepared in {0} s", prepareTime.TotalSeconds); Console.WriteLine("Downloaded {0} chunks in {1} s", chunks.Count(), downloadTime.TotalSeconds); Console.WriteLine("Combined in {0} s", combineTime.TotalSeconds); Console.WriteLine("Total: {0} s", (prepareTime + downloadTime + combineTime).TotalSeconds); Console.ReadLine(); return; string mpdFilePath = //@"C:\Users\Alexander\AppData\Local\Temp\note_5_video_5_source_2-index_00000\manifest.mpd"; await DownloadMpdStreams(mpdUrl, dir); await ConcatStreams(mpdFilePath, Path.Combine(Path.GetDirectoryName(mpdFilePath), "output.mp4")); }
private void button1_Click(object sender, EventArgs e) { NReco.VideoConverter.FFMpegConverter wrap = new FFMpegConverter(); var path = @"C:\Users\Arash\Desktop\Convert"; var file = Directory.GetFiles(path).FirstOrDefault(); var s = $" -i {file} -vf \"drawtext=text='SaraSamet':x=10:y=H-th-10:" + $"fontfile=c:\\windows\\fonts\\arial.ttf:fontsize=16:fontcolor=white:" + $"shadowcolor=black:shadowx=1:shadowy=1\" {path}\\output.mp4"; //wrap.Invoke("-i D:\\d.mp4 -i D:\\w.txt -filter_complex \"overlay=10:10\" D:\\O.mp4"); wrap.Invoke(s); }
/// <summary> /// ایجاد واترمارک بر روی ویدیو /// </summary> /// <param name="filePath"></param> /// <param name="companyName"></param> /// <param name="watermarkType"></param> /// <param name="watermarkPosition"></param> /// <param name="companyLogoFilePath"></param> /// <returns></returns> public async Task WatermarkMediaAsync(string filePath, string companyName, VideoWatermarkType watermarkType, VideoWatermarkPositionType watermarkPosition, string companyLogoFilePath) { var watermarkPath = Path.Combine(HttpContext.Current.Server.MapPath(@"~/Files/Users/Video/Web/Watermark"), Path.GetFileNameWithoutExtension(filePath) + "_Watermarked.mp4"); const string outPutPath = @"~/Files/Users/Video/Web"; var text = $"{companyName.ToLower()}.novinak.com"; var fullName = $@"{outPutPath}\Image\{text}.png".Replace(" / ", "-"); var image = DrawText($"{text}", new Font("Alberta", 8, FontStyle.Regular), Color.FromArgb(40, 255, 255, 255), Color.Transparent);//Color.White image.Save(fullName, ImageFormat.Png); var outPutVideo = watermarkPath; var wrap = new FFMpegConverter(); wrap.Invoke($" -i {filePath} -i {image} -filter_complex \"overlay=main_w-overlay_w-5:main_h-overlay_h-5\" - codec:a copy {outPutVideo}"); }
/// <summary> /// ایجاد واترمارک بر روی ویدیو /// </summary> /// <param name="filePath"></param> /// <returns></returns> public async Task WatermarkWithCustomTextAsync(string filePath) { var videoResolution = new FFProbe().GetMediaInfo(filePath).Streams.Select(p => p.Width).FirstOrDefault(); var fontSize = videoResolution / 30; var padding = videoResolution / 48; var inputFile = filePath; var outputFile = Path.Combine(HttpContext.Current.Server.MapPath(FileConst.VideosWebPath), Path.GetFileNameWithoutExtension(filePath) + "_watermarked.mp4"); // var text = $"{(await _companyService.FindByUserIdAsync(_webContext.CurrentUserId)).Alias}.novinak.com"; var ffMpeg = new FFMpegConverter(); var imagePath = HttpContext.Current.Server.MapPath(FileConst.WatermarkIcon); ffMpeg.Invoke($" -i {filePath} -i {imagePath} -filter_complex \"overlay=10:10\" -codec:a copy {outputFile}"); // ffMpeg.Invoke($" -i {filePath} -vf \"drawtext = fontfile = alb.ttf: fontsize = {fontSize} : fontcolor = [email protected]: text = '{text}' : borderw = 0.5 :x = w - text_w - {padding} :y = h - text_h - {padding}\" -acodec copy {outputFile}"); }
/// <summary> /// Combines all of the InputFiles and writes it to disk. /// </summary> /// <returns>The final video's output path.</returns> public VideoMergeOutput CombineAndWrite() { var output = new VideoMergeOutput(); try { output.FileOutputPath = Path.Combine(InputFiles.First().DirectoryName, Store.Data.Record.LastVideoName + ".mp4"); if (InputFiles.Count == 1) { // Remove _part 1 from the file name, but don't concatenate InputFiles.First().MoveTo(output.FileOutputPath); OutputFile = new FileInfo(output.FileOutputPath); return(output); } TempFileList = new FileInfo(Path.GetTempFileName()); using (var sw = new StreamWriter(TempFileList.FullName)) { foreach (FileInfo file in InputFiles) { sw.WriteLine($"file '{file.FullName}'"); } } FFMpegConverter ffMpegConverter = new FFMpegConverter(); OutputFile = new FileInfo(output.FileOutputPath); string ffmpegArgs = $"-f concat -safe 0 -i \"{TempFileList.FullName}\" -movflags +faststart -c copy \"{OutputFile.FullName}\""; ffMpegConverter.Invoke(ffmpegArgs); DeleteInputFiles(); DeleteTemporaryFiles(); } catch (Exception ex) { DeleteTemporaryFiles(); output.IsSuccessful = false; output.MergeFailureReason = ex.Message; } return(output); }
public static string RemuxVideoToMp4(string filePath, bool convertAudioToAcc = false, bool convertAudioFast = false) { if (filePath.EndsWith(".mp4")) { return(null); } var filename = Path.ChangeExtension(filePath, ".mp4"); var arguments = "-i " + '"' + filePath + '"' + " -codec copy "; if (convertAudioToAcc) { arguments = arguments + "-c:a aac "; } arguments = arguments + '"' + filename + '"'; var ffMpeg = new FFMpegConverter(); ffMpeg.Invoke(arguments); return(filename); }
private void ConvertVideo() { if (File.Exists(videoName + ".avi") && File.Exists(subtitleFiles[0] + ".srt") && File.Exists(subtitleFiles[1] + ".srt")) { var ffMpeg = new FFMpegConverter(); foreach (string file in subtitleFiles) { if (new FileInfo(file + ".srt").Length == 0) { AppendEmptySubstitleFile(file + ".srt"); } } ffMpeg.Invoke(generateCommmand()); File.Delete(videoName + ".avi"); foreach (string file in subtitleFiles) { File.Delete(file + ".srt"); } } }
private static void ProcessVideo(string blobName) { string blobConnectionString = ConfigurationManager.AppSettings["BlobConnectionString"]; CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobConnectionString); CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("media"); CloudBlob cloudBlob = cloudBlobContainer.GetBlobReference(blobName); string tempInputFileName = Path.Combine(Path.GetTempPath(), blobName); string tempOutputFileName = Path.Combine(Path.GetTempPath(), blobName.Replace(".mp4", "_bw.avi")); Directory.CreateDirectory(Path.GetDirectoryName(tempOutputFileName)); cloudBlob.DownloadToFile(tempInputFileName, FileMode.Create); var ffmpeg = new FFMpegConverter(); ffmpeg.Invoke($"-i {tempInputFileName} -vf hue=s=0 {tempOutputFileName}"); CloudBlockBlob convertedBlob = cloudBlobContainer.GetBlockBlobReference(blobName.Replace(".mp4", "_bw.avi")); convertedBlob.Properties.ContentType = "image/gif"; foreach (KeyValuePair <string, string> metadata in cloudBlob.Metadata) { convertedBlob.Metadata.Add(metadata.Key, metadata.Value); } convertedBlob.UploadFromFile(tempOutputFileName); }