从ffmpeg命令读取输出

时间:2013-12-10 17:18:13

标签: java android ffmpeg stream command

我正在尝试从android中的ffmpeg命令读取输出。我一直在尝试这个:

try {
        Process process = Runtime.getRuntime().exec("data/data/com.extremeye/cache/ffmpeg" + " -i " + videoPath + " -y " + framesPath + "%d.jpg");
        BufferedReader bufferedReader = new BufferedReader(
        new InputStreamReader(process.getInputStream()));
        StringBuilder log = new StringBuilder();
        String line;
        while ((line = bufferedReader.readLine()) != null) {
              log.append(line + "\n");
        }
        Log.d(TAG, log.toString());
    } catch (IOException e) {
    }

例如,当命令是“ls / data / data / package / cache”时,它可以工作,但它不会从我的ffmpeg命令中检索我想要的数据。我想要的数据应该是:

enter image description here

但是当我使用我的代码时,它不会检索任何数据。

现在,我正在使用来自答案的新代码,它似乎有效但不是真的。我明白了:

[format @ 0xee7450] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'format'
[scale @ 0xee85f0] w:1280 h:720 fmt:yuv420p sar:1/1 -> w:1280 h:720 fmt:yuvj420p sar:1/1 flags:0x4
Output #0, image2, to '/data/data/com.extremeye/cache/frames/%d.jpg':
Metadata:
major_brand     : mp42
minor_version   : 0
compatible_brands: mp41isom
creation_time   : 2013-11-20 14:45:01
encoder         : Lavf54.6.100
Stream #0:0(und): Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 30 tbc
Metadata:
creation_time   : 2013-11-20 14:45:01
handler_name    : VideoHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> mjpeg)
Press [q] to stop, [?] for help
frame=    3 fps=1.1 q=2.0 size=       0kB time=00:00:00.10 bitrate=   0.0kbits/s    
frame=    5 fps=1.5 q=5.0 size=       0kB time=00:00:00.16 bitrate=   0.0kbits/s    
frame=    7 fps=1.8 q=10.2 size=       0kB time=00:00:00.23 bitrate=   0.0kbits/s    
frame=    9 fps=1.9 q=16.0 size=       0kB time=00:00:00.30 bitrate=   0.0kbits/s    
frame=   11 fps=1.9 q=21.9 size=       0kB time=00:00:00.36 bitrate=   0.0kbits/s    
frame=   12 fps=1.3 q=24.8 size=       0kB time=00:00:00.40 bitrate=   0.0kbits/s    
frame=   13 fps=1.0 q=24.8 size=       0kB time=00:00:00.43 bitrate=   0.0kbits/s    
frame=   14 fps=1.0 q=24.8 size=       0kB time=00:00:00.46 bitrate=   0.0kbits/s    
frame=   15 fps=1.1 q=24.8 size=       0kB time=00:00:00.50 bitrate=   0.0kbits/s    
frame=   17 fps=1.1 q=24.8 size=       0kB time=00:00:00.56 bitrate=   0.0kbits/s    
frame=   19 fps=1.2 q=24.8 size=       0kB time=00:00:00.63 bitrate=   0.0kbits/s    
frame=   21 fps=1.3 q=24.8 size=       0kB time=00:00:00.70 bitrate=   0.0kbits/s    
frame=   23 fps=1.4 q=24.8 size=       0kB time=00:00:00.76 bitrate=   0.0kbits/s    
frame=   25 fps=1.4 q=24.8 size=

数据检索突然中断,我不知道为什么......有什么想法吗?

1 个答案:

答案 0 :(得分:3)

ffmpeg打印是stderr的消息,你正在捕获stdout。使用getErrorStream()