bash ffmpeg查找和文件名中的空格 [英] bash ffmpeg find and spaces in filenames

查看:180
本文介绍了bash ffmpeg查找和文件名中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ffmpeg和文件夹/文件名中的空格有疑问.我的代码如下:

I have a problem with ffmpeg and spaces in folders/filenames. My code looks like this:

cd /volume1/PUBLIC/Musik/AutoConvert
find . -type d -exec mkdir -p -- /volume1/PUBLIC/Musik/Converted/{} \;
find -type f |sed 's|./||' |while read NEWNAME; do
ffmpeg -i ""/volume1/PUBLIC/Musik/AutoConvert/"$NEWNAME""" -codec:a libmp3lame -qscale:a 2 "/volume1/PUBLIC/Musik/Converted/"${NEWNAME%.[Ff][Ll][Aa][Cc]}".mp3"
echo done with file: "$NEWNAME"
done

但是如果ffmpeg到处都有空格,那将失败.我的文件夹结构如下所示:

But that fails with ffmpeg if there is a space anywhere. My Folder Structure looks like that:

user@NAS:/volume1/PUBLIC/Musik/AutoConvert$ find -type f |sed 's|./||'
A B/C.mp3
A B/C D.mp3
A/C D.mp3
A/C.mp3

/Converted/A/C.mp3确实可以工作,但这就是唯一的一个.所有其他在文件夹oder文件名"中带有空格的项目都会失败.

The /Converted/A/C.mp3 does work, but thats the only one. All the others with Spaces in Folder oder Filename fail.

[NULL @ 0x20bb3e0] Unable to find a suitable output format for '/volume1/PUBLIC/Musik/Converted/A/C'
/volume1/PUBLIC/Musik/Converted/A/C: Invalid argument
done with file: A/C D.mp3

[NULL @ 0x11bf280] Unable to find a suitable output format for '/volume1/PUBLIC/Musik/Converted/A'
/volume1/PUBLIC/Musik/Converted/A: Invalid argument
done with file: A B/C D.mp3

[NULL @ 0x11f93e0] Unable to find a suitable output format for '/volume1/PUBLIC/Musik/Converted/A'
/volume1/PUBLIC/Musik/Converted/A: Invalid argument
done with file: A B/C.mp3

如果我在ffmpeg -input上不使用double,则会收到错误消息:

If i don't use the double " on ffmpeg -input i get the error:

/volume1/PUBLIC/Musik/AutoConvert/A: Is a directory
done with file: A B/C.mp3

/volume1/PUBLIC/Musik/AutoConvert/A: Is a directory
done with file: A B/C D.mp3

/volume1/PUBLIC/Musik/AutoConvert/A/C: No such file or directory
done with file: A/C D.mp3

看起来我在正确的轨道上……离我的目标太远了.

It looks like i'm on the right track... just way too far from my goal.

任何人都可以提供帮助吗?

Can anyone offer some help?

推荐答案

也许这段代码可以为您提供帮助

Maybe this code can help you

#!/bin/bash
cd /volume1/PUBLIC/Musik/AutoConvert 2>/dev/null || { echo "The folder is unavailable."; exit 1; }
find . -type d -exec mkdir -p -- /volume1/PUBLIC/Musik/Converted/{} \;
while IFS= read -r -d $'\0' NEWNAME; do
    ffmpeg -i "/volume1/PUBLIC/Musik/AutoConvert/$NEWNAME" -codec:a libmp3lame -qscale:a 2 "/volume1/PUBLIC/Musik/Converted/${NEWNAME%.*}.mp3"
    echo "done with file: $NEWNAME"
done < <(find . -iname '*.flac' -printf '%P\0')

这篇关于bash ffmpeg查找和文件名中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