org.bytedeco.javacpp.avcodec.AVCodecContext Java Examples

The following examples show how to use org.bytedeco.javacpp.avcodec.AVCodecContext. 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: GrabberTmplate.java    From easyCV with Apache License 2.0 6 votes vote down vote up
/**
 * 查找并尝试打开解码器
 * @return 
 */
protected AVCodecContext findAndOpenCodec(AVCodecContext pCodecCtx) {
	// Find the decoder for the video stream
	AVCodec pCodec = avcodec_find_decoder(pCodecCtx.codec_id());
	if (pCodec == null) {
		System.err.println("Codec not found");
		throw new CodecNotFoundExpception("Codec not found");
	}
	AVDictionary optionsDict = null;
	// Open codec
	if (avcodec_open2(pCodecCtx, pCodec, optionsDict) < 0) {
		System.err.println("Could not open codec");
		throw new CodecNotFoundExpception("Could not open codec"); // Could not open codec
	}
	return pCodecCtx;
}
 
Example #2
Source File: GrabberTemplate4.java    From easyCV with Apache License 2.0 6 votes vote down vote up
/**
 * 查找并尝试打开解码器
 * @return 
 */
protected AVCodecContext findAndOpenCodec(AVCodecContext codecCtx) {
	// Find the decoder for the video stream
	AVCodec pCodec = avcodec_find_decoder(codecCtx.codec_id());
	if (pCodec == null) {
		Console.err("Codec not found!");
		throw new CodecNotFoundExpception("Codec not found!");
	}
	AVDictionary optionsDict = null;
	// Open codec
	if (avcodec_open2(codecCtx, pCodec, optionsDict) < 0) {
		Console.err("Could not open codec!");
		throw new CodecNotFoundExpception("Could not open codec!"); // Could not open codec
	}
	return codecCtx;
}
 
Example #3
Source File: TestPusher.java    From easyCV with Apache License 2.0 6 votes vote down vote up
/**
 * 查找并尝试打开解码器
 * @return 
 */
protected AVCodecContext findAndOpenCodec(AVCodecContext pCodecCtx) {
	// Find the decoder for the video stream
	AVCodec pCodec = avcodec_find_decoder(pCodecCtx.codec_id());
	if (pCodec == null) {
		System.err.println("Codec not found");
		throw new CodecNotFoundExpception("Codec not found");
	}
	AVDictionary optionsDict = null;
	// Open codec
	if (avcodec_open2(pCodecCtx, pCodec, optionsDict) < 0) {
		System.err.println("Could not open codec");
		throw new CodecNotFoundExpception("Could not open codec"); // Could not open codec
	}
	return pCodecCtx;
}
 
Example #4
Source File: FFmpegRecorder.java    From easyCV with Apache License 2.0 6 votes vote down vote up
/**
 * 查找并尝试打开解码器
 * @return 
 */
protected AVCodecContext findAndOpenCodec(AVCodecContext pCodecCtx) {
	// Find the decoder for the video stream
	AVCodec pCodec = avcodec_find_decoder(pCodecCtx.codec_id());
	if (pCodec == null) {
		System.err.println("Codec not found");
		throw new CodecNotFoundExpception("Codec not found");
	}
	AVDictionary optionsDict = null;
	// Open codec
	if (avcodec_open2(pCodecCtx, pCodec, optionsDict) < 0) {
		System.err.println("Could not open codec");
		throw new CodecNotFoundExpception("Could not open codec"); // Could not open codec
	}
	return pCodecCtx;
}
 
Example #5
Source File: Coder.java    From JavaAV with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code Coder} with specified codec and context.
 *
 * @param codec     the codec.
 * @param avContext the codec context.
 */
Coder(Codec codec, AVCodecContext avContext) {
	this.codec = codec;
	this.avContext = avContext;

	state = State.Closed;
}
 
Example #6
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 #7
Source File: GrabberTemplate4.java    From easyCV with Apache License 2.0 5 votes vote down vote up
/**
 * 查找并尝试打开解码器
 * @return 
 */
