为什么ffmpeg的随机停止在过程中间? [英] Why does ffmpeg stop randomly in the middle of a process?

查看:1050
本文介绍了为什么ffmpeg的随机停止在过程中间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ffmpeg的感觉就像它花了很长时间。然后我看着我的输出文件,我看到它6 8mbs站之间。一个完全连接codeD文件大约14MB。为什么ffmpeg的停下来?我的code对StandardOutput.ReadToEnd锁定了();.我不得不杀掉该进程,然后我得到标准输出的结果和犯错(看到它没有更多然后在10秒移动,当我看到它每秒更新一次previously后)。 stdout是标准错误如下。

输出味精显示结束了文件大小。我也看到我的CPU使用率下降时停止。我从拷入视觉工作室的说法。 CD相同的工作目录并运行CMD(斌/的ffmpeg)并粘贴参数。它能够完成。

请注意:我得的std出来犯错检查失败

  INT soundProcess(INFN字符串,字符串outfn)
    {
        字符串AA,AA2;
        AA = AA2 =死;        VAR应用=新工艺();        app.StartInfo.UseShellExecute = FALSE;
        app.StartInfo.RedirectStandardOutput =真;
        app.StartInfo.RedirectStandardError = TRUE;
        // * /
        app.StartInfo.FileName = @BIN \\ ffmpeg.exe
        app.StartInfo.Arguments =的String.Format(@ - 我,{0}-AB 192K -y {2},{1},,INFN,outfn,参数);
        app.Start();
        尝试
        {
            app.PriorityClass = ProcessPriorityClass.BelowNormal;
        }
        赶上(异常前)
        {
            如果(!Regex.IsMatch(ex.Message,@无法处理请求,因为这个过程。*​​已退出))
                扔恩;
        }        AA = app.StandardOutput.ReadToEnd();
        AA2 = app.StandardError.ReadToEnd();        app.WaitForExit();        如果(aa2.IndexOf(找不到codeC参数)!= -1)
            返回1;
        否则,如果(AA ==死|| AA2 ==死)
            返回-1;
        否则如果(aa2.Length!= 0)
            返回-2;
        其他
            返回0;
    }

标准错误的输出。 stdout是空的。

 的FFmpeg版本SVN-r15815,版权所有(C)2000-2008法布里斯·贝拉等。
  配置:--enable-memalign可乱砍--enable-postproc --enable-swscale --enable-GPL --enable-libfaac --enable-libfaad --enable-libgsm --enable-了libmp3lame --enable-libvorbis - -enable-libtheora --enable-libx264 --enable-libxvid --disable---disable ffserver的-vhook --enable-AviSynth的--enable-pthreads的
  libavutil 49.12。 0 / 49.12。 0
  libav codeC 52. 3 0/52 3 0
  了libavformat 52.23。 1 / 52.23。 1
  libavdevice 52 1.0 / 52 1 0
  libswscale 0. 6 1/0 6 1
  libpostproc 51 2.0 / 51。2 0
  建于2008年11月13日十点28分29秒,GCC:4.2.4(TDM-1 MinGW的)
输入#0,MOV,MP4,M4A,3GP,3G2,MJ2,由C:\\ dev的\\ SRC \\干线\\ prjname \\ prjname \\ App_Data文件/温度/ M / O / 6304266424778814852:
  时间:00:12:53.36,启动:0.000000,码率:154 kb / s的
    流#0.0(UND):音频:AAC,44100赫兹,立体声,S16
输出#0的iPod,到C:\\ dev的\\ SRC \\干线\\ prjname \\ prjname \\ App_Data文件\\ TEMP \\米\\ o \\ 2.m4a':
    流#0.0(UND):音频:libfaac,44100赫兹,立体声,S16,192 kb / s的
流映射:
  流#0.0 - > #0.0
preSS [Q]停止编码
大小= 87KB时间= 4.74 =比特率150.7kbits /秒
大小= 168KB时间= 9.06 =比特率151.9kbits /秒
大小= 265KB时间= 14.28比特率= ​​151.8kbits /秒
大小= 377KB时间= 20.29比特率= ​​152.1kbits /秒
大小= 487KB时间= 26.22比特率= ​​152.1kbits /秒
大小= 594KB时间= 32.02比特率= ​​152.1kbits /秒
大小= 699KB时间= 37.64比特率= ​​152.1kbits /秒
大小= 808KB时间= 43.54比特率= ​​152.0kbits /秒
大小= 930KB时间= 50.09比特率= ​​152.2kbits /秒
大小= 1058kB时间= 57.05比特率= ​​152.0kbits /秒
大小= 1193kB时间= 64.23比特率= ​​152.1kbits /秒
大小= 1329kB时间= 71.63比特率= ​​152.0kbits /秒
大小= 1450KB时间为78.16比特率= ​​152.0kbits /秒
大小= 1578kB时间= 85.05比特率= ​​152.0kbits /秒
大小= 1706kB时间= 92.00比特率= ​​152.0kbits /秒
大小= 1836kB时间= 98.94比特率= ​​152.0kbits /秒
大小= 1971kB时间= 106.25比特率= ​​151.9kbits /秒
大小= 2107kB时间= 113.57比特率= ​​152.0kbits /秒
大小= 2214kB时间= 119.33比特率= ​​152.0kbits /秒
大小= 2345kB时间= 126.39比特率= ​​152.0kbits /秒
大小= 2479kB时间= 133.56比特率= ​​152.0kbits /秒
大小= 2611kB时间= 140.76比特率= ​​152.0kbits /秒
大小= 2745kB时间= 147.91比特率= ​​152.1kbits /秒
大小= 2880kB时间= 155.20比特率= ​​152.0kbits /秒
大小= 3013kB时间= 162.40比特率= ​​152.0kbits /秒
大小= 3146kB时间= 169.58比特率= ​​152.0kbits /秒
大小= 3277kB时间= 176.61比特率= ​​152.0kbits /秒
大小= 3412kB时间= 183.90比特率= ​​152.0kbits /秒
大小= 3540kB时间= 190.80比特率= ​​152.0kbits /秒
大小= 3670kB时间= 197.81比特率= ​​152.0kbits /秒
大小= 3805kB时间= 205.08比特率= ​​152.0kbits /秒
大小= 3932kB时间= 211.93比特率= ​​152.0kbits /秒
大小= 4052kB时间= 218.38比特率= ​​152.0kbits /秒
大小= 4171kB时间= 224.82比特率= ​​152.0kbits /秒
大小= 4277kB时间= 230.55比特率= ​​152.0kbits /秒
大小= 4378kB时间= 235.96比特率= ​​152.0kbits /秒
大小= 4486kB时间= 241.79比特率= ​​152.0kbits /秒
大小= 4592kB时间= 247.50比特率= ​​152.0kbits /秒
大小= 4698kB时间= 253.21比特率= ​​152.0kbits /秒
大小= 4804kB时间= 258.95比特率= ​​152.0kbits /秒
大小= 4906kB时间= 264.41比特率= ​​152.0kbits /秒
大小= 5012kB时间= 270.09比特率= ​​152.0kbits /秒
大小= 5118kB时间= 275.85比特率= ​​152.0kbits /秒
大小= 5234kB时间= 282.10比特率= ​​152.0kbits /秒
大小= 5331kB时间= 287.39比特率= ​​151.9kbits /秒
大小= 5445kB时间= 293.55比特率= ​​152.0kbits /秒
大小= 5555kB时间= 299.40比特率= ​​152.0kbits /秒
大小= 5665kB时间= 305.37比特率= ​​152.0kbits /秒
大小= 5766kB时间= 310.80比特率= ​​152.0kbits /秒
大小= 5876kB时间= 316.70比特率= ​​152.0kbits /秒
大小= 5984kB时间= 322.50比特率= ​​152.0kbits /秒
大小= 6094kB时间= 328.49比特率= ​​152.0kbits /秒
大小= 6212kB时间= 334.76比特率= ​​152.0kbits /秒
大小= 6327kB时间= 340.99比特率= ​​152.0kbits /秒


解决方案

假设你抓了僵局在这里。

MSDN 参考:


  

