Java Code Examples for org.bytedeco.javacpp.avcodec.AVCodecContext#codec_type()
The following examples show how to use
org.bytedeco.javacpp.avcodec.AVCodecContext#codec_type() .
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 | 5 votes |
/** * 获取第一帧视频位置 * @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 2
Source File: FFmpegRecorder.java From easyCV with Apache License 2.0 | 5 votes |
/** * 获取第一帧视频位置 * @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 3
Source File: TestPusher.java From easyCV with Apache License 2.0 | 5 votes |
/** * 获取第一帧视频位置 * * @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 4
Source File: TestFFmpeg.java From easyCV with Apache License 2.0 | 4 votes |
/** * 把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; }