Skip to content

zuku/bmff

Repository files navigation

bmff

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.

Build Status Coverage Status Gem Version

Installation

Add this line to your application's Gemfile:

gem 'bmff'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bmff

Usage

Dump Box Structure

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

Get Video Duration from Media Header Box

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

Get Each Fragment Duration

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

Progress

ISO/IEC 14496-12:2012

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

ISO/IEC 23001-7:2012

Box Name Type Status
Protection System Specific Header Box pssh OK
Track Encryption Box tenc OK

Protected Interoperable File Format (PIFF) 1.1

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

Contributing

  1. Fork it ( http://github.com/zuku/bmff/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

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/.

About

ISO Base Media File Format Parser

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages