-
Notifications
You must be signed in to change notification settings - Fork 15
/
ffmpeg_utils.c
86 lines (73 loc) · 1.93 KB
/
ffmpeg_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (c)2008 Antonin Amand.
* Licensed under the Ruby License. See LICENSE for details.
*
*/
#include "ffmpeg.h"
#include "ffmpeg_utils.h"
AVFormatContext * get_format_context(VALUE self)
{
AVFormatContext * format_context = NULL;
Data_Get_Struct(self, AVFormatContext, format_context);
if (NULL == format_context) {
rb_fatal("FFMPEG internal error\n");
}
return format_context;
}
AVStream * get_stream(VALUE self)
{
AVStream * stream = NULL;
Data_Get_Struct(self, AVStream, stream);
if (NULL == stream) {
rb_fatal("FFMPEG internal error\n");
}
return stream;
}
AVCodecContext * get_codec_context(VALUE self)
{
AVCodecContext * codec_context = NULL;
Data_Get_Struct(self, AVCodecContext, codec_context);
if (NULL == codec_context) {
rb_fatal("FFMPEG internal error\n");
}
return codec_context;
}
AVFrame * get_frame(VALUE self)
{
AVFrame * frame = NULL;
Data_Get_Struct(self, AVFrame, frame);
if (NULL == frame) {
rb_fatal("FFMPEG internal error\n");
}
return frame;
}
VALUE rb_sym(const char *s) {
return rb_str_intern(rb_str_new2(s));
}
VALUE codec_type_id_to_sym(int codec_type)
{
VALUE type_sym;
switch(codec_type) {
case CODEC_TYPE_AUDIO:
type_sym = rb_sym("audio");
break;
case CODEC_TYPE_VIDEO:
type_sym = rb_sym("video");
break;
case CODEC_TYPE_SUBTITLE:
type_sym = rb_sym("subtitle");
break;
case CODEC_TYPE_DATA:
type_sym = rb_sym("data");
break;
case CODEC_TYPE_ATTACHMENT:
type_sym = rb_sym("attachment");
break;
case CODEC_TYPE_NB:
type_sym = rb_sym("nb");
break;
default:
type_sym = rb_sym("unknown");
break;
}
return type_sym;
}