问题出在YUV4MPEGPipeParser类的run方法中。有两个连续的循环。如果流上当前没有可用数据,则第二个循环立即终止(例如,到目前为止,所有输入均已由解析器处理,并且ffmpeg或流泵的速度不足以为其提供一些新数据->
available()== 0 ->循环终止->泵螺纹结束)。
只需摆脱这两个循环并进入睡眠状态,然后执行一个简单的阻塞read()即可,而不是检查是否有任何数据可用于处理。因为解析器代码是在单独的线程上启动的,所以可能也不需要wait()/
notify()甚至sleep()。
您可以像这样重写run()方法的代码:
public class YUV4MPEGPipeParser extends Thread { ... // optimal size of buffer for reading from pipe stream :-) private static final int BUFSIZE = PipedInputStream.PIPE_SIZE; public void run() { try { byte buffer[] = new byte[BUFSIZE]; int len = 0; while ((len = is.read(buffer, 0, BUFSIZE) != -1) { // we have valid data available // in first 'len' bytes of 'buffer' array. // do stuff.... like write out YUV frames } } catch ... } }


