linux - FFMPEG Bash 自动化

标签 linux bash ffmpeg

我在一个目录中的不同子目录中有一堆视频,我如何运行 FFMPEG 来转换这些子目录中的所有视频,然后将每个视频的输出放回它来自的原始子目录。

for i in **/*.mp4; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .mp4)"/*.mp4  ; done

最佳答案

这个Shellcheck -clean 演示程序可能包含您想要的内容:

#! /bin/bash -p

shopt -s globstar
shopt -s nullglob
shopt -s dotglob

for mp4 in **/*.mp4; do
    new_mp4=${mp4%.mp4}_qscale_0.mp4
    ffmpeg -i "$mp4" -qscale 0 "$new_mp4"
done
  • 对于每个具有类似 a/b/c.mp4 的路径的文件在当前目录下运行ffmpeg生成文件a/b/c_qscale_0.mp4 .原始文件保持不变。
  • new_mp4=${mp4%.mp4}_qscale_0.mp4删除 .mp4$mp4 中路径的末尾开始, 附加 _qscale_0.mp4结果,并将最终结果放入 new_mp4多变的。见 Removing part of a string (BashFAQ/100 (How do I do string manipulation in bash?)) ${var%pattern} 的解释句法。
  • 关于linux - FFMPEG Bash 自动化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71138462/

    相关文章:

    linux - 使用 SSH 更新 WordPress (Centos)

    linux - Kafka 连接 - 无法连接到本地主机端口 8083 : Connection refused

    ios - (DJIWidget) FFmpeg.framework 中的无效 CFBundleSupportedPlatforms 值 iPhoneSimulator

    python - 如何重命名将使用以下程序下载的 .wav 文件?

    windows - ffmpeg 没有从批处理脚本中正确使用通配符

    c - 如何限制通过蓝牙连接到设备的手机数量?

    python - 网络 : Trying to get ipaddress of all Interfaces in Linux

    bash - 带有/空格+ ssh的变量

    bash - noop [ :] in bash? 的用例是什么

    regex - 如何在Linux中仅用字母之间的下划线替换空格,忽略数字