转载自:http://blog.csdn.net/jay100500/article/details/52957837
遵循:BY-NC-SA
署名-非商业性使用-相同方式共享 4.0协议
作者:谭东
时间:2016年10月28日
环境:Windows 7
Mp4Coder,H264和AAC合成MP4视频库
Github地址:https://github.com/zuichu/Mp4Coder
主要支持功能:
H264和AAC合成MP4视频文件
MP4文件拼接成MP4视频文件
AAC文件拼接成AAC音频文件
MP4文件裁剪、剪切
AAC文件裁剪、剪切
MP4文件提取分离AAC音频文件
MP4文件提取分离H264 文件
H264和网络流AAC文件合成MP4视频文件
其他更多功能和用法参考examples里的例子用法…
用法:
try {
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(Environment.getExternalStorageDirectory() + "/imgBufFrame.h264"));
AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl(Environment.getExternalStorageDirectory() + "/test.aac"));
Movie movie = new Movie();
movie.addTrack(h264Track);
movie.addTrack(aacTrack);
Container mp4file = new DefaultMp4Builder().build(movie);
FileChannel fc = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/encode.mp4")).getChannel();
mp4file.writeContainer(fc);
fc.close();
} catch (IOException e) {
e.printStackTrace();
}
也可以根据实际情况自定义帧率:
H264TrackImpl h264Track1 = new H264TrackImpl(new FileDataSourceImpl(Environment.getExternalStorageDirectory() + "/video.h264"), "eng", 15000, 1001);
//给出源码解释:
/**
* Creates a new Track
object from a raw H264 source (DataSource dataSource1
).
* Whenever the timescale and frametick are set to negative value (e.g. -1) the H264TrackImpl
* tries to detect the frame rate.
* Typically values for timescale
and frametick
are:
*
*
23.976 FPS: timescale = 24000; frametick = 1001*
25 FPS: timescale = 25; frametick = 1*
29.97 FPS: timescale = 30000; frametick = 1001*
30 FPS: timescale = 30; frametick = 1*
*
* @param dataSource the source file of the H264 samples
* @param lang language of the movie (in doubt: use "eng")
* @param timescale number of time units (ticks) in one second
* @param frametick number of time units (ticks) that pass while showing exactly one frame
* @throws IOException in case of problems whiel reading from the DataSource