[英]Android Mediarecorder recorded video duration different from expected duration
I recorded a video using android Mediarecorder. 我用android Mediarecorder录制了一个视频。
(Main Problem: I need to know the exact startTime[System time] and endTime[System time] of the video and the [endTime - startTime] must match the duration of the actual video) (主要问题:我需要知道视频的确切startTime [系统时间]和endTime [系统时间],[endTime - startTime]必须与实际视频的持续时间相匹配)
MediaRecorder.start
startTime = System.currentTimeMillis()
then on stop
MediaRecorder.stop
endTime = System.currentTimeMillis()
I am expecting the video to have this duration 我期待视频有这段时间
expected_duration = (endTime - startTime)
expected_duration =(endTime - startTime)
However, the 然而
expected_duration is always more than the actual duration of the video.
expected_duration总是超过视频的实际持续时间。
My suspicion is that MediaRecorder.start is slow, it took some time before it actually started writing the frames into a video. 我怀疑MediaRecorder.start很慢,它实际上开始将帧写入视频需要一些时间。
So now, is there anyway to get notified when the MediaRecorder started writing the first frame into a video? 那么现在,当MediaRecorder开始将第一帧写入视频时,是否有通知? or is there any way I can figure out the exact System startTime of when video actually started recording.
或者有什么方法可以找出视频实际开始录制时的确切系统开始时间。
thanks for reading, and appreciate any comments, opinions or suggestions. 感谢阅读,并感谢任何意见,建议或意见。 ^^
^^
The best way I found to get real start time (and still I'm not sure it's accurate enough) is to find the duration and then subtract it from the endTime like that: 我发现获得真正开始时间的最佳方法(我仍然不确定它是否足够准确)是找到持续时间然后从endTime中减去它,如下所示:
MediaRecorder.stop
endTime = System.currentTimeMillis()
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//use one of overloaded setDataSource() functions to set your data source
retriever.setDataSource(this, Uri.fromFile(file));
String time =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long movieDurationInMillis = Long.parseLong(time );
long startCaptureTimeMillis = endTime - movieDurationInMillis;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.