我使用三星Galaxy Note2上的MPEG2TS容器使用MediaRecorder录制视频。它初始化时没有任何错误,实际上会将数据写入文件(文件会增长到几MB)。但是,该文件不能在任何媒体播放器中播放。
下面是我初始化MediaRecorder的代码:
CamcorderProfile profile = null;
if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
}else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
}else{ profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); }
myMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
myMediaRecorder.setOutputFormat(8);
myMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
myMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
myMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
myMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
String f = Environment.getExternalStorageDirectory().toString() + "/video.ts";
myMediaRecorder.setOutputFile(f);
myMediaRecorder.setPreviewDisplay(previewHolder.getSurface());
myMediaRecorder.prepare();
myMediaRecorder.start();当我将输出格式设置为MP4 ("2")而不是MPEG2-TS (" 8 ")时,上面的代码工作得很好,但当它设置为8时,它会产生一个无法播放(但不是空的)视频!
这是怎么回事呢?
编辑:这是设备上录制的sample video,如果有人感兴趣的话。
发布于 2014-06-04 18:13:50
“任何媒体播放器”都是错误的说法。我发现VLC无法播放MPEG2TS流,但ffplay可以播放它们(ffplay video.ts)。要调试vlc,可以增加详细程度:
$ vlc -vvv video.ts
...
[0x7ffe34c01728] ts demux debug: eof ?
[0x7ffe34c01728] ts demux warning: lost synchro
[0x7ffe34c01728] ts demux debug: skipping 76 bytes of garbage
[0x7ffe34c01728] ts demux debug: Force Seek Per Percent: Seeking failed at 10%.
[0x7ffe34c01728] ts demux error: libdvbpsi (misc PSI): Bad CRC_32 table 0x0 !!!
[0x7ffe34c01728] ts demux error: libdvbpsi (PAT decoder): invalid section (section_syntax_indicator == 0)
[0x7ffe34c01728] ts demux error: libdvbpsi (PAT decoder): invalid section (section_syntax_indicator == 0)
...对于那些想要使用此格式进行流传输的用户,请确保降低用于检测文件格式的初始探测缓冲区。8K对我来说很好:
nc -l -p 1337 | ffplay -probesize 8192 -或者如果流没有正确关闭:
socat TCP-LISTEN:1337,fork,reuseaddr SYSTEM:'killall ffplay; ffplay -probesize 8192 -'发布于 2017-09-29 18:02:25
安卓的文档说MPEG_2_TS需要26级的api
https://developer.android.com/reference/android/media/MediaRecorder.OutputFormat.html#MPEG_2_TS
这可能是您的视频无法播放的原因。在您询问的时候,MPEG_2_TS还没有得到官方支持
https://stackoverflow.com/questions/17885446
复制相似问题