Command to find and output the codecs of all videos in a directory tree

0

0

I have a large digital movie collection, and I've been trying to come up with a way to determine what codecs make up each video in the collection, and then output this information to a file along with the name of the movie.

I managed to surprise myself last night by hacking together enough disparate snippets of code to accomplish this well enough:

find . -type f -regextype posix-extended -iregex '.*\.(mkv|webm|mp4|vob|ogg|ogv|avi|mov|wmv|qt|yuv|m4v|m?v|3gp|flv|f4v)' -printf "%f - " \
-exec ffprobe -v fatal -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 {} \; | 
tee  "/video_codecs_short.txt"

This command is able to find all movies in a directory tree (including those with extensions not in lowercase), and for each one, outputs the following to both STDOUT and a text file:

My Movie Name - h264

This more or less does what I wanted, but as you may have noticed, it isn't too clever. The -printf option is basically a workaround that limits me to using the filename argument returned from find, to which the output from ffprobe is then appended.

This means I'm not able to directly manipulate the output from ffprobe with this command, and prevents me from creating more sophisticated output templates like:

My Movie name (h264)

...or even:

(h264) My Movie Name

How can I refine this command so that I can get the output from -exec ffprobe as a parameter just like the output from find?

Any general advice on how I can make the command cleaner/more efficient/bullet-proof is also welcomed.

Hashim

Posted 2019-04-29T14:09:29.340

Reputation: 6 967

1Run a shell in -exec with sh -c "…" {} and use $1 inside that shell to do more advanced handling with that parameter. Or move everything into a Python script. Maybe output to a properly formatted CSV that can be filtered, queried if needed? – slhck – 2019-04-29T14:22:43.810

No answers