From 743f03876856dfbc5b4b835de0320e60e91a78a1 Mon Sep 17 00:00:00 2001
From: Max <674778+01max@users.noreply.github.com>
Date: Wed, 5 Sep 2018 00:54:33 +0200
Subject: [PATCH] Fix & improve
MediaInfo::Tracks::Attributes.standardize_to_milliseconds. (#30)
---
README.md | 68 +++++++++++++++++++++--------------------
lib/mediainfo/tracks.rb | 36 ++++++++++++----------
spec/mediainfo_spec.rb | 4 +--
3 files changed, 57 insertions(+), 51 deletions(-)
diff --git a/README.md b/README.md
index 08f3ba3..a187f15 100644
--- a/README.md
+++ b/README.md
@@ -3,9 +3,9 @@
MediaInfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.net).
## Installation
-
+
$ gem install mediainfo
-
+
## Usage
#### Parsing raw XML
@@ -16,28 +16,28 @@ MediaInfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.n
media_info = MediaInfo.from('http://techslides.com/demos/sample-videos/small.mp4')
You can specify an alternate path for the MediaInfo Binary:
-
+
ENV['MEDIAINFO_PATH'] = "/opt/local/bin/mediainfo"
-
+
Once you have an MediaInfo object, you can start inspecting tracks:
-
+
media_info.track_types => ['general','video','audio']
media_info.track_types.count => 3
media_info.video? => true
media_info.image? => nil
media_info.image.filesize => MethodNotFound exception
-
-When inspecting specific types of tracks, you have a couple general API options. The
-first approach assumes one track of a given type, a common scenario in many video files,
+
+When inspecting specific types of tracks, you have a couple general API options. The
+first approach assumes one track of a given type, a common scenario in many video files,
for example:
-
+
media_info.video.count => 1
media_info.video.duration => 120 (seconds)
-
+
Sometimes you'll have more than one track of a given type:
- The first track type name, or any track type with 1 will not contain '1'
-
-
+
+
media_info.track_types => ['general','video','video2','audio','other','other2']
media_info.track_types.count => 5
media_info.video? => true
@@ -54,14 +54,14 @@ Sometimes you'll have more than one track of a given type:
media_info.video.encoded_date.class => Time
media_info.video2.duration.class => Integer
media_info.video.display_aspect_ratio.class => Float
-
+
- Any track attribute name with "date" and matching /\d-/ will be converted using Time.parse:
-
+
media_info.video.encoded_date => 2018-03-30 12:12:08 -0400
media_info.video.customdate => 2016-02-10 01:00:00 -0600
-
-- .duration and .overall_duration will be returned as milliseconds AS LONG AS the Duration and Overall_Duration match one of the expected units:
+
+- .duration and .overall_duration will be returned as milliseconds AS LONG AS the Duration and Overall_Duration match one of the expected units (each separated by a space or not):
- h (\15h\) (hour)
- hour (\15hour\)
- mn (\15hour 6mn\) (minute)
@@ -70,25 +70,27 @@ Sometimes you'll have more than one track of a given type:
- s (\15hour 6min 59s\) (second)
- sec (\15hour 6min 59sec\) (second)
- ms (\15hour 6min 59sec 301ms\) (milliseconds)
+ - in the form of a Float (as for iphone mov files)
- [Submit an issue to add more!](https://github.com/greatseth/mediainfo/issues)
-
-
- media_info.video.duration => 9855000 (\15s 164ms\)
- media_info.video.duration => 17196000 (\36s 286ms\)
+
+
+ media_info.video.duration => 15164 (\15s 164ms\)
+ media_info.video.duration => 36286 (\36s 286ms\)
+ media_info.video.duration => 123456 (\123.456\)
- We standardize the naming of several Attributes:
- You can review lib/attribute_standardization_rules.yml to see them all
-
+
media_info.video.bit_rate => nil (\41.2 Mbps\)
media_info.video.bitrate => "41.2 Mbps" (\41.2 Mbps\)
media_info.general.filesize => "11.5 MiB" (\11.5 MiB\
-
+
In order to support all possible MediaInfo variations, you may see the following situation:
media_info.track_types => ['general','video','video5','audio','other','other2']
-
+
The track type media_info.video5 is available, but no video2, 3, and 4. This is because the MediaInfo from the video has: