Java实现FLV格式视频转MP4

使用Javacv平台工具包
<dependency>
	<groupId>org.bytedeco</groupId>
	<artifactId>javacv-platform</artifactId>
	<version>1.5.3</version>
</dependency>
转化代码
public static void flv2Mp4(String inputFile, String outputFile) throws IOException {
	FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
	grabber.start();
	FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile, grabber.getImageWidth(), grabber.getImageHeight());
	recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
	recorder.setFrameRate(grabber.getFrameRate());
	recorder.setAudioChannels(1);
	recorder.start();
	Frame frame;
	while ((frame = grabber.grabFrame()) != null) {
		recorder.record(frame);
	}
	recorder.stop();
	grabber.stop();
}
posted @ 2024-11-25 20:14  日落西风又在吹  阅读(7)  评论(0编辑  收藏  举报