0

As per my understanding "ffprobe" will provide file related data in JSON format. So, I have installed the ffprobe in my Ubuntu machine but I don't know how to access the ffprobe JSON response using Java/Grails.

Expected response format:

{
    "format": {
        "filename": "/Users/karthick/Documents/videos/TestVideos/sample.ts",
        "nb_streams": 2,
        "nb_programs": 1,
        "format_name": "mpegts",
        "format_long_name": "MPEG-TS (MPEG-2 Transport Stream)",
        "start_time": "1.430800",
        "duration": "170.097489",
        "size": "80425836",
        "bit_rate": "3782576",
        "probe_score": 100
    }
}

This is my groovy code

 def process = "ffprobe -v quiet -print_format json -show_format -show_streams HelloWorld.mpeg ".execute()             
        println "Found ${process.text}"
        render  process  as JSON

I m able to get the process object and i m not able to get the json response

Should i want to convert the process object to json object?

OUTPUT:

Found java.lang.UNIXProcess@75566697 org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class java.lang.UNIXProcess

  • This isn't a service to write code to meet your specification. What have _you_ tried? Take a look at [get video fps using ffprobe](http://stackoverflow.com/questions/27792934/get-video-fps-using-ffprobe) or http://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/String.html#execute() – doelleri May 12 '15 at 15:50

2 Answers2

0

Grails has nothing to do with this. Groovy can execute arbitrary shell commands in a very simplistic way:

"mkdir foo".execute()

Or for more advanced features, you might look into using ProcessBuilder. At the end of the day, you need to execute ffprobe and then capture the output stream of JSON to use in your app.

Gregg
  • 34,973
  • 19
  • 109
  • 214
  • i dont know how to capture the output stream of JSON in groovy,what i did is with the process object i rendered as JSON but it is returning this error: " org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class java.lang.UNIXProcess " – KarthickTech May 13 '15 at 10:08
0

Groovy provides a simple way to execute command line processes. Simply write the command line as a string and call the execute() method.

The execute() method returns a java.lang.Process instance.

println "ffprobe <options>".execute().text

[Source]

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • Now i m able to use ffprobe now i used this command " ffprobe -show_format -loglevel quiet " and i got response in output which looks like [FORMAT] filename=HelloWorld.mpeg nb_streams=2 format_name=mpeg format_long_name=MPEG-PS format start_time=0.768300 duration=20.966667 size=706564.000000 [/FORMAT] but i cant able to access those values and if i need to use that i want them in json format and so i used this command "ffprobe -v quiet -print_format json -show_format -show_streams HelloWorld.mpeg " – KarthickTech May 13 '15 at 10:06
  • But this command "ffprobe -v quiet -print_format json -show_format -show_streams HelloWorld.mpeg " is not working, i m getting process object, but not able to get json . – KarthickTech May 13 '15 at 15:40
  • use the absolute path for both the media file and ffprobe if it's not in PATH – aergistal May 13 '15 at 15:53
  • No change this is my CODE : def process = "ffprobe -v quiet -print_format json -show_format -show_streams /home/karthikv/workspace/Mpeg/HelloWorld.mpeg".execute() println "Found ${process}" render process as JSON OUTPUT : org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class java.lang.UNIXProcess . Not able to get json – KarthickTech May 13 '15 at 16:07