背景:我在編寫 h264 轉 mp4 格式demo時出現的問題
代碼:
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/1.h264";
try {
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(path));
// 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);
int index = path.lastIndexOf(".")+1;
String extname = path.substring(index);
String path_t = path.substring(0, index) + "mp4";
FileChannel fc = new FileOutputStream(new File(path_t)).getChannel();
mp4file.writeContainer(fc);
fc.close();
path = path_t;
} catch (IOException e) {//IOException e
e.printStackTrace();
}
過程:
我在H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(path));
行
path = path_t;
行e.printStackTrace();
行打了斷點,監聽執行情況,然而出現的結果是:進入斷點後,按F10,程序再也不進入斷點。後續的代碼也沒有執行(從是否有文件被創建看出)。
後來取消H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(path));
行的斷點,程序正確執行到path = path_t;
行斷點處,文件也被創建。
結論:
1.斷點慎打,特別是在耗費資源,消耗性能的函數調用時。
2.如果出現上述情況,取消斷點,執行看看。
分析原因:
1.函數執行耗費資源與時間上的數據,導致數據不對應。出現程序跑飛的現象。