我想标准化我的视频集合在一个特定的视频编解码器(例如,x265高效率视频编解码)。我知道我可以从一个文件中获得正在使用的编解码器,例如使用'mediainfo filename \ grep "Codec ID‘,它将输出视频编解码器,然后输出每个文件的音频编解码器,如下所示:
Codec ID : V_VP8
Codec ID : A_VORBIS
我已经复习了man find
,但是我似乎不知道如何完成这个任务。有什么想法吗?
发布于 2016-06-03 17:32:49
您可以在工作目录下获得编解码器特定媒体文件的排序列表。
$ mediainfo *\ grep -v codec_id .file_extension .file_extension cut -f2 -d:> list.txt
其中,codec_id是有问题的编解码器(例如。H264和file_extension是所讨论的容器的扩展(例如。.mkv)
但是,如果文件名在名称之间有空格,则命令将无法按需要工作。
发布于 2016-06-03 18:15:27
您可以使用这个小python脚本和find一起打印所有具有特定编解码器的文件:
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)
这将调用ffprobe
,将其输出存储在json字符串中,遍历所有流,并在编解码器名称和类型匹配的情况下打印输入路径。为此您将需要ffprobe
。如果您没有在系统上安装它,您可以从这里获得它作为静态构建。
然后,您可以像这样在每个文件上使用find
调用它:
find . -type f -exec python filterByCodec.py {} hevc video \;
这将打印包含HEVC视频编解码器的所有视频。更多的例子:
find . -type f -exec python filterByCodec.py {} h264 video \;
find . -type f -exec python filterByCodec.py {} mp3 audio \;
您可以扩展脚本并将这些文件移动到某个目录或其他目录中。这可能是这样的:
cmd = 'mv ' + inputPath + ' onlyhevcDir'
os.system(cmd)
我知道这不是最好的方法,但是使用python很简单。
发布于 2023-03-12 11:04:33
通过替换来修正空格的问题
cmd = 'ffprobe -v quiet -show_streams -print_format json ' + inputPath
使用
cmd = 'ffprobe -v quiet -show_streams -print_format json ' + "\"" + inputPath + "\""
https://askubuntu.com/questions/781408
复制相似问题