[英]How to extract frames from all videos in a folder using ffmpeg
I'm currently able to extract images from a file using the following line 我目前可以使用以下行从文件中提取图像
ffmpeg -i inputfile.avi -r 1 image-%d.jpeg
However, I want to apply this to all the files in a folder, and place it in an output folder. 但是,我想将此应用到文件夹中的所有文件,并将其放置在输出文件夹中。
Suppose I have the current folder holding all videos: 假设我当前文件夹中包含所有视频:
input-videos/ 输入视频/
----subfolder1/ ---- subfolder1 /
------video.avi ------ video.avi
----subfolder2/ ---- subfolder2 /
------video.avi ------ video.avi
I want everything in the output folder: 我想要所有内容在输出文件夹中:
output/ 输出/
----subfolder1/ ---- subfolder1 /
------video/ - - - 视频/
----------*.jpeg ---------- * JPEG
----subfolder2/ ---- subfolder2 /
------video/ - - - 视频/
----------*.jpeg ---------- * JPEG
What is the simplest way to go about this using a bash script? 使用bash脚本执行此操作的最简单方法是什么? (or something else better)
(或其他更好的东西)
If the folder depth is constant, the file extension is always avi and the top folders are called "input-videos" and "output": 如果文件夹深度恒定,则文件扩展名始终为avi,最上面的文件夹称为“输入视频”和“输出”:
#!/bin/bash
for file in input-videos/*/*.avi; do
destination="output${file:12:${#file}-17}";
mkdir -p "$destination";
ffmpeg -i "$file" -r 1 "$destination/image-%d.jpeg";
done
If the top folders are just called anything and can be anywhere and the file extension is different, here's a script that you can call like ./script.sh <input folder> <output folder> <file extension>
: 如果最上面的文件夹什么都叫,可以在任何地方,并且文件扩展名不同,则可以使用以下脚本来调用它:
./script.sh <input folder> <output folder> <file extension>
:
#!/bin/bash
if [ "$1" == '' ] || [ "$2" == '' ] || [ "$3" == '' ]; then
echo "Usage: $0 <input folder> <output folder> <file extension>";
exit;
fi
for file in "$1"/*/*."$3"; do
destination="$2${file:${#1}:${#file}-${#1}-${#3}-1}";
mkdir -p "$destination";
ffmpeg -i "$file" -r 1 "$destination/image-%d.jpeg";
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.