greatseth / mediainfo Goto Github PK
View Code? Open in Web Editor NEWRuby wrapper for the mediainfo CLI. http://mediainfo.sourceforge.net
License: MIT License
Ruby wrapper for the mediainfo CLI. http://mediainfo.sourceforge.net
License: MIT License
I'm getting this when I try to use a filename:
irb(main):003:0> media_info = MediaInfo.from('bad-video-hikvision.mkv')
Traceback (most recent call last):
3: from /usr/bin/irb:11:in `<main>'
2: from (irb):3
1: from /var/lib/gems/2.5.0/gems/mediainfo-1.0.1/lib/mediainfo.rb:84:in `from'
ArgumentError (Bad Input)
Input must be:
A video or xml file location. Example: '~/videos/test_video.mov' or '~/videos/test_video.xml'
A valid URL. Example: 'http://www.site.com/videofile.mov'
Or MediaInfo XML
However, this works:
irb(main):004:0> media_info = MediaInfo.from('./bad-video-hikvision.mkv')
It would be good if a filename can be provided without ./
Hi,
the command line version of mediainfo can (at least for some videos) give details about the language for audio and subtitle tracks, like
Language : English
The gem, however, doesn't seem to support this. Would be nice.
regards
Hello,
I've just downloaded this gem and everything was great until I started experimented with the video's properties.
When I executed the following code I got a nasty expection:
begin
info = Mediainfo.new destination_file_path
self.duration = info.video.duration
rescue
logger.fatal "Unable to access Video Info through MediaInfo CLI!\n$!"
return false
end
/Users/dba/.rvm/gems/ruby-head/gems/mediainfo-0.7.1/lib/mediainfo/attr_readers.rb:36: [BUG] Segmentation fault ruby 1.9.2dev (2010-05-04 trunk 27615) [x86_64-darwin10.3.0] -- control frame ---------- c:0014 p:0067 s:0047 b:0046 l:000430 d:000045 LAMBDA /Users/dba/.rvm/gems/ruby-head/gems/mediainfo-0.7.1/lib/mediainfo/attr_readers.rb:36 c:0013 p:---- s:0043 b:0043 l:000042 d:000042 FINISH c:0012 p:0075 s:0041 b:0041 l:000c28 d:000c28 METHOD /Users/dba/.rvm/gems/ruby-head/gems/mediainfo-0.7.1/lib/mediainfo.rb:143 c:0011 p:---- s:0034 b:0034 l:000033 d:000033 FINISH c:0010 p:0255 s:0032 b:0031 l:000d90 d:000d90 METHOD /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/video.rb:56 c:0009 p:0011 s:0025 b:0025 l:000024 d:000024 METHOD /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/video.rb:21 c:0008 p:0042 s:0021 b:0021 l:000020 d:000020 METHOD /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/upload_processor/file_processor.rb:11 c:0007 p:0088 s:0017 b:0017 l:000016 d:000016 METHOD /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/upload_processor/daemon.rb:24 c:0006 p:0027 s:0013 b:0013 l:001498 d:000012 BLOCK ./bin/content_upload_daemon:22 c:0005 p:---- s:0011 b:0011 l:000010 d:000010 FINISH c:0004 p:---- s:0009 b:0009 l:000008 d:000008 CFUNC :loop c:0003 p:0206 s:0006 b:0006 l:001498 d:000a48 EVAL ./bin/content_upload_daemon:21 c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH c:0001 p:0000 s:0002 b:0002 l:001498 d:001498 TOP --------------------------- -- Ruby level backtrace information ---------------------------------------- ./bin/content_upload_daemon:21:in `' ./bin/content_upload_daemon:21:in `loop' ./bin/content_upload_daemon:22:in `block in ' /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/upload_processor/daemon.rb:24:in `start' /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/upload_processor/file_processor.rb:11:in `process_product_file' /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/video.rb:21:in `create_sample!' /Users/dba/work/mobbit/insight.v3/programming/content_upload_daemon/lib/insight_v3/video.rb:56:in `inspect_video' /Users/dba/.rvm/gems/ruby-head/gems/mediainfo-0.7.1/lib/mediainfo.rb:143:in `method_missing' /Users/dba/.rvm/gems/ruby-head/gems/mediainfo-0.7.1/lib/mediainfo/attr_readers.rb:36:in `block in mediainfo_attr_reader' -- C level backtrace information ------------------------------------------- [NOTE] You may have encountered a bug in the Ruby interpreter or extension libraries. Bug reports are welcome. For details: http://www.ruby-lang.org/bugreport.html Abort trap
For some reason that yield is causing ruby to blowup. Any help would be appreciated :)
I wanted to inform you about a "backward incompatibility" with the latest version of the MediaInfo CLI and the latest version of this Gem.
The CLI version [MediaInfo Command line, MediaInfoLib - v0.7.82] works with the 0.7.2 gem.
But with CLI version [MediaInfo Command line, MediaInfoLib - v0.7.95] intalled, when querying a WAVE file's duration from the gem, the following error is thrown:
/Library/Ruby/Gems/2.0.0/gems/mediainfo-0.7.2/lib/mediainfo/attr_readers.rb:60:in block (2 levels) in mediainfo_duration_reader': unexpected time fragment! please report bug! (RuntimeError) from /Library/Ruby/Gems/2.0.0/gems/mediainfo-0.7.2/lib/mediainfo/attr_readers.rb:51:in
each'
from /Library/Ruby/Gems/2.0.0/gems/mediainfo-0.7.2/lib/mediainfo/attr_readers.rb:51:in block in mediainfo_duration_reader' from /Library/Ruby/Gems/2.0.0/gems/mediainfo-0.7.2/lib/mediainfo/attr_readers.rb:36:in
block in mediainfo_attr_reader'
This, of course, blows up.
I have an AVI where
info.streams.count = 3
info.audio = true
info.video = true
info.image = false
and info.video.duration throws a seg fault
using ubuntu 10.10 64 bit with the latest mediainfo libraries directly downloaded.
the default CLI report works fine
General
Complete name : DSCN1275.AVI
Format : AVI
Format/Info : Audio Video Interleave
File size : 6.03 MiB
Duration : 5s 833ms
Overall bit rate : 8 670 Kbps
Video
ID : 0
Format : JPEG
Codec ID : MJPG
Duration : 5s 833ms
Bit rate : 8 578 Kbps
Width : 640 pixels
Height : 480 pixels
Display aspect ratio : 4:3
Frame rate : 30.000 fps
Color space : YUV
Chroma subsampling : 4:2:2
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.931
Stream size : 5.96 MiB (99%)
Audio
ID : 1
Format : PCM
Format settings, Sign : Unsigned
Codec ID : 1
Codec ID/Hint : Microsoft
Duration : 5s 833ms
Bit rate mode : Constant
Bit rate : 64.0 Kbps
Channel(s) : 1 channel
Sampling rate : 8 000 Hz
Bit depth : 8 bits
Stream size : 45.6 KiB (1%)
Interleave, duration : 972 ms (29.17 video frames)
Interleave, preload duration : 1000 ms
/var/lib/gems/1.8/gems/mediainfo-0.7.1/lib/mediainfo.rb:177:in `create': bad stream type: "Text" (Mediainfo::Stream::InvalidStreamType)
/Library/Ruby/Gems/2.0.0/gems/mediainfo-0.7.2/lib/mediainfo.rb:182:in `create': bad stream type: "Other" (Mediainfo::Stream::InvalidStreamType)
Other
ID : 2
Type : Time code
Format : QuickTime TC
Duration : 5s 0ms
Time code of first frame : 00:00:05:00
Time code settings : Striped
Language : English
Encoded date : UTC 2013-10-25 12:52:10
Tagged date : UTC 2013-10-25 12:52:10
This seems to be an edge case for some video files.
When the metadata info 'tracks' XML element is empty, this code will blow up:
https://github.com/greatseth/mediainfo/blob/1eb021d8018a37b0cd3604d55c17a3e7a1eef56c/lib/mediainfo/tracks.rb#L40
since ::REXML::Element#text
, i.e.: parameter.text
will return nil
.
Hi trying to get the mediainfo of a file on AWS S3 using a signed URL (code shown below) but am getting the error
MediaInfo::RemoteUrlError: HTTP call to xxxxxxxx is not working!.
I know the URL is accessible because I can access it through a browser (it initiates a download). Also, I think it should work since the mediainfo command line (MediaInfoLib - v18.12) works and returns the JSON, using this command:
mediainfo --Output=JSON https://eu-west-1-xxxxxxx
Here's what I'm doing with Ruby
s3_resource = Aws::S3::Resource.new(region: AWS_REGION)
obj = s3_resource.bucket(BUCKET_NAME).object(s3_name)
signed_url = obj.presigned_url(:get, expires_in: 3600)
media_info = MediaInfo.from(signed_url)
the result is
MediaInfo::RemoteUrlError: HTTP call to xxxxxxxx is not working!
I'm using mediainfo gem (1.1.2), aws-sdk (2.11.58) and ruby-2.3.1 if it helps at all
MediaInfo.from('/some/path/some-file-name-with-colon:like-this.txt')
will internally call MediaInfo.from_link
instead of MediaInfo.from_local_file
.
It's showing wrong duration info. For a video of 6 seconds its showing 5700 seconds
This
def self.standardize_to_milliseconds(value)
return standardize_float_to_milliseconds(value.to_f) if value.to_f.to_s == value.to_s
return standardize_string_to_milliseconds(value)
value
end
doesn't work if value has a trailing zero (e.g. 123.450
) and it will return a string instead of an integer.
Here's a suggested fix:
return standardize_float_to_milliseconds(value.to_f) if value =~ /^\d+\.?\d*$/
[12] pry(main)> media_info.video.duration
RuntimeError: unexpected time fragment! please report bug!
from /usr/local/opt/gems/gems/mediainfo-0.7.2/lib/mediainfo/attr_readers.rb:60:in `block (2 levels) in mediainfo_duration_reader'
[13] pry(main)> media_info.video
=> #<Mediainfo::StreamProxy:0x007fd515183070
@mediainfo=#<Mediainfo:0x007fd514a9eed0 ...>,
@stream_type=:video,
@streams=
[#<Mediainfo::VideoStream:0x007fd515169968
@duration_before_type_cast="15 s 82 ms",
@parsed_response=
{:video=>
{"id"=>"481 (0x1E1)",
"menu_id"=>"1 (0x1)",
"format"=>"MPEG Video",
"format_version"=>"Version 2",
"format_profile"=>"Main@High",
"format_settings_bvop"=>"Yes",
"format_settings_matrix"=>"Custom",
"format_settings_gop"=>"Variable",
"format_settings_picture_structure"=>"Frame",
"codec_id"=>"2",
"duration"=>"15 s 82 ms",
"bit_rate_mode"=>"Constant",
"bit_rate"=>"7 411 kb/s",
"maximum_bit_rate"=>"7 200 kb/s",
"width"=>"1 920 pixels",
"height"=>"1 080 pixels",
"display_aspect_ratio"=>"16:9",
"frame_rate"=>"29.970 (30000/1001) FPS",
"color_space"=>"YUV",
"chroma_subsampling"=>"4:2:0",
"bit_depth"=>"8 bits",
"scan_type"=>"Interlaced",
"scan_order"=>"Top Field First",
"compression_mode"=>"Lossy",
"bits_pixel_frame_"=>"0.119",
"time_code_of_first_frame"=>"00:00:00:00",
"time_code_source"=>"Group of pictures header",
"gop_open_closed"=>"Open",
"gop_open_closed_of_first_frame"=>"Closed",
"stream_size"=>"13.3 MiB (92%)"}},
@stream_type=:video>]>
Like all good boys should.
mediainfo seems to be throwing the wrong exception when receiving an invalid method. I typoed .video.bit_rate_mode
as .video.bitrate_mode
; however, the exception raised received was:
Mediainfo::StreamProxy::NoStreamsForProxyError: there are no :video streams to send :bitrate_mode to
That made me scratch my head for awhile, because the video does have a video stream. I think a different exception should be raised in this instance.
Hi, I'm getting an exception trying to convert data to JSON format
mi = Mediainfo.new '/tmp/sample.mp4'
puts mi.to_json
ActiveSupport::JSON::Encoding::CircularReferenceError: object references itself
thanks
I have mediainfo installed:
$ which mediainfo
/usr/bin/mediainfo
$ /usr/bin/env mediainfo --version
MediaInfo Command line,
MediaInfoLib - v0.7.82
However the gem is looking for it in the wrong place:
irb(main):004:0> media_info = MediaInfo.from('./bad-video-hikvision.mkv')
Traceback (most recent call last):
5: from /usr/bin/irb:11:in `<main>'
4: from (irb):4
3: from /var/lib/gems/2.5.0/gems/mediainfo-1.0.1/lib/mediainfo.rb:86:in `from'
2: from /var/lib/gems/2.5.0/gems/mediainfo-1.0.1/lib/mediainfo.rb:45:in `run'
1: from /var/lib/gems/2.5.0/gems/mediainfo-1.0.1/lib/mediainfo.rb:12:in `location'
MediaInfo::EnvironmentError (/usr/local/bin/mediainfo cannot be found. Are you sure mediainfo is installed?)
It would be good if it would find it using /usr/bin/env and only fallback to the hardcoded path.
Since those are both free for open source projects, could we add :
I don't have the right on this repo myself to "PR" these integrations.
I would be okay to improve the code based on CodeClimate's & Rubocop's advices for maximum availability if you are ok with integrating those.
It seems that timezone information of date fields are not properly parsed, because Time.parse does not understand the prefix "UTC" in the date strings. It just ignores it and returns a local time.
Ways to reproduce
require 'mediainfo'
require 'active_support/core_ext/hash'
source = .... # Your file here
mi = MediaInfo.from(source)
puts "Returned from MediaInfo: #{mi.general.encoded_date}"
xmldate = Hash.from_xml(mi.xml)["MediaInfo"]["media"]["track"][0]["Encoded_Date"]
puts "Raw date from MediaInfo xml: #{xmldate}"
puts "Time parse directly on xmldate: #{Time.parse(xmldate)}"
puts "Time parse with UTC correction: #{Time.parse(xmldate.gsub("UTC\s+", '') + " UTC").localtime}"
This will return (for one example):
Returned from MediaInfo: 2017-08-09 23:08:00 +0200 -> Wrong
Raw date from MediaInfo xml: UTC 2017-08-09 23:08:00 -> This is what is in the file.
Time parse directly on xmldate: 2017-08-09 23:08:00 +0200 -> Wrong
Time parse with UTC correction: 2017-08-10 01:08:00 +0200 -> This should be returned
I just noticed this, because I was checking filenames (which included dates) against metadata using MediaInfo gem and because I am in UTC+2 there was this file where there was a different date returned by MediaInfo compared to the filename.
Hi,
mediainfo issues the following section for videos with a timecode, e.g. from a GoPro:
Other
ID : 3
Type : Time code
Format : QuickTime TC
Duration : 46s 263ms
Title : GoPro TCD
Language : English
Encoded date : UTC 2015-12-01 07:14:39
Tagged date : UTC 2015-12-01 07:14:39
This causes the gem to abort with
Error bad stream type: "Other"
Mediainfo::Stream::InvalidStreamType
/var/lib/gems/1.9.1/gems/mediainfo-0.7.2/lib/mediainfo.rb:182:in create' /var/lib/gems/1.9.1/gems/mediainfo-0.7.2/lib/mediainfo.rb:495:in
block in parse!'
/usr/lib/ruby/1.9.1/rexml/element.rb:905:in block in each' /usr/lib/ruby/1.9.1/rexml/xpath.rb:67:in
each'
/usr/lib/ruby/1.9.1/rexml/xpath.rb:67:in each' /usr/lib/ruby/1.9.1/rexml/element.rb:905:in
each'
/var/lib/gems/1.9.1/gems/mediainfo-0.7.2/lib/mediainfo.rb:494:in parse!' /var/lib/gems/1.9.1/gems/mediainfo-0.7.2/lib/mediainfo.rb:412:in
raw_response='
/var/lib/gems/1.9.1/gems/mediainfo-0.7.2/lib/mediainfo.rb:405:in `initialize'
Could you add an example or description how to enumerate the fields which were found in a file?
At least there seems to be no common directory of tags which can exist, or does it?
with MediaInfoLib - v21.09, the command to generate output as XML seems to remove dashes from elements' names :
mediainfo <file> --Output=XML
<extra>
<WAVELISTYEAR>2020</WAVELISTYEAR>
</extra>
with MediaInfoLib - v22.09, the command returns elements' names with dashes :
mediainfo <file> --Output=XML
<extra>
<WAVELIST-YEAR>2020</WAVELIST-YEAR>
</extra>
This is causing issue with MediaInfo.from(<filepath>)
:
NameError (`@wavelist-year' is not allowed as an instance variable name)
Although we set the path by using MEDIAINFO_PATH, there is a check on the .location method where it tries which('mediainfo')
no matter what.
So, even though we specified the custom path, it tries to find the original one from PATH.
My use case is a Lambda function, so I won't change the original PATH, but rather use the mediainfo binary located in my project.
[5] pry(main)> ::MediaInfo.location
MediaInfo::EnvironmentError: MediaInfo binary cannot be found. Are you sure mediainfo is installed?
from /Users/victoralencar/projects/mlabs/uploader/vendor/bundle/ruby/2.5.0/gems/mediainfo-1.3.3/lib/mediainfo.rb:29:in `location'
[6] pry(main)> ::File.exist? 'lib/mediainfo'
=> true
https://github.com/greatseth/mediainfo/blob/master/lib/mediainfo.rb#L29
Please correct me if I am wrong. Thanks!
Hello,
we encountered some issues with the MediaInfo.from(file. path)
files submitted by our users have all zeros as an encoding date
Could MediaInfo handle the encoding date if it's not able to be parsed instead of throwing the error:
ArgumentError: mon out of range
I'm using the latest version of the gem and MediaInfo v17.12. When using mediainfo directly, it works and identifies the multiple streams and that this is a video:
irb(main):014:0> puts `mediainfo './test.mp4'`
General
Complete name : ./test.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 211 MiB
Duration : 25 min 32 s
Overall bit rate mode : Variable
Overall bit rate : 1 152 kb/s
Writing application : Lavf53.21.1
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : [email protected]
Format settings : CABAC / 3 Ref Frames
Format settings, CABAC : Yes
Format settings, ReFrames : 3 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 25 min 32 s
Bit rate : 1 024 kb/s
Width : 854 pixels
Height : 480 pixels
Display aspect ratio : 16:9
Original display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.083
Stream size : 187 MiB (89%)
Writing library : x264 core 123 r2189 35cf912
Encoding settings : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=0 / b_adapt=1 / b_bias=0 / direct=1 / weightb=0 / open_gop=1 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=1024 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.25 / aq=1:1.00
Language : English
Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : LC
Codec ID : mp4a-40-2
Duration : 25 min 32 s
Bit rate mode : Variable
Bit rate : 124 kb/s
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 22.7 MiB (11%)
Language : English
Default : Yes
Alternate group : 1
When using the gem, it does not identify the streams or that this is a video :(
irb(main):015:0> info = Mediainfo.new('./test.mp4')
=> #<Mediainfo:0x00007fd93304b938 @streams=[], @full_filename="/Volumes/MyBook/test.mp4", @path="/Volumes/MyBook/", @filename="test.mp4", @escaped_full_filename="\"/Volumes/MyBook/test.mp4\"", @last_command="mediainfo \"/Volumes/MyBook/test.mp4\" --Output=XML", @raw_response="...", @general_stream=#<Mediainfo::GeneralStream:0x00007fd93393d488 @stream_type=:general, @parsed_response={:general=>{}}>, @video_stream=#<Mediainfo::VideoStream:0x00007fd93393d208 @stream_type=:video, @parsed_response={:video=>{}}>, @audio_stream=#<Mediainfo::AudioStream:0x00007fd93393cf88 @stream_type=:audio, @parsed_response={:audio=>{}}>, @image_stream=#<Mediainfo::ImageStream:0x00007fd93393cd08 @stream_type=:image, @parsed_response={:image=>{}}>, @menu_stream=#<Mediainfo::MenuStream:0x00007fd93393ca88 @stream_type=:menu, @parsed_response={:menu=>{}}>, @text_stream=#<Mediainfo::TextStream:0x00007fd93393c808 @stream_type=:text, @parsed_response={:text=>{}}>>
irb(main):016:0> info.video?
=> false
irb(main):017:0> info.streams
=> []
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.