You can use this small python script together with find to print all files with specific codec:
filterByCodec.py
import os
import sys
import json
inputPath = sys.argv[1]
codec = sys.argv[2]
type = sys.argv[3]
cmd = 'ffprobe -v quiet -show_streams -print_format json ' + inputPath
output = os.popen(cmd).read()
output = json.loads(output)
if not 'streams' in output:
sys.exit(0)
for stream in output['streams']:
if stream['codec_name'] == codec and stream['codec_type'] == type:
print inputPath
sys.exit(0)
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 need ffprobe
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:
find . -type f -exec python filterByCodec.py {} hevc video \;
this will print all videos containing HEVC video codec. More examples:
find . -type f -exec python filterByCodec.py {} h264 video \;
find . -type f -exec python filterByCodec.py {} mp3 audio \;
You can extend the script and move those files into some directory or whatever. This could look something like this:
cmd = 'mv ' + inputPath + ' onlyhevcDir'
os.system(cmd)
I know that this is not the best way to do it, but using python it's pretty simple to do.