Why does ffmpeg stop randomly in the middle of a process?

后端 未结 1 460
孤城傲影
孤城傲影 2021-01-21 06:34

ffmpeg feels like its taking a long time. I then look at my output file and i see it stops between 6 and 8mbs. A fully encoded file is about 14mb. Why does ffmpeg stop? My code

相关标签:
1条回答
  • 2021-01-21 07:01

    Suppose you caught a deadlock here.

    A reference from MSDN:

    There is a similar issue when you read all text from both the standard output and standard error streams. The following C# code, for example, performs a read operation on both streams.

     // Do not perform a synchronous read to the end of both
     // redirected streams.
     // string output = p.StandardOutput.ReadToEnd();
     // string error = p.StandardError.ReadToEnd();
     // p.WaitForExit();
     // Use asynchronous read operations on at least one of the streams.
     p.BeginOutputReadLine();
     string error = p.StandardError.ReadToEnd();
     p.WaitForExit();

    The code example avoids the deadlock condition by performing asynchronous read operations on the StandardOutput stream. A deadlock condition results if the parent process calls p.StandardOutput.ReadToEnd followed by p.StandardError.ReadToEnd and the child process writes enough text to fill its error stream. The parent process would wait indefinitely for the child process to close its StandardOutput stream. The child process would wait indefinitely for the parent to read from the full StandardError stream.

    You can use asynchronous read operations to avoid these dependencies and their deadlock potential. Alternately, you can avoid the deadlock condition by creating two threads and reading the output of each stream on a separate thread.

    UPDATE: when I worked with ffmpeg, I wrote a wrapper to it. The main idea was to parse each output line from stderr. Due to this I was able to recognize conversion deadlocks and manually kill the conversion process when necessary. It also useful to obtain additional media information like duration and codecs used.

    UPDATE2(guess the last ;) ): as I mentioned above I used stderr in async mode to parse output. In addition stdout was used in normal(mean, not async) mode to get the result of video preview generation (a feature of ffmpeg) to get result without using of temporary file.

    Hope, this helps.

    0 讨论(0)
提交回复
热议问题