有一个类似的问题,当你阅读
  从标准输出的所有文本
  和标准错误流。该
  下面的C#code,例如,
  执行在两个读操作
  流。


  //不要执行同步读既年底
 //重定向数据流。
 //字符串输出= p.StandardOutput.ReadToEnd();
 //字符串错误= p.StandardError.ReadToEnd();
 // p.WaitForExit();
 //在流中的至少一项的用途异步读取操作。
 p.BeginOutputReadLine();
 字符串错误= p.StandardError.ReadToEnd();
 p.WaitForExit();


  

在code例如避免僵局
  通过执行异步条件
  读了StandardOutput操作
  流。死锁条件结果
  如果父进程调用
  p.StandardOutput.ReadToEnd其次是
  p.StandardError.ReadToEnd和
  子进程写入足够多的文本来
  填补其错误流。父
  进程将无限期地等待
  子进程关闭其
  StandardOutput流。孩子
  进程将无限期地等待
  父从充分阅读
  StandardError的流。


  
  

您可以使用异步读取
  操作,以避免这些依赖
  和他们的僵局潜力。
  或者,您可以避开
  通过创建两个死锁条件
  线程和读出的每一个的输出
  流在单独的线程。


更新:当我和ffmpeg的工作,我写了一个包装它。其主要思想是,以解析来自标准错误每个输出线。由于这个我能够认识的转换死锁并在必要时手动终止转换过程。
它也有用以获得类似期限和codeCS使用的其他介质的信息。

UPDATE2 (猜最后;)):正如我上面提到我用标准错误在异步模式解析输出。此外标准输出在正常(意思是,不是异步)模式用于获取视频preVIEW代(ffmpeg的的一个特征)的结果得到的结果,而不使用临时文件。

希望,这有助于。

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 locks up on StandardOutput.ReadToEnd();. I had to kill the process (after seeing it not move for more then 10 seconds when i see it update every second previously) then i get the results of stdout and err. stdout is "" stderr is below.

The output msg shows the filesize ended. I also see a drop in my CPU usage when it stops. I copyed the argument from visual studios. CD to the same working directory and ran the cmd (bin/ffmpeg) and pasted the argument. It was able to complete.

NOTE: I must get std out and err to check for failures.

    int soundProcess(string infn, string outfn)
    {
        string aa, aa2;
        aa = aa2 = "DEAD";

        var app = new Process();

        app.StartInfo.UseShellExecute = false;
        app.StartInfo.RedirectStandardOutput = true;
        app.StartInfo.RedirectStandardError = true;
        //*/
        app.StartInfo.FileName = @"bin\ffmpeg.exe";
        app.StartInfo.Arguments = string.Format(@"-i ""{0}"" -ab 192k -y {2} ""{1}""", infn, outfn, param);
        app.Start();
        try
        {
            app.PriorityClass = ProcessPriorityClass.BelowNormal;
        }
        catch (Exception ex)
        {
            if (!Regex.IsMatch(ex.Message, @"Cannot process request because the process .*has exited"))
                throw ex;
        }

        aa = app.StandardOutput.ReadToEnd();
        aa2 = app.StandardError.ReadToEnd();

        app.WaitForExit();

        if (aa2.IndexOf("could not find codec parameters") != -1)
            return 1;
        else if (aa == "DEAD" || aa2 == "DEAD")
            return -1;
        else if (aa2.Length != 0)
            return -2;
        else
            return 0;
    }

The output of stderr. stdout is empty.

FFmpeg version SVN-r15815, Copyright (c) 2000-2008 Fabrice Bellard, et al.
  configuration: --enable-memalign-hack --enable-postproc --enable-swscale --enable-gpl --enable-libfaac --enable-libfaad --enable-libgsm --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libx264 --enable-libxvid --disable-ffserver --disable-vhook --enable-avisynth --enable-pthreads
  libavutil     49.12. 0 / 49.12. 0
  libavcodec    52. 3. 0 / 52. 3. 0
  libavformat   52.23. 1 / 52.23. 1
  libavdevice   52. 1. 0 / 52. 1. 0
  libswscale     0. 6. 1 /  0. 6. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Nov 13 2008 10:28:29, gcc: 4.2.4 (TDM-1 for MinGW)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\dev\src\trunk\prjname\prjname\App_Data/temp/m/o/6304266424778814852':
  Duration: 00:12:53.36, start: 0.000000, bitrate: 154 kb/s
    Stream #0.0(und): Audio: aac, 44100 Hz, stereo, s16