protected AVCodecContext findAndOpenCodec(AVFormatContext formatCtx ,int videoStreamIndex) {
	// Find codec param
	AVCodecParameters codecParameters=findVideoParameters(formatCtx ,videoStreamIndex);

	// Find the decoder for the video stream
	AVCodec codec = avcodec_find_decoder(codecParameters.codec_id());

	if (codec == null) {
		Console.err("Codec not found!");
		throw new CodecNotFoundExpception("Codec not found!");
	}
	AVDictionary optionsDict = null;
	AVCodecContext codecCtx = avcodec_alloc_context3(codec);

	//convert to codecContext
	if(avcodec_parameters_to_context( codecCtx, codecParameters)<0) {
		Console.err("Could not convert parameter to codecContext!");
		throw new CodecNotFoundExpception("Could not convert parameter to codecContext!"); // Could not open codec
	}

	// Open codec
	if (avcodec_open2(codecCtx, codec, optionsDict) < 0) {
		Console.err("Could not open codec!");
		throw new CodecNotFoundExpception("Could not open codec!"); // Could not open codec
	}
	
	return codecCtx;
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
Source File: FFmpegRecorder.java    From easyCV with Apache License 2.0 4 votes vote down vote up
/**
	 * 抓取视频帧(默认跳过音频帧和空帧)
	 * @param url
	 * @param fmt - 像素格式,比如AV_PIX_FMT_BGR24
	 * @return
	 * @throws IOException
	 */
	public ByteBuffer grabVideoFrame(String url,int fmt) throws IOException {
		
		// Open video file
		AVFormatContext pFormatCtx=openInput(url);
//		if(url.indexOf("rtmp")>=0) {
			//解决rtmp检索时间过长问题
		    //限制最大读取缓存
		    pFormatCtx.probesize(PROBESIZE);//设置500k能保证高清视频也能读取到关键帧
		  //限制avformat_find_stream_info最大持续时长,设置成3秒
		    pFormatCtx.max_analyze_duration(MAX_ANALYZE_DURATION);
//		}
		// Retrieve stream information
		pFormatCtx=findStreamInfo(pFormatCtx);
		// Dump information about file onto standard error
		//av_dump_format(pFormatCtx, 0, url, 0);

		//Find a video stream
		int videoStream=findVideoStreamIndex(pFormatCtx);
		AVCodecContext pCodecCtx =findVideoStream(pFormatCtx,videoStream);
		
		// Find the decoder for the video stream
		pCodecCtx= findAndOpenCodec(pCodecCtx);
		// Allocate video frame
		AVFrame pFrame = av_frame_alloc();
		AVPacket packet = new AVPacket();
		int[] frameFinished = new int[1];
		
		// Read frames and save first five frames to disk
		while (av_read_frame(pFormatCtx, packet) >= 0) {
			// Is this a packet from the video stream?
			if (packet.stream_index() == videoStream) {
				// Decode video frame
				avcodec_decode_video2(pCodecCtx, pFrame, frameFinished, packet);
				// Did we get a video frame?
				if (frameFinished != null&&frameFinished[0] != 0) {
					
				}
			}
			// Free the packet that was allocated by av_read_frame
			av_free_packet(packet);
		}
		//ge
		av_free(pFrame);// Free the YUV frame
		avcodec_close(pCodecCtx);// Close the codec
		avformat_close_input(pFormatCtx);// Close the video file
		return null;
	}
 
Example #14
Source File: TestPusher.java    From easyCV with Apache License 2.0 4 votes vote down vote up
public boolean push(String in_filename, String out_filename) {
		int videoindex = -1;

		ifmt_ctx = openInput(in_filename);
		ifmt_ctx = findStreamInfo(ifmt_ctx);
		videoindex = findVideoStreamIndex(ifmt_ctx);
		//输入流的编解码器
		AVCodecContext inCodecCtx =findVideoStream(ifmt_ctx,videoindex);
		// Find the decoder for the video stream
		inCodecCtx= findAndOpenCodec(inCodecCtx);
		// 打印
		 av_dump_format(ifmt_ctx, 0, in_filename, 0);
		 //初始化输出流上下文
		 avformat_alloc_output_context2(ofmt_ctx, null,null,out_filename); 
		 if(ofmt_ctx.isNull()) {
			// 输出(Output)
			if (avformat_alloc_output_context2(ofmt_ctx, null, "flv", out_filename) < 0) { // RTMP或flv
				//初始化失败
				return false;
			}
		 }
		 //把输入流的编解码器复制给输出流
		 av_dump_format(ofmt_ctx, 0, out_filename, 1);
		 AVStream out_stream = avformat_new_stream(ofmt_ctx,null);
		 if(out_stream==null) {//fail to create new stream
			 return false;
		 }
		 av_dump_format(ofmt_ctx, 0, out_filename, 1);
		 
//		 avcodec_parameters_copy(out_stream.codecpar(), ifmt_ctx.streams(videoindex).codecpar());
//		 if(avcodec_parameters_from_context(out_stream.codecpar(), inCodecCtx)<0) {
//			 return false;
//		 }
		 if (avcodec_copy_context(out_stream.codec(), inCodecCtx) < 0) {
			return false;
		 }

		// Dump Format------------------
		 av_dump_format(ofmt_ctx, 0, out_filename, 1);
//		 System.out.println("尝试打开输入文件");
		/* open the output file, if needed */
//		if(avio_open2(ifmt_ctx.pb(), in_filename, AVIO_FLAG_READ_WRITE, null, null) < 0) {
//			 System.out.println("打开输入流失败");
//			return false;
//		}
//		 System.out.println("已经打开了输入流");
		 //打开输出URL(Open output URL)
//		 System.out.println("尝试打开输出流");
//		 AVIOContext pb = new AVIOContext(null);
//		 if(avio_open(ofmt_ctx.pb(), out_filename, AVIO_FLAG_WRITE)<0) {
//			 System.out.println("打开输出流失败");
//			 //fail
//			 return false;
//		 }
		 System.out.println("已经打开输出流");
		//
		// 写文件头(Write file header)
//		AVDictionary metadata = new AVDictionary(null);
		/* write the stream header, if any */
		System.out.println("写入头");
//		AVDictionary options = new AVDictionary(null);
		if (avformat_write_header(ofmt_ctx, (PointerPointer<?>)null) < 0) {
			return false;
		}
		System.out.println("写入头完成");
		AVStream in_stream;
		try {
			for (long errorindex=0; av_read_frame(ifmt_ctx, pkt) >= 0;) {
				in_stream = ifmt_ctx.streams(pkt.stream_index());
				out_stream = ofmt_ctx.streams(pkt.stream_index());
				pkt.dts(av_rescale_q_rnd(pkt.dts(), in_stream.time_base(), out_stream.time_base(),(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)));
				pkt.pos(-1);
				if (av_interleaved_write_frame(ofmt_ctx, pkt) < 0) {
					// 错误计数
					errorindex++;
				}
				av_free_packet(pkt);
			}
			return true;
		} finally {
			// 写文件尾(Write file trailer)
			av_write_trailer(ofmt_ctx);
			avformat_close_input(ifmt_ctx);
			/* close output */
			avio_close(ofmt_ctx.pb());
			avformat_free_context(ofmt_ctx);
		}
	}
 
Example #15
Source File: GrabberTmplate.java    From easyCV with Apache License 2.0 4 votes vote down vote up
/**
	 * 抓取视频帧(默认跳过音频帧和空帧)
	 * @param url
	 * @param fmt - 像素格式,比如AV_PIX_FMT_BGR24
	 * @return
	 * @throws IOException
	 */
	public ByteBuffer grabVideoFrame(String url,int fmt) throws IOException {
		// Open video file
		AVFormatContext pFormatCtx=openInput(url);

		// Retrieve stream information
		pFormatCtx=findStreamInfo(pFormatCtx);

		// Dump information about file onto standard error
		//av_dump_format(pFormatCtx, 0, url, 0);

		//Find a video stream
		int videoStream=findVideoStreamIndex(pFormatCtx);
		AVCodecContext pCodecCtx =findVideoStream(pFormatCtx,videoStream);
		
		// Find the decoder for the video stream
		pCodecCtx= findAndOpenCodec(pCodecCtx);

		// Allocate video frame
		AVFrame pFrame = av_frame_alloc();
		//Allocate an AVFrame structure
		AVFrame pFrameRGB = av_frame_alloc();

		width = pCodecCtx.width();
		height = pCodecCtx.height();
		pFrameRGB.width(width);
		pFrameRGB.height(height);
		pFrameRGB.format(fmt);

		// Determine required buffer size and allocate buffer
		int numBytes = avpicture_get_size(fmt, width, height);

		SwsContext sws_ctx = sws_getContext(width, height, pCodecCtx.pix_fmt(), width, height,fmt, SWS_BILINEAR, null, null, (DoublePointer) null);

		BytePointer buffer = new BytePointer(av_malloc(numBytes));
		// Assign appropriate parts of buffer to image planes in pFrameRGB
		// Note that pFrameRGB is an AVFrame, but AVFrame is a superset
		// of AVPicture
		avpicture_fill(new AVPicture(pFrameRGB), buffer, fmt, width, height);
		AVPacket packet = new AVPacket();
		int[] frameFinished = new int[1];
		try {
			// Read frames and save first five frames to disk
			while (av_read_frame(pFormatCtx, packet) >= 0) {
				// Is this a packet from the video stream?
				if (packet.stream_index() == videoStream) {
					// Decode video frame
					avcodec_decode_video2(pCodecCtx, pFrame, frameFinished, packet);
					// Did we get a video frame?
					if (frameFinished != null&&frameFinished[0] > 0) {
						// Convert the image from its native format to BGR
						sws_scale(sws_ctx, pFrame.data(), pFrame.linesize(), 0, height, pFrameRGB.data(),pFrameRGB.linesize());
						//Convert BGR to ByteBuffer
						saveFrame(pFrameRGB, width, height);
					}
				}
				// Free the packet that was allocated by av_read_frame
				av_free_packet(packet);
			}
			return null;
		}finally {
			//Don't free buffer
//			av_free(buffer);
			av_free(pFrameRGB);// Free the RGB image
			av_free(pFrame);// Free the YUV frame
			sws_freeContext(sws_ctx);//Free SwsContext
			avcodec_close(pCodecCtx);// Close the codec
			avformat_close_input(pFormatCtx);// Close the video file
		}
	}
 
Example #16
Source File: TestFFmpeg.java    From easyCV with Apache License 2.0 4 votes vote down vote up
/**
	 * 把YUVJ420P数据编码保存成jpg图片
	 * @param pFrame -YUVJ420P数据
	 * @param index -序号
	 * @return
	 */
	private static int saveImg(AVFrame pFrame, int index,String out_file) {
		int width= pFrame.width(), height= pFrame.height();
		// 分配AVFormatContext对象
		AVFormatContext pFormatCtx = avformat_alloc_context();
		// 设置输出文件格式
		pFormatCtx.oformat(av_guess_format("PNG", null, null));
		if (pFormatCtx.oformat() == null) {
			return -1;
		}
		// 创建并初始化一个和该url相关的AVIOContext
		AVIOContext pb = new AVIOContext();
		if (avio_open(pb, out_file, AVIO_FLAG_READ_WRITE) < 0) {
			System.err.println("Couldn't open output file.");
			return -1;
		}
		pFormatCtx.pb(pb);
		// 构建一个新stream
		AVCodec codec = null;
		AVStream pAVStream = avformat_new_stream(pFormatCtx, codec);
		if (pAVStream == null) {
			return -1;
		}
		// 设置该stream的信息
		AVCodecContext pCodecCtx = pAVStream.codec();
		pCodecCtx.codec_id(pFormatCtx.oformat().video_codec());
		pCodecCtx.codec_type(AVMEDIA_TYPE_VIDEO);
		pCodecCtx.pix_fmt(pFrame.format());
		pCodecCtx.width(width);
		pCodecCtx.height(height);
		pCodecCtx.time_base().num(1);
		pCodecCtx.time_base().den(25);
		// Begin Output some information
		av_dump_format(pFormatCtx, 0, out_file, 1);
		// End Output some information
		// 查找解码器
		AVCodec pCodec = avcodec_find_encoder(pCodecCtx.codec_id());
		if (pCodec == null) {
			System.err.println("Codec not found.");
			return -1;
		}
		// 设置pCodecCtx的解码器为pCodec
		if (avcodec_open2(pCodecCtx, pCodec, (PointerPointer) null) < 0) {
			System.err.println("Could not open codec.");
			return -1;
		}

		// Write Header
		avformat_write_header(pFormatCtx, (PointerPointer) null);

		int y_size = width * height;

		// 给AVPacket分配足够大的空间
		AVPacket pkt = new AVPacket();
		av_new_packet(pkt, y_size * 3);
		//
		int[] got_picture_arr = { 0 };
//		IntPointer got_picture = new IntPointer(got_picture_arr);
		int ret = avcodec_encode_video2(pCodecCtx, pkt, pFrame, got_picture_arr);
		if (ret < 0) {
			System.err.println("Encode Error.\n");
			return -1;
		}
		if (pkt != null && !pkt.isNull()) {
			// pkt.stream_index = pAVStream->index;
			ret = av_write_frame(pFormatCtx, pkt);
		}
		// Write Trailer
		if (av_write_trailer(pFormatCtx) >= 0) {
			System.err.println("Encode Successful.");
		}

		av_free_packet(pkt);

		if (pAVStream != null) {
			avcodec_close(pAVStream.codec());
		}

		if (pFormatCtx != null) {
			avio_close(pFormatCtx.pb());
			avformat_free_context(pFormatCtx);
		}

		return 0;
	}
 
Example #17
Source File: Muxer.java    From JavaAV with GNU General Public License v2.0 4 votes vote down vote up
public void open() throws Exception {
	formatContext = null;
	videoStream = null;
	audioStream = null;

       /* auto detect the output format from the name. */
	String formatName = null;
	if ((outputFormat = av_guess_format(formatName, outputPath, null)) == null) {
		int proto = outputPath.indexOf("://");
		if (proto > 0) {
			formatName = outputPath.substring(0, proto);
		}
		if ((outputFormat = av_guess_format(formatName, outputPath, null)) == null)
			throw new JavaAVException("Could not guess output format for " + outputPath);
	}

       /* allocate the output media context */
	if ((formatContext = avformat_alloc_context()) == null)
		throw new JavaAVException("Could not allocate format context");

	formatContext.oformat(outputFormat);
	formatContext.filename().putString(outputPath);

	if (getImageWidth() > 0 && getImageHeight() > 0) {
		outputFormat.video_codec(videoCodec.getID().value());

		if ((videoStream = avformat_new_stream(formatContext, videoCodec.getCodec())) == null) {
			release();
			throw new JavaAVException("Could not allocate video stream.");
		}

		videoEncoder = new Encoder(videoCodec, videoStream.codec());
		videoEncoder.setMediaType(MediaType.VIDEO);
		videoEncoder.setBitrate(getVideoBitrate());
		videoEncoder.setImageWidth((getImageWidth() + 15) / 16 * 16);
		videoEncoder.setImageHeight(getImageHeight());
		videoEncoder.setFramerate(getFramerate());
		videoEncoder.setGOPSize(getGOPSize());
		videoEncoder.setQuality(getVideoQuality());
		videoEncoder.setPixelFormat(getPixelFormat());
		videoEncoder.setProfile(AVCodecContext.FF_PROFILE_H264_CONSTRAINED_BASELINE);

		if ((outputFormat.flags() & AVFMT_GLOBALHEADER) != 0)
			videoEncoder.setFlag(CodecFlag.GLOBAL_HEADER);
	}

       /* add an audio output stream */
	if (getAudioChannels() > 0 && getAudioBitrate() > 0 && getSampleRate() > 0) {
		outputFormat.audio_codec(audioCodec.getID().value());

		audioStream = avformat_new_stream(formatContext, audioCodec.getCodec());

		if (audioStream == null) {
			release();
			throw new JavaAVException("Could not allocate audio stream.");
		}

		audioEncoder = new Encoder(audioCodec, audioStream.codec());
		audioEncoder.setMediaType(MediaType.AUDIO);
		audioEncoder.setBitrate(getAudioBitrate());
		audioEncoder.setSampleRate(getSampleRate());
		audioEncoder.setChannels(getAudioChannels());
		audioEncoder.setSampleFormat(getSampleFormat());
		audioEncoder.setQuality(getAudioQuality());

		if ((outputFormat.flags() & AVFMT_GLOBALHEADER) != 0)
			audioEncoder.setFlag(CodecFlag.GLOBAL_HEADER);
	}

	av_dump_format(formatContext, 0, outputPath, 1);

	if (videoStream != null)
		videoEncoder.open(videoOptions);

	if (audioStream != null)
		audioEncoder.open(audioOptions);

       /* open the output file */
	if ((outputFormat.flags() & AVFMT_NOFILE) == 0) {
		AVIOContext pb = new AVIOContext(null);
		if (avio_open(pb, outputPath, AVIO_FLAG_WRITE) < 0) {
			release();
			throw new JavaAVException("Could not open " + outputPath);
		}
		formatContext.pb(pb);
	}

       /* write the stream header*/
	avformat_write_header(formatContext, (AVDictionary) null);
}
 
Example #18
Source File: Codec.java    From JavaAV with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Initializes the {@code Codec} with a dictionary that may contain specific codec
 * parameters and a previously created codec context.
 *
 * @param avDictionary dictionary with codec parameters.
 * @param avContext    codec context.
 *
 * @return zero on success, a negative value on error.
 *
 * @throws JavaAVException if the codec could not be opened.
 */
int open(AVDictionary avDictionary, AVCodecContext avContext) throws JavaAVException {
	if (avContext == null)
		throw new JavaAVException("Could not open codec. Codec context is null.");

	this.avContext = avContext;

	return avcodec_open2(avContext, avCodec, avDictionary);
}
 
Example #19
Source File: Codec.java    From JavaAV with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Initializes the {@code Codec} with a dictionary that may contain specific
 * codec parameters.
 *
 * @param avDictionary dictionary with codec parameters.
 *
 * @return zero on success, a negative value on error.
 *
 * @throws JavaAVException if the codec could not be opened.
 */
int open(AVDictionary avDictionary) throws JavaAVException {
	AVCodecContext avContext = avcodec_alloc_context3(avCodec);

	return open(avDictionary, avContext);
}
 
Example #20
Source File: Codec.java    From JavaAV with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the codec context.
 *
 * @return the codec context.
 */
AVCodecContext getContext() {
	return avContext;
}