ffmpeg-video-info 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db934e39423d4e7d8b7f3b47ae5493f3ce6c78a6
4
+ data.tar.gz: 964c730cae6b24ad1572d7786c4a9c4cf186813f
5
+ SHA512:
6
+ metadata.gz: 4e427ff3305f151807767e2a8fffc2cae785458b16b7f9bb06abfdbc6463c721715fc4c8ed63aadd177dfef4a6bbb8fc13f570fb41c4dffb6844afb0d87dd700
7
+ data.tar.gz: 05921d06d1d088dfc72b7967ff480267d86b51a6450117a7561ee1d1113c39108a5032566cbf8049b4a1bbb5608d8c21d0d161af100d6ff8bd0416fb4c6b2353
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rdoc", "~> 3.12"
10
+ gem "bundler", "~> 1.0"
11
+ gem "jeweler", "~> 1.8.7"
12
+ gem "rspec"
13
+ gem "rake-compiler"
14
+ end
@@ -0,0 +1,66 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ diff-lcs (1.2.5)
7
+ faraday (0.8.8)
8
+ multipart-post (~> 1.2.0)
9
+ git (1.2.6)
10
+ github_api (0.10.1)
11
+ addressable
12
+ faraday (~> 0.8.1)
13
+ hashie (>= 1.2)
14
+ multi_json (~> 1.4)
15
+ nokogiri (~> 1.5.2)
16
+ oauth2
17
+ hashie (2.0.5)
18
+ highline (1.6.20)
19
+ httpauth (0.2.0)
20
+ jeweler (1.8.8)
21
+ builder
22
+ bundler (~> 1.0)
23
+ git (>= 1.2.5)
24
+ github_api (= 0.10.1)
25
+ highline (>= 1.6.15)
26
+ nokogiri (= 1.5.10)
27
+ rake
28
+ rdoc
29
+ json (1.8.1)
30
+ jwt (0.1.8)
31
+ multi_json (>= 1.5)
32
+ multi_json (1.8.2)
33
+ multi_xml (0.5.5)
34
+ multipart-post (1.2.0)
35
+ nokogiri (1.5.10)
36
+ oauth2 (0.9.2)
37
+ faraday (~> 0.8)
38
+ httpauth (~> 0.2)
39
+ jwt (~> 0.1.4)
40
+ multi_json (~> 1.0)
41
+ multi_xml (~> 0.5)
42
+ rack (~> 1.2)
43
+ rack (1.5.2)
44
+ rake (10.1.0)
45
+ rake-compiler (0.9.2)
46
+ rake
47
+ rdoc (3.12.2)
48
+ json (~> 1.4)
49
+ rspec (2.14.1)
50
+ rspec-core (~> 2.14.0)
51
+ rspec-expectations (~> 2.14.0)
52
+ rspec-mocks (~> 2.14.0)
53
+ rspec-core (2.14.7)
54
+ rspec-expectations (2.14.4)
55
+ diff-lcs (>= 1.1.3, < 2.0)
56
+ rspec-mocks (2.14.4)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.0)
63
+ jeweler (~> 1.8.7)
64
+ rake-compiler
65
+ rdoc (~> 3.12)
66
+ rspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Pavel Tatarsky
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = ffmpeg-video-info
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ffmpeg-video-info
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Pavel Tatarsky. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "ffmpeg-video-info"
16
+ gem.homepage = "http://github.com/vintikzzz/ffmpeg-video-info"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby binding for FFmpeg library}
19
+ gem.description = %Q{It only provides gathering info about media files}
20
+ gem.email = "fazzzenda@mail.ru"
21
+ gem.authors = ["Pavel Tatarsky"]
22
+ # dependencies defined in Gemfile
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
25
+
26
+ require 'rdoc/task'
27
+ Rake::RDocTask.new do |rdoc|
28
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
29
+
30
+ rdoc.rdoc_dir = 'rdoc'
31
+ rdoc.title = "ffmpeg-video-info #{version}"
32
+ rdoc.rdoc_files.include('README*')
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ end
35
+
36
+ require "rake/extensiontask"
37
+ Rake::ExtensionTask.new('ffmpeg_video_info')
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,5 @@
1
+ require "mkmf"
2
+
3
+ have_library('avcodec') or raise
4
+ have_library('avformat') or raise
5
+ create_makefile('ffmpeg_video_info')
@@ -0,0 +1,341 @@
1
+ #include <ruby.h>
2
+ #include <libavcodec/avcodec.h>
3
+ #include <libavformat/avformat.h>
4
+ #include <stdio.h>
5
+
6
+ void my_av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output, VALUE res)
7
+ {
8
+ int i;
9
+ uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
10
+ if (ic->nb_streams && !printed)
11
+ return;
12
+
13
+ rb_hash_aset(res, rb_str_new2("format_name"), rb_str_new2(ic->iformat->name));
14
+ rb_hash_aset(res, rb_str_new2("file_name"), rb_str_new2(url));
15
+ VALUE metadata = rb_hash_new();
16
+ my_dump_metadata(NULL, ic->metadata, " ", metadata);
17
+ rb_hash_aset(res, rb_str_new2("metadata"), metadata);
18
+ if (!is_output) {
19
+ if (ic->duration != AV_NOPTS_VALUE) {
20
+ int hours, mins, secs, us;
21
+ int64_t duration = ic->duration + 5000;
22
+ secs = duration / AV_TIME_BASE;
23
+ us = duration % AV_TIME_BASE;
24
+ mins = secs / 60;
25
+ secs %= 60;
26
+ hours = mins / 60;
27
+ mins %= 60;
28
+ // av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
29
+ // (100 * us) / AV_TIME_BASE);
30
+ rb_hash_aset(res, rb_str_new2("duration"), INT2FIX(hours*3600 + mins*60 + secs));
31
+ }
32
+ if (ic->start_time != AV_NOPTS_VALUE) {
33
+ int secs, us;
34
+ secs = ic->start_time / AV_TIME_BASE;
35
+ us = abs(ic->start_time % AV_TIME_BASE);
36
+ rb_hash_aset(res, rb_str_new2("start"), INT2FIX((int)av_rescale(us, 1000000, AV_TIME_BASE)));
37
+ }
38
+ if (ic->bit_rate) {
39
+ rb_hash_aset(res, rb_str_new2("bitrate"), INT2FIX(ic->bit_rate));
40
+ }
41
+ }
42
+ // for (i = 0; i < ic->nb_chapters; i++) {
43
+ // AVChapter *ch = ic->chapters[i];
44
+ // av_log(NULL, AV_LOG_INFO, " Chapter #%d.%d: ", index, i);
45
+ // av_log(NULL, AV_LOG_INFO, "start %f, ", ch->start * av_q2d(ch->time_base));
46
+ // av_log(NULL, AV_LOG_INFO, "end %f\n", ch->end * av_q2d(ch->time_base));
47
+
48
+ // VALUE metadata = rb_hash_new();
49
+ // my_dump_metadata(NULL, ch->metadata, " ", metadata);
50
+ // }
51
+ // if(ic->nb_programs) {
52
+ // int j, k, total = 0;
53
+ // for(j=0; j<ic->nb_programs; j++) {
54
+ // AVDictionaryEntry *name = av_dict_get(ic->programs[j]->metadata,
55
+ // "name", NULL, 0);
56
+ // av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id,
57
+ // name ? name->value : "");
58
+ // VALUE metadata = rb_hash_new();
59
+ // my_dump_metadata(NULL, ic->programs[j]->metadata, " ", metadata);
60
+ // for(k=0; k<ic->programs[j]->nb_stream_indexes; k++) {
61
+ // my_dump_stream_format(ic, ic->programs[j]->stream_index[k], index, is_output, res);
62
+ // printed[ic->programs[j]->stream_index[k]] = 1;
63
+ // }
64
+ // total += ic->programs[j]->nb_stream_indexes;
65
+ // }
66
+ // if (total < ic->nb_streams)
67
+ // av_log(NULL, AV_LOG_INFO, " No Program\n");
68
+ // }
69
+ VALUE streams = rb_ary_new();
70
+ for(i=0;i<ic->nb_streams;i++)
71
+ {
72
+ if (!printed[i])
73
+ {
74
+ VALUE stream = rb_hash_new();
75
+ my_dump_stream_format(ic, i, index, is_output, stream);
76
+ rb_ary_push(streams, stream);
77
+ }
78
+ }
79
+ rb_hash_aset(res, rb_str_new2("streams"), streams);
80
+
81
+ av_free(printed);
82
+ }
83
+ void my_avcodec_string(AVCodecContext *enc, int encode, VALUE res)
84
+ {
85
+ const char *codec_type;
86
+ const char *codec_name;
87
+ const char *profile = NULL;
88
+ const AVCodec *p;
89
+ int bitrate;
90
+ AVRational display_aspect_ratio;
91
+
92
+ codec_type = av_get_media_type_string(enc->codec_type);
93
+ codec_name = avcodec_get_name(enc->codec_id);
94
+ if (enc->profile != FF_PROFILE_UNKNOWN) {
95
+ if (enc->codec)
96
+ p = enc->codec;
97
+ else
98
+ p = encode ? avcodec_find_encoder(enc->codec_id) :
99
+ avcodec_find_decoder(enc->codec_id);
100
+ if (p)
101
+ profile = av_get_profile_name(p, enc->profile);
102
+ }
103
+
104
+ rb_hash_aset(res, rb_str_new2("type"), rb_str_new2(codec_type ? codec_type : "unknown"));
105
+ rb_hash_aset(res, rb_str_new2("name"), rb_str_new2(codec_name));
106
+
107
+ if (enc->codec && strcmp(enc->codec->name, codec_name))
108
+ rb_hash_aset(res, rb_str_new2("codec_name"), rb_str_new2(enc->codec->name));
109
+
110
+ if (profile)
111
+ rb_hash_aset(res, rb_str_new2("profile"), rb_str_new2(profile));
112
+ if (enc->codec_tag) {
113
+ char tag_buf[32];
114
+ av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
115
+ rb_hash_aset(res, rb_str_new2("codec_tag"), rb_str_new2(tag_buf));
116
+ }
117
+
118
+ switch (enc->codec_type) {
119
+ case AVMEDIA_TYPE_VIDEO:
120
+ if (enc->pix_fmt != AV_PIX_FMT_NONE) {
121
+ const char *colorspace_name;
122
+ // rb_hash_aset(res, rb_str_new2("pixel_format"), rb_str_new2(av_get_pix_fmt_name(enc->pix_fmt)));
123
+ // if (enc->bits_per_raw_sample &&
124
+ // enc->bits_per_raw_sample <= my_av_pix_fmt_desc_get(enc->pix_fmt)->comp[0].depth_minus1)
125
+ // av_strlcatf(detail, sizeof(detail), "%d bpc, ", enc->bits_per_raw_sample);
126
+ // if (enc->color_range != AVCOL_RANGE_UNSPECIFIED)
127
+ // av_strlcatf(detail, sizeof(detail),
128
+ // enc->color_range == AVCOL_RANGE_MPEG ? "tv, ": "pc, ");
129
+
130
+ colorspace_name = av_get_colorspace_name(enc->colorspace);
131
+ if (colorspace_name)
132
+ rb_hash_aset(res, rb_str_new2("color_space"), rb_str_new2(colorspace_name));
133
+
134
+ }
135
+ if (enc->width) {
136
+ rb_hash_aset(res, rb_str_new2("width"), INT2FIX(enc->width));
137
+ rb_hash_aset(res, rb_str_new2("height"), INT2FIX(enc->height));
138
+ if (enc->sample_aspect_ratio.num) {
139
+ av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
140
+ enc->width * enc->sample_aspect_ratio.num,
141
+ enc->height * enc->sample_aspect_ratio.den,
142
+ 1024 * 1024);
143
+ VALUE sar = rb_hash_new();
144
+ rb_hash_aset(sar, rb_str_new2("width"), INT2FIX(enc->sample_aspect_ratio.num));
145
+ rb_hash_aset(sar, rb_str_new2("height"), INT2FIX(enc->sample_aspect_ratio.den));
146
+ rb_hash_aset(res, rb_str_new2("SAR"), sar);
147
+ VALUE dar = rb_hash_new();
148
+ rb_hash_aset(dar, rb_str_new2("width"), INT2FIX(display_aspect_ratio.num));
149
+ rb_hash_aset(dar, rb_str_new2("height"), INT2FIX(display_aspect_ratio.den));
150
+ rb_hash_aset(res, rb_str_new2("SAR"), dar);
151
+ }
152
+ // if (av_log_get_level() >= AV_LOG_DEBUG) {
153
+ // int g = av_gcd(enc->time_base.num, enc->time_base.den);
154
+ // snprintf(buf + strlen(buf), buf_size - strlen(buf),
155
+ // ", %d/%d",
156
+ // enc->time_base.num / g, enc->time_base.den / g);
157
+ // }
158
+ }
159
+ if (encode) {
160
+ rb_hash_aset(res, rb_str_new2("qmin"), INT2FIX(enc->qmin));
161
+ rb_hash_aset(res, rb_str_new2("qmax"), INT2FIX(enc->qmax));
162
+ }
163
+ break;
164
+ case AVMEDIA_TYPE_AUDIO:
165
+ if (enc->sample_rate) {
166
+ rb_hash_aset(res, rb_str_new2("sample_rate"), INT2FIX(enc->sample_rate));
167
+ }
168
+ char layout_buf[32];
169
+ av_get_channel_layout_string(layout_buf, sizeof(layout_buf), enc->channels, enc->channel_layout);
170
+ rb_hash_aset(res, rb_str_new2("channel_layout"), rb_str_new2(layout_buf));
171
+ if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
172
+ rb_hash_aset(res, rb_str_new2("sample_format"), rb_str_new2(av_get_sample_fmt_name(enc->sample_fmt)));
173
+ }
174
+ break;
175
+ case AVMEDIA_TYPE_DATA:
176
+ // if (av_log_get_level() >= AV_LOG_DEBUG) {
177
+ // int g = av_gcd(enc->time_base.num, enc->time_base.den);
178
+ // if (g)
179
+ // snprintf(buf + strlen(buf), buf_size - strlen(buf),
180
+ // ", %d/%d",
181
+ // enc->time_base.num / g, enc->time_base.den / g);
182
+ // }
183
+ break;
184
+ case AVMEDIA_TYPE_SUBTITLE:
185
+ if (enc->width)
186
+ rb_hash_aset(res, rb_str_new2("width"), INT2FIX(enc->width));
187
+ rb_hash_aset(res, rb_str_new2("height"), INT2FIX(enc->height));
188
+ break;
189
+ default:
190
+ return;
191
+ }
192
+ if (encode) {
193
+ if (enc->flags & CODEC_FLAG_PASS1)
194
+ rb_hash_aset(res, rb_str_new2("pass"), INT2FIX(1));
195
+ if (enc->flags & CODEC_FLAG_PASS2)
196
+ rb_hash_aset(res, rb_str_new2("pass"), INT2FIX(2));
197
+ }
198
+ bitrate = get_bit_rate(enc);
199
+ if (bitrate != 0) {
200
+ rb_hash_aset(res, rb_str_new2("bitrate"), INT2FIX(bitrate));
201
+ } else if (enc->rc_max_rate > 0) {
202
+ rb_hash_aset(res, rb_str_new2("bitrate"), INT2FIX(enc->rc_max_rate));
203
+ }
204
+ }
205
+ int get_bit_rate(AVCodecContext *ctx)
206
+ {
207
+ int bit_rate;
208
+ int bits_per_sample;
209
+
210
+ switch (ctx->codec_type) {
211
+ case AVMEDIA_TYPE_VIDEO:
212
+ case AVMEDIA_TYPE_DATA:
213
+ case AVMEDIA_TYPE_SUBTITLE:
214
+ case AVMEDIA_TYPE_ATTACHMENT:
215
+ bit_rate = ctx->bit_rate;
216
+ break;
217
+ case AVMEDIA_TYPE_AUDIO:
218
+ bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
219
+ bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
220
+ break;
221
+ default:
222
+ bit_rate = 0;
223
+ break;
224
+ }
225
+ return bit_rate;
226
+ }
227
+
228
+ void my_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output, VALUE res)
229
+ {
230
+ int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
231
+ AVStream *st = ic->streams[i];
232
+ int g = av_gcd(st->time_base.num, st->time_base.den);
233
+ AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
234
+ my_avcodec_string(st->codec, is_output, res);
235
+ /* the pid is an important information, so we display it */
236
+ /* XXX: add a generic system */
237
+ if (flags & AVFMT_SHOW_IDS)
238
+ rb_hash_aset(res, rb_str_new2("show_id"), INT2FIX(st->id));
239
+ if (lang)
240
+ rb_hash_aset(res, rb_str_new2("language"), rb_str_new2(lang->value));
241
+ if (st->sample_aspect_ratio.num && // default
242
+ av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
243
+ AVRational display_aspect_ratio;
244
+ av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
245
+ st->codec->width*st->sample_aspect_ratio.num,
246
+ st->codec->height*st->sample_aspect_ratio.den,
247
+ 1024*1024);
248
+ VALUE sar = rb_hash_new();
249
+ rb_hash_aset(sar, rb_str_new2("width"), INT2FIX(st->sample_aspect_ratio.num));
250
+ rb_hash_aset(sar, rb_str_new2("height"), INT2FIX(st->sample_aspect_ratio.den));
251
+ rb_hash_aset(res, rb_str_new2("SAR"), sar);
252
+ VALUE dar = rb_hash_new();
253
+ rb_hash_aset(dar, rb_str_new2("width"), INT2FIX(display_aspect_ratio.num));
254
+ rb_hash_aset(dar, rb_str_new2("height"), INT2FIX(display_aspect_ratio.den));
255
+ rb_hash_aset(res, rb_str_new2("SAR"), dar);
256
+ }
257
+ if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
258
+ if(st->avg_frame_rate.den && st->avg_frame_rate.num)
259
+ rb_hash_aset(res, rb_str_new2("fps"), INT2FIX(av_q2d(st->avg_frame_rate)));
260
+ }
261
+ if (st->disposition & AV_DISPOSITION_DEFAULT)
262
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("default"));
263
+ if (st->disposition & AV_DISPOSITION_DUB)
264
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("dub"));
265
+ if (st->disposition & AV_DISPOSITION_ORIGINAL)
266
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("original"));
267
+ if (st->disposition & AV_DISPOSITION_COMMENT)
268
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("comment"));
269
+ if (st->disposition & AV_DISPOSITION_LYRICS)
270
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("lyrics"));
271
+ if (st->disposition & AV_DISPOSITION_KARAOKE)
272
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("karaoke"));
273
+ if (st->disposition & AV_DISPOSITION_FORCED)
274
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("forced"));
275
+ if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
276
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("hearing impaired"));
277
+ if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
278
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("visual impaired"));
279
+ if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
280
+ rb_hash_aset(res, rb_str_new2("disposition"), rb_str_new2("clean effects"));
281
+ VALUE metadata = rb_hash_new();
282
+ my_dump_metadata(NULL, st->metadata, " ", metadata);
283
+ rb_hash_aset(res, rb_str_new2("metadata"), metadata);
284
+ }
285
+ void my_dump_metadata(void *ctx, AVDictionary *m, const char *indent, VALUE res)
286
+ {
287
+ if(m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))){
288
+ AVDictionaryEntry *tag=NULL;
289
+
290
+ while((tag=av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
291
+ if(strcmp("language", tag->key)){
292
+ const char *p = tag->value;
293
+ while(*p) {
294
+ char tmp[256];
295
+ size_t len = strcspn(p, "\x8\xa\xb\xc\xd");
296
+ av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1));
297
+ rb_hash_aset(res, rb_str_new2(tag->key), rb_str_new2(tmp));
298
+ p += len;
299
+ if (*p) p++;
300
+ }
301
+ }
302
+ }
303
+ }
304
+ }
305
+
306
+ VALUE get_info(VALUE self, VALUE arg)
307
+ {
308
+ const char* file = StringValueCStr(arg);
309
+ VALUE res = rb_hash_new();
310
+ // Register all available file formats and codecs
311
+ av_register_all();
312
+
313
+ int err;
314
+
315
+ // Open video file
316
+ AVFormatContext* format_context = NULL;
317
+ err = avformat_open_input(&format_context, file, NULL, NULL);
318
+ if (err < 0) {
319
+ rb_raise(rb_eRuntimeError, "ffmpeg: Unable to open input file");
320
+ }
321
+
322
+ // Retrieve stream information
323
+ err = avformat_find_stream_info(format_context, NULL);
324
+ if (err < 0) {
325
+ rb_raise(rb_eRuntimeError, "ffmpeg: Unable to find stream info");
326
+ }
327
+
328
+ // Dump information about file onto standard error
329
+ my_av_dump_format(format_context, 0, file, 0, res);
330
+
331
+ // Close the video file
332
+ avformat_close_input(&format_context);
333
+
334
+ return res;
335
+ }
336
+ static VALUE rb_mFFmpegVideoInfo;
337
+ void Init_ffmpeg_video_info()
338
+ {
339
+ rb_mFFmpegVideoInfo = rb_define_module("FFmpegVideoInfo");
340
+ rb_define_singleton_method(rb_mFFmpegVideoInfo, "get", get_info, 1);
341
+ }
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "ffmpeg-video-info"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Pavel Tatarsky"]
12
+ s.date = "2013-11-30"
13
+ s.description = "It only provides gathering info about media files"
14
+ s.email = "fazzzenda@mail.ru"
15
+ s.extensions = ["ext/ffmpeg_video_info/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "ext/ffmpeg_video_info/extconf.rb",
29
+ "ext/ffmpeg_video_info/ffmpeg_video_info.c",
30
+ "ffmpeg-video-info.gemspec",
31
+ "spec/fixtures/test.mp4",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = "http://github.com/vintikzzz/ffmpeg-video-info"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "2.0.5"
38
+ s.summary = "Ruby binding for FFmpeg library"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ s.add_development_dependency(%q<rake-compiler>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
53
+ s.add_dependency(%q<rspec>, [">= 0"])
54
+ s.add_dependency(%q<rake-compiler>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
60
+ s.add_dependency(%q<rspec>, [">= 0"])
61
+ s.add_dependency(%q<rake-compiler>, [">= 0"])
62
+ end
63
+ end
64
+
Binary file
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ Dir.chdir File.dirname(File.dirname(__FILE__))
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffmpeg-video-info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Tatarsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-compiler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: It only provides gathering info about media files
84
+ email: fazzzenda@mail.ru
85
+ executables: []
86
+ extensions:
87
+ - ext/ffmpeg_video_info/extconf.rb
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.rdoc
97
+ - Rakefile
98
+ - VERSION
99
+ - ext/ffmpeg_video_info/extconf.rb
100
+ - ext/ffmpeg_video_info/ffmpeg_video_info.c
101
+ - ffmpeg-video-info.gemspec
102
+ - spec/fixtures/test.mp4
103
+ - spec/spec_helper.rb
104
+ homepage: http://github.com/vintikzzz/ffmpeg-video-info
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Ruby binding for FFmpeg library
128
+ test_files: []