Log in

View Full Version : How to read metadata from a JSON file?


FranceBB
9th June 2018, 14:02
Hi,
we get JSON files that contain metadata with the start and end time in ms, a type and a message.
Is there anything that is able to read these JSON files?
I'm writing a program myself in C#, but I'd like to avoid that.
The file reports the analysis made with a software that recognises objects, scene changes and so on.
Any guess?

This is the JSON file: http://www.opfitalia.net/Server/test.json

Category id1: shots
These are scene changes in a video.
Category id2: faces VIP people.
It means that it recognises the faces of important people that have been inserted into the database.
Category id3: object.
It shows the objects that are recognised in the video, like chairs, people, buses etc.
Category id4: speech to text.
In other words, subtitles.
"full transcript" is the whole text contained in the video.
"timeline" are the single lines.
In other words, the single subtitles.
Category id5: compliance explicit.
It basically finds things like nudity, if people are naked and so on.
Category id6: compliance - SW.
It finds offensive or sexual-oriented words like "shit", "fuck you" etc.
Category id7: settings.
It basically finds if there are signs, graphics, text on the video and so on.
Like if there are many people (crowd).
If people are in a studio, if people are outside or inside etc.

I'm looking for an easy way to open these JSON files we get and check them against the video sample we sent to various companies.

ChaosKing
9th June 2018, 14:19
With Vapoursynth (and python) you could read the json file and display the description, type, etc as subtitles. 5-10min of work...
But I don't really understand what your precise goal is.

FranceBB
9th June 2018, 14:22
Oh, Vapoursynth? I see... I'm familiar with Avisynth, but I've never tried VS.
Anyway, my "goal" would be something like: Link (https://i.imgur.com/Lh5rjOK.png)

But showing them as subtitles in the video would be nice as well.

ChaosKing
9th June 2018, 14:40
So you basically want to display a clip trimmed down to start/end with desk and type information. You could also add a blankclip next to the video clip and display the information there...

Or you could generate a bunch of avisynth files as well with trim + subtitles. Associate them with a player and just double click on them. Same goes for vapoursynth, only that you can parse the json file within your script very easy. Doeas avisynth has a json reader?

foxyshadis
10th June 2018, 21:12
VS will barf because of the stupid non-JSON crap at the top of the file -- no particular reason they couldn't have put that into JSON -- and being illegally encoded into ANSI instead of UTF-8. I have no idea why companies will adopt an interoperable format, then make them non-interoperable. But you can get around it by using this:

import json
viddata = json.loads('{'+open('test.json','rb').read().decode('latin-1').split('{',1)[-1])

From there you can load the file and parse it into whatever pieces you want:

import vapoursynth as vs
core = vs.get_core()
src = core.lsmas.LWLibavSource(r'test.mp4')

snip = viddata['info'][7]['timeline'][0]

def time2frame(c, frametime):
return int(c.fps.numerator/c.fps.denominator * frametime)

segment = src[time2frame(src,snip['startTime']/1000):time2frame(src,snip['endTime']/1000)]
segment.set_output()

You can do other interesting things from there, like looping over viddata and saving each individual clip, or whatever you like. The possibilities are pretty endless.

FranceBB
11th June 2018, 22:37
Oh, I see...
Yep, by the way I knew about the first lines and the fact that is not UTF-8 'cause I got issues at the very beginning and it was the very first thing I looked at.
Anyway, I got it. I never thought Vapoursynth would be so useful.
Thank you all. :D