我使用FFMPEG来衡量存储在Amazon S3 Bucket中的视频的持续时间。
我已经阅读了FFMPEG文档,他们明确声明需要转义所有空格和特殊字符,以便FFMPEG正确处理它们:
参见文档2.1和2.1.1:https://ffmpeg.org/ffmpeg-utils.html
但是,在处理文件名包含空格的文件时,ffmpeg无法呈现结果。
我尝试过以下操作,但没有成功
ffmpeg -i "http://s3.mybucketname.com/videos/my\ video\ file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my video file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my'\' video'\' file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my\ video\ file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
但是,如果我删除文件名中的空格 - 一切都很好,并返回视频的持续时间。
感谢任何帮助!
答案 0 :(得分:17)
如果您的文件名中恰好有空格,请引用它们:
ffmpeg -i "my video file.mov"
在网址中,空格不能存在。很可能你必须用%20
替换每个空格,以便得到:
ffmpeg -i http://myurl.com/my%20video%20file.mov
^^^ ^^^
答案 1 :(得分:3)
ffmpeg使用%来定义模式并处理多个文件。例如,如果您的文件名是URI编码的,则必须使用“-pattern_type none”以避免误解ffmpeg:
ffmpeg -pattern_type none -i file%20name.mp4
答案 2 :(得分:1)
for fileOne in *.mp4
do
baseName=$(basename "$fileOne" .mp4) # "$fileOne" quotes are necessary because of special chars in it
echo "input: " $fileOne
echo "var: " $baseName
echo "target: " $baseName".mp3"
cp "$fileOne" "tmp.mp4"
# ffmpeg problem with specialchars like whitespaces and '-'
# ffmpeg -i \"$fileOne\" "$baseName..mp3"
ffmpeg -i "tmp.mp4" "tmp.mp3"
mv "tmp.mp3" "$baseName".mp3""
done
rm "tmp-mp4"
`只需重命名文件即可进行转换:)
答案 3 :(得分:0)
要使ffmeg与带有空格的文件名/路径一起使用,您应该:
1)使用Pushd
设置工作目录
2)将文件名放在引号""
这是一个有效的示例:
cls
REM ++++++++++++++++++++++++++
REM Cut an audio file by right-cliking it (works also on multiple selected audio)
REM 1) save this file
REM 2) open registry, browse to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\audio\shell. On the left panel, right-click on "shell" and select "New", then "Key". Type "Cut audio 5min". Right click on the newly created folder "Cut audio 5min" and select again "New" and then "Key". Type “command”. On the right pane, double-click the "(default)" value name and type the following: "C:\Users\Me\Cut audio.cmd" "%1"
REM optional: if you want an Icon : in the left pane, right click "Cut audio 5min", and select String value, then in the right pane, rename the new value to Icon, then double click on it and past this "%SystemRoot%\\System32\\shell32.dll,186" (; list icon: https://diymediahome.org/windows-icons-reference-list-with-details-locations-images/ )
REM 3) right click an audio file and select "Cut audio 5min": the chunks will be created in the same folder.
REM because ffmpeg has trouble with path/filename with space, we set the working directory to the folder of the audio file and the we run the command not on a full path but just on the filename, with "" around it
REM get https://stackoverflow.com/a/15568171/3154274
REM fullpath of rightclicked file %1
REM full path (letter drive + path ithout letter drive) %~d1%~p1
REM filename (filename + extension) %~n1%~x1
REM https://windowsloop.com/split-mp3-files-with-ffmpeg/
REM ffmpeg -i "input_audio_file.mp3" -f segment -segment_time 300 -c copy output_audio_file_%%03d.mp3
REM 300= 5min chunk
REM ++++++++++++++++++++++++++
REM set working directory
Pushd %~d1%~p1
REM to let the windows open cmd /k ffmpeg -i "%~n1%~x1" -f segment -segment_time 300 -c copy "%~n1"_%%03d.mp3
cmd /k ffmpeg -i "%~n1%~x1" -f segment -segment_time 300 -c copy "%~n1"_%%03d.mp3
答案 4 :(得分:0)
我通过“引用”包含文件路径的arg解决了它。在我的情况下,该路径存储在%1参数中(该参数写在注册表中的转义引号下:\“%1 \”)。我只需使用$ arg(内置参数)即可检索它(使用PowerShell脚本)。然后,我用它来获取一些文件信息,例如:
# Get the File path:
$FilePath = $args
# Get the complete file name:
$file_name_complete = [System.IO.Path]::GetFileName("$FilePath")
# Get File Name Without Extension:
$fileNameOnly = [System.IO.Path]::GetFileNameWithoutExtension("$FilePath")
# Get the Extension:
$fileExtensionOnly = [System.IO.Path]::GetExtension("$FilePath")
不要忘记$FilePath
周围的引号。
然后您可以使用它将音频文件分成5分钟的部分,就像这样:
ffmpeg -i $file_name_complete -f segment -segment_time 300 -c copy $fileNameOnly"_"%03d$fileExtensionOnly #
答案 5 :(得分:0)
正如许多人指出的那样,最好的选择是引用字符串。它适用于所有其他特殊字符。我附上了快照,来自ffmpeg documentation page中的一些示例。我附上一个屏幕截图,以防万一将来无法使用。
答案 6 :(得分:0)
您使用视频 URL 作为输入,因此您需要对该 URL 进行编码,因为据我所知 CURL
或 WGET
也需要对 URL 进行编码,例如 SPACE
变为 { {1}},如果您使用 PHP,请执行以下操作:%20