javaCV源代码简单分析:FFmpegFrameRecorder

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014253332/article/details/86520308

构造函数

public FFmpegFrameRecorder(String filename, int imageWidth, int imageHeight, int audioChannels)
//指定文件名、分辨率、音频通道数;初始化格式、编码器、比特率、采样率;分配AVPacket空间。

javaCV源码如下:

public FFmpegFrameRecorder(File file, int audioChannels) {
        this(file, 0, 0, audioChannels);
    }
    public FFmpegFrameRecorder(String filename, int audioChannels) {
        this(filename, 0, 0, audioChannels);
    }
    public FFmpegFrameRecorder(File file, int imageWidth, int imageHeight) {
        this(file, imageWidth, imageHeight, 0);
    }
    public FFmpegFrameRecorder(String filename, int imageWidth, int imageHeight) {
        this(filename, imageWidth, imageHeight, 0);
    }
    public FFmpegFrameRecorder(File file, int imageWidth, int imageHeight, int audioChannels) {
        this(file.getAbsolutePath(), imageWidth, imageHeight, audioChannels);
    }
    public FFmpegFrameRecorder(String filename, int imageWidth, int imageHeight, int audioChannels) {
        this.filename      = filename;
        this.imageWidth    = imageWidth;
        this.imageHeight   = imageHeight;
        this.audioChannels = audioChannels;

        this.pixelFormat   = AV_PIX_FMT_NONE;
        this.videoCodec    = AV_CODEC_ID_NONE;
        this.videoBitrate  = 400000;
        this.frameRate     = 30;

        this.sampleFormat  = AV_SAMPLE_FMT_NONE;
        this.audioCodec    = AV_CODEC_ID_NONE;
        this.audioBitrate  = 64000;
        this.sampleRate    = 44100;

        this.interleaved = true;

        this.video_pkt = new AVPacket();
        this.audio_pkt = new AVPacket();
    }

公共方法

public void start()
//创建并设置编码器、打开编码器、申请必要的编码缓存区。
public void record(Frame frame, int pixelFormat)
//转码视频并写入文件/推流
public boolean recordSample(int sampleRate, int audioChannels, Buffer... samples)
//转码音频并写入文件/推流,如果不指定sampleRate、audioChannels将由音频编码器决定
public void stop()
//flush所有buffer。finally会执行release()。
public void release()
//释放所有资源,当GC时会自动执行

属性:

private String filename;// 输出文件名
private AVFrame picture, tmp_picture;// 存放编码后的一帧图片的byte[]及相关信息
private BytePointer picture_buf;// 一帧图片的存储区域
private AVFrame frame;// 存放编码后的一帧音频的byte[]及相关信息
private BytePointer video_outbuf;// 输出视频的存储区域
private int video_outbuf_size;// 输出视频的存储区域的大小
private BytePointer audio_outbuf;// 输出音频的存储区域
private int audio_outbuf_size;// 输出音频的存储区域的大小
private Pointer[] samples_in;
private BytePointer[] samples_out;
private PointerPointer samples_in_ptr;
private PointerPointer samples_out_ptr;
private int audio_input_frame_size;// 输入音频一帧的大小
private AVOutputFormat oformat;// 输出视频格式
private AVFormatContext oc;
private AVCodec video_codec, audio_codec;// 编码器
private AVCodecContext video_c, audio_c;
private AVStream video_st, audio_st;// 流
private SwsContext img_convert_ctx;
private SwrContext samples_convert_ctx;
private int samples_channels, samples_format, samples_rate;
private AVPacket video_pkt, audio_pkt;
private int[] got_video_packet, got_audio_packet;

(图后补、源码解析后补)

猜你喜欢

转载自blog.csdn.net/u014253332/article/details/86520308