# How to use FFMpeg's FFProbe without resorting to shell/string calls?

**URL:** https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562
**Category:** How to?
**Tags:** clojure
**Created:** [January 30, 2024, 9:17pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562 "2024-01-30T21:17:46Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [January 30, 2024, 9:17pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/1 "2024-01-30T21:17:46Z")

</div>

I have an ffprobe line of code. I could just work the strings and do a command-line ssh to pull it off, but… strings, reusability, extensibility, maintainability, brittleness…

I am new to ffprobe (and ffmpeg in general), but the working commandline solution is this:

```sh
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,display_aspect_ratio -of json=c=1 ./small_test_video.mp4

```

with results like this:

```js
{
    "programs": [

    ],
    "streams": [
	{ "width": 1280, "height": 720, "display_aspect_ratio": "16:9" }
    ]
}

```

Here is my current attempt in Kawa. Please pardon all the `#_` comments; I am trying to figure this out.

```clojure
(let [file-path (-> env :FILES :media-url (str "small_test_video.mp4"))
	  test-name :ffprobe
	  #_#_ mp4 (ffmanager/register :mp4 (ffm/ffmpeg! :format "lavfi" :input-url "testsrc" :duration 10
						    :pixel-format "yuv420p" "testsrc.mp4"))
	  ffp (ffmanager/register test-name
				  (ffm/ffprobe! :input-url file-path :output-format "json"))]
      #_(shell/sh "ffprobe" "-v" "error" "-select_streams" "v:0" "-show_entries" "stream=width,height,display_aspect_ratio" "-of" "json=c=1" (-> (:tempfile file) .getAbsolutePath))      
      (-> (ffmanager/ls) test-name :process #_:out #_#_:err slurp)
      ;(is false)
      )

```

And then the goal is to reason over that return value to make a decision based on the aspect ratio.

I have tried using the Clojure [Kawa](https://github.com/w33tmaricich/kawa/) library, but can’t figure out how to get it to output the data I want. Is system sh munging and then conversion from JSON really the best I can do?

---

<div class="post-metadata">

### Author: ![p-himik](https://clojureverse.org/user_avatar/clojureverse.org/p-himik/32/4137_2.png) [@p-himik](https://clojureverse.org/u/p-himik)
#### Post date: [January 30, 2024, 9:24pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/2 "2024-01-30T21:24:33Z")

</div>

> strings, reusability, extensibility, maintainability, brittleness…

Not sure what those words are supposed to mean. They only have meanings in a particular context. If “launch `ffprobe` and get its output” is the only context, then there’s absolutely nothing wrong with using `shell/sh` with strings. I myself would definitely go that route, this is not a worthy bike shed.

---

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [January 30, 2024, 9:30pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/3 "2024-01-30T21:30:21Z")

</div>

Sorry; they were rhetorical. I maintain enough code, and have worked with enough maintenance, that string munging is up there with magic numbers for stuff that hurts code quality and will come back to bite you with obscure errors at the worst times. But if scripting-style is the best way to go, that is what I have to work with.

I’m hoping someone more familiar with FFMpeg will come and explain just what that shell command is doing, and understand what needs to happen for something more re-usable and extensible to achieve the same results (and eventually more).

---

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [January 30, 2024, 9:50pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/4 "2024-01-30T21:50:00Z")

</div>

got it, using [GitHub - luissantos/ffclj: Clojure ffmpeg wrapper](https://github.com/luissantos/ffclj) instead

---

<div class="post-metadata">

### Author: ![christoph](https://clojureverse.org/user_avatar/clojureverse.org/christoph/32/2006_2.png) [@christoph](https://clojureverse.org/u/christoph)
#### Post date: [January 31, 2024, 1:08am UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/5 "2024-01-31T01:08:11Z")

</div>

If you’re looking for something more like a library and less like a command-line wrapper, the [clj-media](https://github.com/phronmophobic/clj-media) project has also has a [probe function](https://phronmophobic.github.io/clj-media/#clj-media/probe). It’s built on top of ffmpeg, but it uses the API bindings.

---

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [January 31, 2024, 1:52pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/6 "2024-01-31T13:52:39Z")

</div>

Ah, that’s the sort of recommendation I was looking for! Thank you!

---

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [January 31, 2024, 7:35pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/7 "2024-01-31T19:35:05Z")

</div>

oops. I spoke to soon. I have not been able to get clj-media to work because, down the dependency line, it’s not enough just to have ffprobe; you need more stuff (Clang’s libxb so that it can expose the C APIs with JNI… TMI, I know. Just sharing some of the pain.)

---

<div class="post-metadata">

### Author: ![DeepSymmetry](https://clojureverse.org/user_avatar/clojureverse.org/deepsymmetry/32/1305_2.png) [@DeepSymmetry](https://clojureverse.org/u/DeepSymmetry)
#### Post date: [February 8, 2024, 4:28pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/8 "2024-02-08T16:28:49Z")

</div>

Yes, sometimes just using the command-line options via a shell subprocess is the most straightforward solution.

---

<div class="post-metadata">

### Author: ![emmawilson](https://clojureverse.org/user_avatar/clojureverse.org/emmawilson/32/5464_2.png) [@emmawilson](https://clojureverse.org/u/emmawilson)
#### Post date: [June 25, 2024, 6:00am UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/9 "2024-06-25T06:00:20Z")

</div>

Thanks @Webdev_Tory I check this URL. This is really helpful for me.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [December 24, 2024, 6:00pm UTC](https://clojureverse.org/t/how-to-use-ffmpegs-ffprobe-without-resorting-to-shell-string-calls/10562/10 "2024-12-24T18:00:50Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
