Java Code Examples for org.bytedeco.javacv.FFmpegFrameGrabber#getAudioCodec()

The following examples show how to use org.bytedeco.javacv.FFmpegFrameGrabber#getAudioCodec() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaCVRecord.java    From easyCV with Apache License 2.0 6 votes vote down vote up
/**
 * 视频源
 * 
 * @param src
 * @return
 * @throws Exception
 */
public Recorder from(String src) throws Exception {
	av_log_set_level(AV_LOG_ERROR);
	if (src == null) {
		throw new Exception("源视频不能为空");
	}
	this.src = src;
	// 采集/抓取器
	grabber = new FFmpegFrameGrabber(src);
	if (hasRTSP(src)) {
		grabber.setOption("rtsp_transport", "tcp");
	}
	grabber.start();// 开始之后ffmpeg会采集视频信息,之后就可以获取音视频信息
	if (width < 0 || height < 0) {
		width = grabber.getImageWidth();
		height = grabber.getImageHeight();
	}
	// 视频参数
	audiocodecid = grabber.getAudioCodec();
	codecid = grabber.getVideoCodec();
	framerate = grabber.getVideoFrameRate();// 帧率
	bitrate = grabber.getVideoBitrate();// 比特率
	// 音频参数
	// 想要录制音频,这三个参数必须有:audioChannels > 0 && audioBitrate > 0 && sampleRate > 0
	audioChannels = grabber.getAudioChannels();
	audioBitrate = grabber.getAudioBitrate();
	if (audioBitrate < 1) {
		audioBitrate = 128 * 1000;// 默认音频比特率
	}
	sampleRate = grabber.getSampleRate();
	return this;
}
 
Example 2
Source File: ConvertVideoPakcet.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 选择视频源
 * @param src
 * @author eguid
 * @throws Exception
 */
public ConvertVideoPakcet from(String src) throws Exception {
	// 采集/抓取器
	grabber = new FFmpegFrameGrabber(src);
	if(src.indexOf("rtsp")>=0) {
		grabber.setOption("rtsp_transport","tcp");
	}
	grabber.start();// 开始之后ffmpeg会采集视频信息,之后就可以获取音视频信息
	if (width < 0 || height < 0) {
		width = grabber.getImageWidth();
		height = grabber.getImageHeight();
	}
	// 视频参数
	audiocodecid = grabber.getAudioCodec();
	System.err.println("音频编码:" + audiocodecid);
	codecid = grabber.getVideoCodec();
	framerate = grabber.getVideoFrameRate();// 帧率
	bitrate = grabber.getVideoBitrate();// 比特率
	// 音频参数
	// 想要录制音频,这三个参数必须有:audioChannels > 0 && audioBitrate > 0 && sampleRate > 0
	audioChannels = grabber.getAudioChannels();
	audioBitrate = grabber.getAudioBitrate();
	if (audioBitrate < 1) {
		audioBitrate = 128 * 1000;// 默认音频比特率
	}
	return this;
}
 
Example 3
Source File: JavaCVRecord.java    From easyCV with Apache License 2.0 4 votes vote down vote up
/**
 * 转发源视频到输出(复制)
 * 
 * @param src
 *            -源视频
 * @param out
 *            -输出流媒体服务地址
 * @return
 * @throws org.bytedeco.javacv.FrameRecorder.Exception
 */
public Recorder stream(String src, String out) throws IOException {
	if (src == null || out == null) {
		throw new Exception("源视频和输出为空");
	}
	this.src = src;
	this.out = out;
	// 采集/抓取器
	grabber = new FFmpegFrameGrabber(src);
	grabber.start();
	if (width < 0 || height < 0) {
		width = grabber.getImageWidth();
		height = grabber.getImageHeight();
	}
	// 视频参数
	int audiocodecid = grabber.getAudioCodec();
	int codecid = grabber.getVideoCodec();
	double framerate = grabber.getVideoFrameRate();// 帧率
	int bitrate = grabber.getVideoBitrate();// 比特率

	// 音频参数
	// 想要录制音频,这三个参数必须有:audioChannels > 0 && audioBitrate > 0 && sampleRate > 0
	int audioChannels = grabber.getAudioChannels();
	int audioBitrate = grabber.getAudioBitrate();
	int sampleRate = grabber.getSampleRate();

	// 录制/推流器
	record = new FFmpegFrameRecorderPlus(out, width, height);
	record.setVideoOption("crf", "18");
	record.setGopSize(1);

	record.setFrameRate(framerate);
	record.setVideoBitrate(bitrate);
	record.setAudioChannels(audioChannels);
	record.setAudioBitrate(audioBitrate);
	record.setSampleRate(sampleRate);
	AVFormatContext fc = null;
	//rtmp和flv
	if (hasRTMPFLV(out)) {
		// 封装格式flv,并使用h264和aac编码
		record.setFormat("flv");
		record.setVideoCodec(AV_CODEC_ID_H264);
		record.setAudioCodec(AV_CODEC_ID_AAC);
		if(hasRTMPFLV(src)) {
			fc = grabber.getFormatContext();
		}
	}else if(hasMP4(out)){//MP4
		record.setFormat("mp4");
		record.setVideoCodec(AV_CODEC_ID_H264);
		record.setAudioCodec(AV_CODEC_ID_AAC);
	}
	record.start(fc);
	return this;
}