3 Nisan 2019 Çarşamba

ffmpeg API

Giriş
- libavcodec-extra : ffmpeg library with additional de/encoders for audio/video codecs anlamına gelir.

- libavformat : ffmpeg library with (de)muxers for multimedia containers - runtime files anlamına gelir. Açıklaması şöyle.
ffmpeg calls the libavformat library (containing demuxers) to read input files and get packets containing encoded data from them... Encoded packets are then passed to the decoder... The decoder produces uncompressed frames (raw video/PCM audio/...) which can be processed further by filtering...
- libavutil : ffmpeg library with functions for simplifying programming - runtime files anlamına gelir.
avcodec_receive_frame metodu
Şöyle yaparız
static void decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt,
                   const char *filename)
{
    char buf[1024];
    int ret;
    ret = avcodec_send_packet(dec_ctx, pkt);
    if (ret < 0) {
        fprintf(stderr, "Error sending a packet for decoding\n");
        exit(1);
    }
    while (ret >= 0) {
        ret = avcodec_receive_frame(dec_ctx, frame);
        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
            return;
        else if (ret < 0) {
            fprintf(stderr, "Error during decoding\n");
            exit(1);
        }
        printf("saving frame %3d\n", dec_ctx->frame_number);
        fflush(stdout);
        /* the picture is allocated by the decoder. no need to
           free it */
        snprintf(buf, sizeof(buf), filename, dec_ctx->frame_number);
        pgm_save(frame->data[0], frame->linesize[0],
                 frame->width, frame->height, buf);
    }
}
avformat_alloc_output_context2 metodu
Şöyle yaparız.
AVFormatContext* ofmt_ctx = NULL;

avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, "out_filename");
if (!ofmt_ctx) {
  //error

}
Şöyle silinir.
avformat_free_context(ofmt_ctx);
av_dump_format metodu
Şöyle yaparız.
AVFormatContext* ifmt_ctx = ...;
av_dump_format(ifmt_ctx, 0, "in_filename", 0);
av_file_map metodu
Şöyle yaparız.
int retOp; // for holding the operations results


// Open image
uint8_t *buffer = NULL;
size_t buffer_size;
retOp = av_file_map("in.png", &buffer, &buffer_size, 0, NULL);
if(retOp < 0){
  cerr << "Could not load image!" << endl;
  return -1;
}
avformat_find_stream_info metodu
Şöyle yaparız.
AVFormatContext* ifmt_ctx =...;
if (avformat_find_stream_info(ifmt_ctx, 0) < 0) {
  //error
}
avformat_open_input metodu
Şöyle yaparız.
AVFormatContext* ifmt_ctx = NULL;
if ((avformat_open_input(&ifmt_ctx, "in_filename", 0, 0) < 0) {
  //error
}
Şöyle yaparız.
avformat_close_input(&ifmt_ctx)
Girdinin stream'leri şöyle dolaşılır.
for (i = 0; i < ifmt_ctx->nb_streams; i++) {
  AVStream *in_stream = ifmt_ctx->streams[i];
  ...
}
av_register_all metodu
Örnek
Şöyle yaparız.
av_register_all();
Örnek
Şöyle yaparız.
// Initializes FFmpeg
av_register_all();
Örnek
Şöyle yaparız.
av_register_all();
avcodec_register_all();
avdevice_register_all();
avformat_network_init();


Hiç yorum yok:

Yorum Gönder