自动匹配输出文件和输入文件(Applescript x FFMPEG)

Automatically match output file with input file (Applescript x FFMPEG)

我使用以下 AppleScript 作为 Automator 服务在查找器中右键单击视频文件并使用 ffmpeg 终端命令刻录匹配的字幕文件 (.ass)。在这种情况下,ffmpeg 编码一个新的 Prores 422(HQ) 文件。

on run {input, parameters}
tell application "Terminal"
    activate
    set filesString to ""
    repeat with file_ in input
        set filesString to filesString & " " & quoted form of (POSIX path of file_)
    end repeat
    do script "for f in" & filesString & "; do  
base=$f  
ffmpeg -y -i \"$base\" -c:v prores -profile:v 3 -pix_fmt yuv422p10le -vf \"ass=${base%.*}.ass\" -c:a copy \"${base%.*}_sub.mov\";
done"
    end tell
    return input
end run 

是否可以将输出文件及其编解码器自动匹配到输入文件?
由于混合 windows / mac 环境(Prores (mov)、dnxhr (mxf/mov)),我们使用了很多不同的输入格式,我不想使用 8-12 编码工作站的 finder 服务菜单中的选项 :)。

提前致谢!!

ffmpeg 将从文件结尾选择编解码器本身,如果没有作为参数给出。在大多数情况下,这很好。只需将输入文件的扩展名设置为输出文件即可。

如果需要更细粒度,可以使用ffprobe。它是ffmpeg的一个工具,可以读取视频文件的所有属性。

可以在这里找到很好的解释:https://trac.ffmpeg.org/wiki/FFprobeTips

例如,第一个流的编解码器(这是大多数视频文件中的视频流)可以通过以下方式读取:

ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 input.mp4

您可以将值保存在变量中并在 ffmpeg 命令中设置它们。