2

I have some files - audio and video files - stored in an aws s3 bucket, which can have different containers and stuff, and I would like to send them to the aws mediaConvert(MC). My issue is that I need to know whenever the file is an audio or a video file, because I need to configure the MC accordingly. The main app on the server is php based, but this information might not be that interesting.

I have ffmpeg, and I already use ffprobe to get the file duration, however I can't tell from the returning data if it's a video or audio-only file. And in an another question someone said that maybe I can get this info by using the ffmpeg, but as far as I know that requires me to download the file from the s3 to the server. There is also an s3 function that I can use to get the header of a specific object, which contains the mime type of the file, however this sometimes returns as audio/mpeg for video files, which then configures the MC incorrectly.

I could also check the error message from the first job create of MC, which then tells me about the issue, and I can resend the file with the correct configuration, but then the job is marked as failed with error, which doesn't feel right to do.

So my question is; what would be the best approach to tell from a media file if it's a video or audio only? It's possible that ffmpeg or ffprobe can do it remotely, but I just don't know the tools deeply enough, so I'm not entirely sure that it can only work in that way I described it.

Random Dude
  • 872
  • 1
  • 9
  • 24
  • See duplicate link [Using ffprobe to check if file is audio or video only](https://stackoverflow.com/a/32289198/). No need for `jq` or other additional parsing tools as shown in the answer below because you can get `ffprobe` to output only the info you need. – llogan Feb 25 '21 at 17:36
  • yep, it seems like a duplicate. I would like to point out however, that I couldn't find the question with the information I had above here when I posted the question, and I spent a few times searching for it. And while I didn't knew that ffprobe is capable of doing that, I knew that I would like to do it without downloading the file to the server, if possible. Also at the end I never tried jq, just got the info from the response. – Random Dude Feb 25 '21 at 20:33

1 Answers1

3

You could use

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

The above command outputs input file's (here: sample.mp4) parameters along with audio and video streams' details. You can see the sample output here.

What you're interested in is .streams[].codec_type to figure out if the input file contains only audio, only video or both streams. You can use jq for that matter, for example:

ffprobe -v quiet -print_format json -show_format -show_streams sample.mp4 | jq .streams[].codec_type
"video"
"audio"

or parse the output JSON in any other way.

pszemus
  • 375
  • 2
  • 10