Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Video encoded by ffmpeg.exe giving me a garbage video in c# .net
10 septembre 2018, par Amit YadavI want to record video through webcam and file to be saved in
.mp4
format. So for recording i am usingAforgeNet.dll
for recording and formp4
format i am encoding raw video intomp4
usingffmpeg.exe
usingNamedPipeStreamServer
as i receive frame i push into the named pipe buffer. this process works fine i have checked inProcessTheErrorData
event but when i stop recording the output file play garbage video shown in the image belowHere is Code for this
Process Process; NamedPipeServerStream _ffmpegIn; byte[] _videoBuffer ; const string PipePrefix = @"\\.\pipe\"; public void ffmpegWriter() { if(File.Exists("outputencoded.mp4")) { File.Delete("outputencoded.mp4"); } _videoBuffer = new byte[widht * heigth * 4]; var audioPipeName = GetPipeName(); var videoPipeName = GetPipeName(); var videoInArgs = $@" -thread_queue_size 512 -use_wallclock_as_timestamps 1 -f rawvideo -pix_fmt rgb32 -video_size 640x480 -i \\.\pipe\{videoPipeName}"; var videoOutArgs = $"-vcodec libx264 -crf 15 -pix_fmt yuv420p -preset ultrafast -r 10"; _ffmpegIn = new NamedPipeServerStream(videoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, _videoBuffer.Length); Process=StartFFmpeg($"{videoInArgs} {videoOutArgs} \"{"outputencoded.mp4"}\"", "outputencoded.mp4"); } bool WaitForConnection(NamedPipeServerStream ServerStream, int Timeout) { var asyncResult = ServerStream.BeginWaitForConnection(Ar => { }, null); if (asyncResult.AsyncWaitHandle.WaitOne(Timeout)) { ServerStream.EndWaitForConnection(asyncResult); return ServerStream.IsConnected; } return false; } static string GetPipeName() => $"record-{Guid.NewGuid()}"; public static Process StartFFmpeg(string Arguments, string OutputFileName) { var process = new Process { StartInfo = { FileName = "ffmpeg.exe", Arguments = Arguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, }, EnableRaisingEvents = true }; // var logItem = ServiceProvider.Get
().CreateNew(Path.GetFileName(OutputFileName)); process.ErrorDataReceived += (s, e) => ProcessTheErrorData(s,e); process.Start(); process.BeginErrorReadLine(); return process; } and Writing each frame like this.
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { try { if (_recording) { using (var bitmap = (Bitmap) eventArgs.Frame.Clone()) { var _videoBuffers = ImageToByte(bitmap); if (_firstFrameTime != null) { bitmap.Save("image/" + DateTime.Now.ToString("ddMMyyyyHHmmssfftt")+".bmp"); _lastFrameTask?.Wait(); _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffers, 0, _videoBuffers.Length); } else { if (_firstFrame) { if (!WaitForConnection(_ffmpegIn, 5000)) { throw new Exception("Cannot connect Video pipe to FFmpeg"); } _firstFrame = false; } _firstFrameTime = DateTime.Now; _lastFrameTask?.Wait(); _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffers, 0, _videoBuffers.Length); } } } using (var bitmap = (Bitmap) eventArgs.Frame.Clone()) { var bi = bitmap.ToBitmapImage(); bi.Freeze(); Dispatcher.CurrentDispatcher.Invoke(() => Image = bi); } } catch (Exception exc) { MessageBox.Show("Error on _videoSource_NewFrame:\n" + exc.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StopCamera(); } }
Even i have written each frame to disk as bitmap .bmp and frames are correct but i don't know what's i am missing here? please help thanks in advance.
-
FFmpeg blend mode is not working with `multiply` option
10 septembre 2018, par Praveen TamilWhen using multiply blend option, the green color image is generated
Hi I'm using below code
ffmpeg -i gradient_0.png -i gradient_1.png -filter_complex "[0:v]setsar=1[v0];[1:v]setsar=1[v1];[v1][v0]blend=all_mode=multiply" output.jpeg -y
Input 1 with color code #eaeae9 Input 2 with color code #a9a499 Result with color code #3eda1e But I need output like below image with color code #9b968c
-
FFMPEG, C++, Memory leak, what am I doing wrong ?
10 septembre 2018, par MrSmithSo I've built this app that consumes an IP cameras rtsp feed and does fun things with it, however I have a small memory leak that I have only just now pinned down.
If I just run this
while (av_read_frame(input_format_context, &input_packet) >= 0) {}
It will just grow'n grow'n grow ... So what am I missing?
Am using a windows port of ffmpeg and my version is 58.9.100.0 Could it be a leak in FFMPEG itself?
-
How can I turn libavformat error messages off
10 septembre 2018, par amrhassanBy default, libavformat writes error messages to
stderr
, Like:Estimating duration from bitrate, this may be inaccurate
How can I turn it off? or better yet, pipe it to my own neat logging function?
Edit: Redirecting stderr to somewhere else is not acceptable since I need it for other logging purposes, I just want libavformat to not write to it.
-
Is there any way to create a WEBM file like this ?
10 septembre 2018, par yksnmelI'm trying to convert my mp4 to webm with these settings. Does anyone know how can I do this on FFMpeg?
Here is the settings:
Format : WebM Format version : Version 2 File size : 296 MiB Duration : 3 min 31 s Overall bit rate : 11.8 Mb/s Writing application : Lavf56.40.101 Writing library : Lavf56.40.101 Video ID : 1 Format : VP8 Codec ID : V_VP8 Duration : 3 min 31 s Bit rate : 11.3 Mb/s Width : 1 216 pixels Height : 720 pixels Display aspect ratio : 5:3 Frame rate mode : Constant Frame rate : 25.000 FPS Compression mode : Lossy Bits/(Pixel*Frame) : 0.516 Stream size : 284 MiB (96%) Default : Yes Forced : No
Thanks!