I would like to standardize my video collection on a specific video codec (for instance the x265 High Efficiency Video Codec). I know I can obtain the codec in use from a single file using for instance 'mediainfo filename | grep "Codec ID"' Which will output the video codec followed by the audio codec for each file like:
Codec ID : V_VP8
Codec ID : A_VORBIS
I've reviewed man find
but I can't seem to figure out how to accomplish this. Any ideas?
A combination of
find
,ffprobe
,jq
utilities could be used to print info about all*.avi
,*.mp4
files (in the current directory tree recursively) that are NOT encoded using"h264"
video codec:To install the utilities, run:
The example works on
jq
1.4
. Ifapt-get
version provides an older version; you could download a newerjq
binary (just put the downloaded file somewhere in$PATH
, rename it tojq
and make it executable:chmod +x jq
).You can get a sorted list of your codec specific media files under the working directory by
$ mediainfo * | grep -v codec_id | grep .file_extension | cut -f2 -d: > list.txt
where codec_id is the codec in question (ex. h264) and file_extension is the extension of the container in question (ex. .mkv)
but if the file names have blank spaces between names then the command will not work as desired.
You can use this small python script together with find to print all files with specific codec:
filterByCodec.py
This will call
ffprobe
, store its output in json string, iterate over all streams and print the input path in case codec name and type match. You will needffprobe
for this. You can get it as a static build from here if you don't have it installed on your system.Then you can call it on every file using
find
like this:this will print all videos containing HEVC video codec. More examples:
You can extend the script and move those files into some directory or whatever. This could look something like this:
I know that this is not the best way to do it, but using python it's pretty simple to do.