Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ffmpeg4r_avformat.h"
- VALUE r_av_register_all( void ) {
- av_register_all();
- return Qnil;
- };
- VALUE r_avformat_context_allocate(VALUE klass) {
- AVFormatContext *ctx = avformat_alloc_context();
- return Data_Wrap_Struct(klass, NULL, r_avformat_context_free, ctx);
- }
- void r_avformat_context_mark(void *p){
- };
- void r_avformat_context_free(void *p) {
- AVFormatContext *ctx = (AVFormatContext *) p;
- if (ctx) {
- avformat_free_context(ctx);
- }
- };
- VALUE r_avformat_open_input_file(VALUE self, VALUE context, VALUE filename) {
- AVFormatContext *ctx;
- char* fn;
- int res = -1;
- Check_Type(filename, T_STRING);
- Data_Get_Struct(context, AVFormatContext, ctx);
- fn = StringValuePtr(filename);
- res = avformat_open_input(&ctx, fn, NULL, NULL);
- return INT2NUM(res);
- };
- VALUE r_avformat_close_input_file(VALUE self, VALUE context) {
- AVFormatContext *ctx;
- Data_Get_Struct(context, AVFormatContext, ctx);
- avformat_close_input(&ctx);
- ctx = NULL;
- return Qnil;
- };
- VALUE r_avformat_context_metadata(VALUE self) {
- AVFormatContext *ctx;
- AVDictionaryEntry *t = NULL;
- VALUE result = rb_hash_new();
- Data_Get_Struct(self, AVFormatContext, ctx);
- while (t = av_dict_get(ctx->metadata, "", t, AV_DICT_IGNORE_SUFFIX)) {
- rb_hash_aset(result, rb_str_new2(t->key), rb_str_new2(t->value));
- }
- return result;
- };
- VALUE r_avformat_context_initialize(VALUE self) {
- return self;
- }
- void Init_ffmpeg4r_avformat(VALUE module) {
- mAVFormat = rb_define_module_under(module, "AVFormat");
- rb_define_module_function(mAVFormat, "av_register_all", r_av_register_all, 0);
- rb_define_module_function(mAVFormat, "avformat_open_input_file", r_avformat_open_input_file, 2);
- rb_define_module_function(mAVFormat, "avformat_close_input_file", r_avformat_close_input_file, 1);
- // FFmpeg4r::AVFormat::AVFormatContext
- cAVFormatContext = rb_define_class_under(mAVFormat, "AVFormatContext", rb_cObject);
- rb_define_alloc_func(cAVFormatContext, r_avformat_context_allocate);
- rb_define_method(cAVFormatContext, "initialize", r_avformat_context_initialize, 0);
- rb_define_method(cAVFormatContext, "metadata", r_avformat_context_metadata, 0);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement