/
stream.rb
158 lines (113 loc) · 3.43 KB
/
stream.rb
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
class FFMPEG::Stream
inline :C do |builder|
FFMPEG.builder_defaults builder
##
# :singleton-method: from
builder.c_singleton <<-C
VALUE from(VALUE _format_context, int index) {
AVFormatContext *format_context;
VALUE obj;
int idx = index;
Data_Get_Struct(_format_context, AVFormatContext, format_context);
obj = Data_Wrap_Struct(self, 0, 0,
format_context->streams[idx]);
rb_funcall(obj, rb_intern("initialize"), 1, _format_context);
return obj;
}
C
##
# :method: codec_context
builder.c <<-C
VALUE codec_context() {
VALUE codec_context_klass;
codec_context_klass = rb_path2class("FFMPEG::CodecContext");
return rb_funcall(codec_context_klass, rb_intern("from"), 1, self);
}
C
##
# :method: context_defaults
builder.c <<-C
VALUE context_defaults(int codec_type) {
AVStream *stream;
Data_Get_Struct(self, AVStream, stream);
avcodec_get_context_defaults2(stream->codec, codec_type);
return self;
}
C
##
# :method: r_frame_rate
builder.c <<-C
VALUE r_frame_rate() {
AVStream *stream;
AVRational *r_frame_rate;
Data_Get_Struct(self, AVStream, stream);
r_frame_rate = &(stream->r_frame_rate);
return ffmpeg_rat2obj(r_frame_rate);
}
C
##
# :method: r_frame_rate=
builder.c <<-C
VALUE r_frame_rate_equals(VALUE value) {
AVStream *stream;
Data_Get_Struct(self, AVStream, stream);
stream->r_frame_rate.num = FIX2INT(rb_funcall(value, rb_intern("num"), 0));
stream->r_frame_rate.den = FIX2INT(rb_funcall(value, rb_intern("den"), 0));
return ffmpeg_rat2obj(&(stream->r_frame_rate));
}
C
##
# :method: time_base
builder.c <<-C
VALUE time_base() {
AVStream *stream;
AVRational *time_base;
Data_Get_Struct(self, AVStream, stream);
time_base = &(stream->time_base);
return ffmpeg_rat2obj(time_base);
}
C
##
# :method: time_base=
builder.c <<-C
VALUE time_base_equals(VALUE value) {
AVStream *stream;
Data_Get_Struct(self, AVStream, stream);
stream->time_base.num = FIX2INT(rb_funcall(value, rb_intern("num"), 0));
stream->time_base.den = FIX2INT(rb_funcall(value, rb_intern("den"), 0));
return ffmpeg_rat2obj(&(stream->time_base));
}
C
builder.struct_name = 'AVStream'
builder.accessor :id, 'int'
builder.accessor :last_IP_duration, 'int'
builder.accessor :nb_index_entries, 'int'
builder.accessor :stream_index, 'int', :index
builder.accessor :cur_dts, 'int64_t'
builder.accessor :duration, 'int64_t'
builder.accessor :last_IP_pts, 'int64_t'
builder.accessor :nb_frames, 'int64_t'
builder.accessor :start_time, 'int64_t'
builder.accessor :quality, 'double'
end
##
# FIFO for audio streams
attr_accessor :fifo
attr_reader :format_context
attr_accessor :next_pts
attr_accessor :pts
attr_accessor :sync_pts
def initialize(format_context=nil)
@format_context = format_context
@next_pts = FFMPEG::NOPTS_VALUE
@pts = 0
@sync_pts = 0
@fifo = nil
end
def inspect
"#<%s:%x %s>" % [self.class, object_id, codec_context.codec_type]
end
def type
codec_context.codec_type
end
end