Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 ffmpeg 批量将 .flac 文件转换为 .m4a #13

Open
luoxiaohei opened this issue Mar 7, 2023 · 0 comments
Open

使用 ffmpeg 批量将 .flac 文件转换为 .m4a #13

luoxiaohei opened this issue Mar 7, 2023 · 0 comments

Comments

@luoxiaohei
Copy link
Owner

#!/bin/bash

# 定义输入目录和输出目录
input_dir="$1"
output_dir="$2"

# 遍历目录及子目录中的所有 .flac 文件
find "$input_dir" -type f -iname "*.flac" | while read flac_file
do
  # 获取输入文件的路径和文件名
  input_path=$(dirname "$flac_file")
  input_file=$(basename "$flac_file")
  # 获取输出文件名
  output_file=$(basename "$flac_file" .flac).m4a
  # 生成输出文件的完整路径,保留原有目录结构
  output_path=$(echo "$input_path" | sed "s|$input_dir|$output_dir|")/$output_file
  # 确保输出目录存在
  output_dir_path=$(dirname "$output_path")
  mkdir -p "$output_dir_path"
  # 如果输出文件已经存在,则跳过转换操作并输出提示信息
  if [ -f "$output_path" ]; then
    echo "文件 $output_file 已存在,跳过转换"
  else
    # 转换文件格式并输出到指定目录
    ffmpeg -i "$flac_file" -c:a alac -c:v copy "$output_path" < /dev/null
  fi
done

echo "转换完成!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant