Java Code Examples for org.bytedeco.javacpp.avformat.AVFormatContext#streams()

The following examples show how to use org.bytedeco.javacpp.avformat.AVFormatContext#streams() . 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: testRecorder.java    From easyCV with Apache License 2.0 6 votes vote down vote up
/**
 * 从输入音视频流获取音视频格式
 * 
 * @param avfc
 */
private void getInputParam(AVFormatContext avfc) {
	// get input video and audio stream indices from ifmt_ctx
	for (int idx = 0; idx < avfc.nb_streams(); idx++) {
		System.err.println("读取流参数:"+idx);
		AVStream stream = avfc.streams(idx);
		AVCodecParameters codecpar = stream.codecpar();
		if (codecpar.codec_type() == AVMEDIA_TYPE_VIDEO) {
			AVRational frame_rate = stream.r_frame_rate();
			if (frame_rate.num() != AV_NOPTS_VALUE && frame_rate.den() != 0) {
				this.frameRate = (frame_rate.num()) / (frame_rate.den());
			}
			this.videoindex=idx;
			this.in_videoCodecpar = codecpar;
			this.in_videoStream = stream;
		} else if (codecpar.codec_type() == AVMEDIA_TYPE_AUDIO) {
			this.in_audioCodecpar = codecpar;
			this.in_audioStream = stream;
			this.audioindex=idx;
		}
	}
}
 
Example 2
Source File: GrabberTmplate.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 获取第一帧视频位置
 * @param pFormatCtx
 * @return
 */
protected int findVideoStreamIndex(AVFormatContext pFormatCtx) {
	int i = 0, videoStream = -1;
	for (i = 0; i < pFormatCtx.nb_streams(); i++) {
		AVStream stream=pFormatCtx.streams(i);
		AVCodecContext codec=stream.codec();
		if (codec.codec_type() == AVMEDIA_TYPE_VIDEO) {
			videoStream = i;
			break;
		}
	}
	return videoStream;
}
 
Example 3
Source File: GrabberTmplate.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 指定视频帧位置获取对应视频帧
 * @param pFormatCtx
 * @param videoStream
 * @return
 */
protected AVCodecContext findVideoStream(AVFormatContext pFormatCtx ,int videoStream)throws StreamNotFoundException {
	if(videoStream >=0) {
		// Get a pointer to the codec context for the video stream
		AVStream stream=pFormatCtx.streams(videoStream);
		AVCodecContext pCodecCtx = stream.codec();
		return pCodecCtx;
	}
	throw new StreamNotFoundException("Didn't open video file");
}
 
Example 4
Source File: FFmpegRecorder.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 获取第一帧视频位置
 * @param pFormatCtx
 * @return
 */
protected int findVideoStreamIndex(AVFormatContext pFormatCtx) {
	int i = 0;
	for (i = 0; i < pFormatCtx.nb_streams(); i++) {
		AVStream stream=pFormatCtx.streams(i);
		AVCodecContext codec=stream.codec();
		if (codec.codec_type() == AVMEDIA_TYPE_VIDEO) {
			return i;
		}
	}
	return -1;
}
 
Example 5
Source File: FFmpegRecorder.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 指定视频帧位置获取对应视频帧
 * @param pFormatCtx
 * @param videoStream
 * @return
 */
protected AVCodecContext findVideoStream(AVFormatContext pFormatCtx ,int videoStream)throws StreamNotFoundException {
	if(videoStream >=0) {
		// Get a pointer to the codec context for the video stream
		AVStream stream=pFormatCtx.streams(videoStream);
		AVCodecContext pCodecCtx = stream.codec();
		return pCodecCtx;
	}
	throw new StreamNotFoundException("Didn't open video file");
}
 
Example 6
Source File: TestPusher.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 获取第一帧视频位置
 * 
 * @param pFormatCtx
 * @return
 */
protected int findVideoStreamIndex(AVFormatContext pFormatCtx) {
	int i = 0, videoStream = -1;
	for (i = 0; i < pFormatCtx.nb_streams(); i++) {
		AVStream stream = pFormatCtx.streams(i);
		AVCodecContext codec = stream.codec();
		if (codec.codec_type() == AVMEDIA_TYPE_VIDEO) {
			videoStream = i;
			break;
		}
	}
	return videoStream;
}
 
Example 7
Source File: TestPusher.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 指定视频帧位置获取对应视频帧
 * @param pFormatCtx
 * @param videoStream
 * @return
 */
protected AVCodecContext findVideoStream(AVFormatContext pFormatCtx ,int videoStream)throws StreamNotFoundException {
	if(videoStream >=0) {
		// Get a pointer to the codec context for the video stream
		AVStream stream=pFormatCtx.streams(videoStream);
		AVCodecContext pCodecCtx = stream.codec();
		return pCodecCtx;
	}
	throw new StreamNotFoundException("Didn't open video file");
}
 
Example 8
Source File: GrabberTemplate4.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 查找视频通道
 * @param pFormatCtx
 * @return
 */
protected int findVideoStreamIndex(AVFormatContext formatCtx) {
	int size=formatCtx.nb_streams();
	for (int i = 0; i < size; i++) {
		AVStream stream=formatCtx.streams(i);
		AVCodecParameters codec=stream.codecpar();
		int type=codec.codec_type();
		if (type == AVMEDIA_TYPE_VIDEO) {
			return i;
		}
	}
	return -1;
}
 
Example 9
Source File: GrabberTemplate4.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 查找音频通道
 * @param pFormatCtx
 * @return
 */
protected int findAudioStreamIndex(AVFormatContext formatCtx) {
	int size=formatCtx.nb_streams();
	for (int i = 0; i < size; i++) {
		AVStream stream=formatCtx.streams(i);
		AVCodecParameters codec=stream.codecpar();
		int type=codec.codec_type();
		if (type == AVMEDIA_TYPE_AUDIO) {
			return i;
		}
	}
	return -1;
}
 
Example 10
Source File: GrabberTemplate4.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
	 * 指定视频帧位置获取对应视频帧
	 * @param pFormatCtx
	 * @param videoStream
	 * @return
	 */
	protected AVCodecParameters findVideoParameters(AVFormatContext formatCtx ,int videoStreamIndex)throws StreamNotFoundException {
		if(videoStreamIndex >=0) {
			// Get a pointer to the codec context for the video stream
			AVStream stream=formatCtx.streams(videoStreamIndex);
//			AVCodecContext pCodecCtx = stream.codec();
			AVCodecParameters codecParam=stream.codecpar();
			return codecParam;
		}
		//if no stream,throws Excetion.
		throw new StreamNotFoundException("Didn't open video file");
	}