Android FFmpeg-来自MediaCodec的Mux编码的h264帧

时间:2019-01-24 13:18:19

标签: android ffmpeg h.264 android-ffmpeg android-mediacodec

我正在尝试从Android摄像机(由MediaCodec编码)捕获h264帧,并将它们传递给在同一设备上运行的FFmpeg进程。

目前,我是通过将从MediaCodec接收到的编码字节数组写入一个名为out.h264的文件来实现的。

就像这样:

    FileOutputStream fosVideo = new ...

    ...

    // encoder callback
    @Override
    public void onVideoData(ByteBuffer h264Buffer, MediaCodec.BufferInfo info) {
        fosVideo.write(h264Buffer);
    }

正在写入h264文件时,我开始FFmpeg进程并提供h264文件作为输入。

ffmpeg -re -i out.h264 -c:v copy -r 30 -loglevel 48 a.mp4

我也尝试过

ffmpeg -re -framerate 25 -i out.h264 -c:v copy -r 30 -loglevel 48 a.mp4

FFmpeg进程会在10秒到几分钟之间的任意时间运行,然后突然停止,并显示以下信息:

frame=  330 fps= 29 q=31.0 size=     512kB time=00:00:10.98 bitrate= 381.8kbits/s dup=55 drop=0 speed=0.972x    
[h264 @ 0xf1863800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1863b80] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1863f00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
*** 1 dup!
[h264 @ 0xf1864280] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
Clipping frame in rate conversion by 0.199989
[h264 @ 0xf1864600] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1862a00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1862d80] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1863100] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
*** 1 dup!
Clipping frame in rate conversion by 0.199989
*** 1 dup!
frame=  347 fps= 29 q=31.0 size=     768kB time=00:00:11.53 bitrate= 545.5kbits/s dup=58 drop=0 speed=0.974x    
Clipping frame in rate conversion by 0.199989
[out_0_0 @ 0xf182e1e0] EOF on sink link out_0_0:default.
No more output streams to write to, finishing.
frame=  349 fps= 29 q=24.8 Lsize=     920kB time=00:00:17.68 bitrate= 426.1kbits/s dup=58 drop=0 speed=1.48x    
video:631kB audio:282kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.732886%
Input file #0 (/storage/emulated/0/MOVIES/out.h264):
Input stream #0:0 (video): 291 packets read (6065016 bytes); 291 frames decoded; 
Total: 291 packets (6065016 bytes) demuxed
Input file #1 (/storage/emulated/0/MOVIES/out.aac):
Input stream #1:0 (audio): 830 packets read (289119 bytes); 
Total: 830 packets (289119 bytes) demuxed
Output file #0 (/storage/emulated/0/hls/a.mp4):
Output stream #0:0 (video): 349 frames encoded; 349 packets muxed (645952 bytes); 
Output stream #0:1 (audio): 830 packets muxed (289119 bytes); 
Total: 1179 packets (935071 bytes) muxed
291 frames successfully decoded, 0 decoding errors

即使out.h264文件仍被记录到其中。 好像ffmpeg进程认为文件已结束。

有什么想法吗?

0 个答案:

没有答案