beanieboi / ffprober

a small ruby wrapper for ffprobe
MIT License
41 stars 21 forks source link

expose ffprober.json? #67

Closed tilllt closed 8 years ago

tilllt commented 8 years ago

Hi, i am a beginner with Ruby and tried to use your ffprober gem. I was going mental about finding out how i can access the JSON data which is returned (as i can see via .inspect) ... pretty much everyone told me that there is or should be a method like ffprobe.json, that returns the JSON. With the help of the people from the #ruby channel on freenode, i figured out that the .json method is private and therefore cannot be accessed from the "outside"... so what would be the proper way to get to the JSON metadata or is this just a mistake in the gem?

cheers, t.

documentation of my attempts: https://gist.github.com/tilllt/73983d3579a46aed0993

beanieboi commented 8 years ago

Hey @tilllt

thanks for the feedback! My idea for ffprober is, that it uses the JSON under the hood to create usable classes with attributes in a OO way. so you don't have to deal with the JSON directly.

if you want to work with the JSON directly you can call ffprobe on the command line directly with those parameters. https://github.com/beanieboi/ffprober/blob/master/lib/ffprober/ffmpeg/exec.rb#L25

ffprobe -v quiet -print_format json -show_format -show_streams myvideo.mp4

hope that helps.

ben

tilllt commented 8 years ago

that sounds logical, BUT wouldnt it make sense to be able use it for both of these use cases?

i am trying to built a media darabase so in the first step i want to gather all the metadara i can get to start building a gui. later on, i am sure i want to have a direct and easy way to query properties of a mediafile, i.e. to track changes to the stored information. sure, i can call ffprobe directly, but since i already required the gem, ffprober already checked it has a working ffprobe version etc. in my understanding it would make sense if your gem could additionally just pass on the entire json to make it more versatile?

cheers, t.

beanieboi commented 8 years ago

Hey!

You are totally right. Would you feel comfortable preparing a PR? If not that's fine, I can work on it over the weekend. It is just a small change to expose the parsed JSON.

Thx for the input. Ben

On Feb 5, 2016, at 10:29 AM, tilllt notifications@github.com wrote:

that sounds logical, BUT wouldnt it make sense to be able use it for both of these use cases?

i am trying to built a media darabase so in the first step i want to gather all the metadara i can get to start building a gui. later on, i am sure i want to have a direct and easy way to query properties of a mediafile, i.e. to track changes to the stored information. sure, i can call ffprobe directly, but since i already required the gem, ffprober already checked it has a working ffprobe version etc. in my understanding it would make sense if your gem could additionally just pass on the entire json to make it more versatile?

cheers, t.

— Reply to this email directly or view it on GitHub.

tilllt commented 8 years ago

Hey Ben, i would actually enjoy helping you on this, but my Ruby skills are absolutely too limited, in fact i will probably break more than help. I will watch the changes you do and learn for the next time.

cheers, t.

beanieboi commented 8 years ago

hey

don't feel discouraged! it's totally fine i can look into this over the weekend. also, ffprober has a decent test suite. it will tell you when things are broken.

you can run the test suite by executing bundle exec rake inside the ffprobe directory. it should look like this if everything is ok.

Run options: --seed 46151

# Running:

...........

Finished in 0.164549s, 66.8493 runs/s, 212.7022 assertions/s.

11 runs, 35 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /Users/ben/Development/ffprober/coverage. 253 / 259 LOC (97.68%) covered.

don't feel pressured to deliver the PR, i'm very happy that you opened the issue and shared your ideas! thats a really great start!

it would be awesome if you feel encouraged to play around. no worries, you can't break ffprober :)

tilllt commented 8 years ago

The reason why i chose ffprober btw. is that i did a quick comparison of the mediainfo wrapper vs. ffprober and medianfo (probably due to the library itself) is so slow! maybe it spits out some extra information that ffprobe does not get, but the extra time it takes to extract the metadata is not worth it...

tilllt commented 8 years ago

lazy me, i found i preliminary solution doing ffprobe.instance_variable_get(:@json)

sorry, finding out how to make the json method public in your gem is over my skill set right now, so for the moment i will use this not-so-elegant workaround!

beanieboi commented 8 years ago

hey

i just released version 0.5.1. now you can access the json by calling ffprobe.json. let me know if you need help.

ben

tilllt commented 8 years ago

Thanks! So now i learned about attr_reader!