This gem library is an ISO Base Media File Format (BMFF) parser. You can parse BMFF file. And you may be able to parse a file related to BMFF like MP4.
Add this line to your application's Gemfile:
gem 'bmff'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bmff
require "bmff"
def print_box(box, level = 0)
puts "#{' ' * level}#{box.type} #{box.class}"
if box.container?
box.children.each do |child|
print_box(child, level + 1)
end
end
end
open("/path/to/video.mp4", "rb:ascii-8bit") do |f|
file_container = BMFF::FileContainer.parse(f)
file_container.boxes.each do |box|
print_box(box)
end
end
require "bmff"
open("/path/to/video.mp4", "rb:ascii-8bit") do |f|
file_container = BMFF::FileContainer.parse(f)
media_header = file_container.select_descendants(BMFF::Box::MediaHeader).first
if media_header
puts media_header.duration / media_header.timescale.to_f
end
end
require "bmff"
open("/path/to/video.ismv", "rb:ascii-8bit") do |f|
file_container = BMFF::FileContainer.parse(f)
file_container.select_descendants(BMFF::Box::TrackRun).each do |track_run|
puts track_run.sample_duration.inject {|result, item| result + item}
end
end
Box Name | Type | Status |
---|---|---|
File Type Box | ftyp | OK |
Media Data Box | mdat | OK |
Free Space Box | free, skip | OK |
Progressive Download Information Box | pdin | OK |
Movie Box | moov | OK |
Movie Header Box | mvhd | OK |
Track Box | trak | OK |
Track Header Box | tkhd | OK |
Track Reference Box | tref | OK |
Track Group Box | trgr | OK |
Media Box | mdia | OK |
Media Header Box | mdhd | OK |
Handler Reference Box | hdlr | OK |
Media Information Box | minf | OK |
Video Media Header Box | vmhd | OK |
Sound Media Header Box | smhd | OK |
Hint Media Header Box | hmhd | OK |
Null Media Header Box | nmhd | OK |
Sample Table Box | stbl | OK |
Sample Description Box | stsd | OK |
Degradation Priority Box | stdp | OK |
Decoding Time to Sample Box | stts | OK |
Composition Time to Sample Box | ctts | OK |
Composition to Decode Box | cslg | OK |
Sync Sample Box | stss | OK |
Shadow Sync Sample Box | stsh | OK |
Independent and Disposable Samples Box | sdtp | OK |
Edit Box | edts | OK |
Edit List Box | elst | OK |
Data Information Box | dinf | OK |
Data Reference Box | url , urn , dref | OK |
Sample Size Box | stsz | OK |
Compact Sample Size Box | stz2 | OK |
Sample to Chunk Box | stsc | OK |
Chunk Offset Box | stco, co64 | OK |
Padding Bits Box | padb | OK |
Sub-Sample Information Box | subs | OK |
Sample Auxiliary Information Sizes Box | saiz | OK |
Sample Auxiliary Information Offsets Box | saio | OK |
Movie Extends Box | mvex | OK |
Movie Extends Header Box | mehd | OK |
Track Extends Box | trex | OK |
Movie Fragment Box | moof | OK |
Movie Fragment Header Box | mfhd | OK |
Track Fragment Box | traf | OK |
Track Fragment Header Box | tfhd | OK |
Track Fragment Run Box | trun | OK |
Movie Fragment Random Access Box | mfra | OK |
Track Fragment Random Access Box | tfra | OK |
Movie Fragment Random Access Offset Box | mfro | OK |
Track fragment decode time | tfdt | OK |
Level Assignment Box | leva | OK |
Sample to Group Box | sbgp | Not yet |
Sample Group Description Box | sgpd | Not yet |
User Data Box | udta | OK |
Copyright Box | cprt | OK |
Track Selection Box | tsel | OK |
The Meta Box | meta | OK |
XML Box | xml | Not yet |
Binary XML Box | bxml | Not yet |
The Item Location Box | iloc | Not yet |
Primary Item Box | pitm | Not yet |
Item Protection Box | ipro | Not yet |
Item Information Box | iinf | Not yet |
Additional Metadata Container Box | meco | Not yet |
Metabox Relation Box | mere | Not yet |
Item Data Box | idat | Not yet |
Item Reference Box | iref | Not yet |
Protection Scheme Information Box | sinf | OK |
Original Format Box | frma | OK |
Scheme Type Box | schm | OK |
Scheme Information Box | schi | OK |
FD Item Information Box | fiin | Not yet |
File Partition Box | fpar | Not yet |
FEC Reservoir Box | fecr | Not yet |
FD Session Group Box | segr | Not yet |
Group ID to Name Box | gitn | Not yet |
File Reservoir Box | fire | Not yet |
Sub Track Box | strk | Not yet |
Sub Track Information Box | stri | Not yet |
Sub Track Definition Box | strd | Not yet |
Sub Track Sample Group Box | stsg | Not yet |
Restricted Scheme Information Box | rinf | Not yet |
Stereo Video Box | stvi | Not yet |
Segment Type Box | styp | OK |
Segment Index Box | sidx | OK |
Subsegment Index Box | ssix | OK |
Producer Reference Time Box | prft | Not yet |
Box Name | Type | Status |
---|---|---|
Protection System Specific Header Box | pssh | OK |
Track Encryption Box | tenc | OK |
Box Name | UUID | Status |
---|---|---|
Protection System Specific Header Box | d08a4f18-10f3-4a82-b6c8-32d8aba183d3 | OK |
Sample Encryption Box | a2394f52-5a9b-4f14-a244-6c427c648df4 | OK |
Track Encryption Box | 8974dbce-7be7-4c51-84f9-7148f9882554 | OK |
- Fork it ( http://github.com/zuku/bmff/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright (c) 2014 Takayuki Ogiso.
This library (except audio-visual contents) is released under the MIT license. See LICENSE.txt.
The audio-visual contents are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.