Output #0, ipod, to 'C:\dev\src\trunk\prjname\prjname\App_Data\temp\m\o\2.m4a':
    Stream #0.0(und): Audio: libfaac, 44100 Hz, stereo, s16, 192 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
size=      87kB time=4.74 bitrate= 150.7kbits/s    
size=     168kB time=9.06 bitrate= 151.9kbits/s    
size=     265kB time=14.28 bitrate= 151.8kbits/s    
size=     377kB time=20.29 bitrate= 152.1kbits/s    
size=     487kB time=26.22 bitrate= 152.1kbits/s    
size=     594kB time=32.02 bitrate= 152.1kbits/s    
size=     699kB time=37.64 bitrate= 152.1kbits/s    
size=     808kB time=43.54 bitrate= 152.0kbits/s    
size=     930kB time=50.09 bitrate= 152.2kbits/s    
size=    1058kB time=57.05 bitrate= 152.0kbits/s    
size=    1193kB time=64.23 bitrate= 152.1kbits/s    
size=    1329kB time=71.63 bitrate= 152.0kbits/s    
size=    1450kB time=78.16 bitrate= 152.0kbits/s    
size=    1578kB time=85.05 bitrate= 152.0kbits/s    
size=    1706kB time=92.00 bitrate= 152.0kbits/s    
size=    1836kB time=98.94 bitrate= 152.0kbits/s    
size=    1971kB time=106.25 bitrate= 151.9kbits/s    
size=    2107kB time=113.57 bitrate= 152.0kbits/s    
size=    2214kB time=119.33 bitrate= 152.0kbits/s    
size=    2345kB time=126.39 bitrate= 152.0kbits/s    
size=    2479kB time=133.56 bitrate= 152.0kbits/s    
size=    2611kB time=140.76 bitrate= 152.0kbits/s    
size=    2745kB time=147.91 bitrate= 152.1kbits/s    
size=    2880kB time=155.20 bitrate= 152.0kbits/s    
size=    3013kB time=162.40 bitrate= 152.0kbits/s    
size=    3146kB time=169.58 bitrate= 152.0kbits/s    
size=    3277kB time=176.61 bitrate= 152.0kbits/s    
size=    3412kB time=183.90 bitrate= 152.0kbits/s    
size=    3540kB time=190.80 bitrate= 152.0kbits/s    
size=    3670kB time=197.81 bitrate= 152.0kbits/s    
size=    3805kB time=205.08 bitrate= 152.0kbits/s    
size=    3932kB time=211.93 bitrate= 152.0kbits/s    
size=    4052kB time=218.38 bitrate= 152.0kbits/s    
size=    4171kB time=224.82 bitrate= 152.0kbits/s    
size=    4277kB time=230.55 bitrate= 152.0kbits/s    
size=    4378kB time=235.96 bitrate= 152.0kbits/s    
size=    4486kB time=241.79 bitrate= 152.0kbits/s    
size=    4592kB time=247.50 bitrate= 152.0kbits/s    
size=    4698kB time=253.21 bitrate= 152.0kbits/s    
size=    4804kB time=258.95 bitrate= 152.0kbits/s    
size=    4906kB time=264.41 bitrate= 152.0kbits/s    
size=    5012kB time=270.09 bitrate= 152.0kbits/s    
size=    5118kB time=275.85 bitrate= 152.0kbits/s    
size=    5234kB time=282.10 bitrate= 152.0kbits/s    
size=    5331kB time=287.39 bitrate= 151.9kbits/s    
size=    5445kB time=293.55 bitrate= 152.0kbits/s    
size=    5555kB time=299.40 bitrate= 152.0kbits/s    
size=    5665kB time=305.37 bitrate= 152.0kbits/s    
size=    5766kB time=310.80 bitrate= 152.0kbits/s    
size=    5876kB time=316.70 bitrate= 152.0kbits/s    
size=    5984kB time=322.50 bitrate= 152.0kbits/s    
size=    6094kB time=328.49 bitrate= 152.0kbits/s    
size=    6212kB time=334.76 bitrate= 152.0kbits/s    
size=    6327kB time=340.99 bitrate= 152.0kbits/s    

解决方案

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.

这篇关于为什么ffmpeg的随机停止在过程中间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