2016-08-10 19 views
0

avformat_alloc_contextとavio_alloc_contextでカスタムioを実装して、別の関数の出力をリアルタイムで読み取ることができます。この関数はboost asioスレッドでバッファを読み込み、ffmpegは別のスレッドからこのバッファを読み込みます。C言語のffmpeg用のカスタムリアルタイム入力

私はこの機能がに書き込むIOバッファを初期化し、ffmpegのは読み取る:私はmemsetをis explained hereを行うのはなぜ

BufferData input_buffer = {0}; 
input_buffer.size = 65536; 
input_buffer.ptr = (uint8_t *) av_malloc(buf_size); 
memset(input_buffer.ptr,'0',100); 

fprintf(stdout, "initialisation: buffer pointer %p buffer data pointer: %p\n", &input_buffer, input_buffer.ptr); 

。 そして、私がやったポインタアドレステストする:参照

typedef struct { 
    uint8_t *ptr; 
    size_t size; 
} BufferData; 

読み取り機能

static int read_function(void* opaque, uint8_t* buf, int buf_size) { 
    BufferData *bd = (BufferData *) opaque; 
    buf_size = FFMIN(buf_size, bd->size); 
    memcpy(buf, bd->ptr, buf_size); 
    bd->ptr += buf_size; //This seemed to cause the problem 
    bd->size -= buf_size; 
    return buf_size; 
} 

については

BufferData * decode_buffer; 
decode_buffer->size = 65536; 
decode_buffer->ptr = (uint8_t *) av_malloc(decode_buffer->size); 

AVIOContext * av_io_ctx = avio_alloc_context(decode_buffer->ptr, decode_buffer->size, 0, &input_buffer, &read_function, NULL, NULL); 

AVFormatContext *av_fmt_ctx = avformat_alloc_context(); 
av_fmt_ctx->pb = av_io_ctx; 


BufferData * tmpPtr = (BufferData *) video_input_file->av_io_ctx->opaque; 

fprintf(stdout, "video decoder before: buffer pointer %p, buffer data pointer: %p\n", tmpPtr, tmpPtr->ptr); 

open_res = avformat_open_input(&av_fmt_ctx, "anyname", in_fmt, options ? &options : NULL); 

fprintf(stdout, "video decoder after: buffer pointer %p, buffer data pointer: %p\n", tmpPtr, tmpPtr->ptr); 

を、結果が次のようになります。

initialisation: buffer pointer 0x7f2c4a613620, buffer data pointer: 0x7f2c48c56040 

video decoder before: buffer pointer 0x7f2c4a613620, buffer data pointer: 0x7f2c48c56040 

video decoder after: buffer pointer 0x7f2c4a613620, buffer data pointer: 0x7f2c49e24b50 

それは普通のbですか?バッファのデータptrがavformat_open_inputによって変更されていますか?私は別の関数でそれを使用しており、必要なメモリをmallocedして与えられた初期ポインタアドレスを保持したいので。

答えて

0

これは私の読み取り機能と関係があり、avformat_open_inputとは関係ありません。私はper described here(read_packet関数を参照)としてポインタ上に書いていました。それを考えると、読み込み関数がポインタを次のフレームの先頭にインクリメントしなければならないとしたら、それは意味がありました。

関連する問題