简体   繁体   English

如何使用ffmpeg从文件夹中的所有视频中提取帧

[英]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.

相关问题 如何使用 OpenCV Python 一次从大量视频中提取和保存图像帧? - How can I extract and save image frames from a large number of videos all at once using OpenCV Python? 如何使用ffmpeg bash脚本从一个文件夹中的多个视频中提取单个图像(每次使用不同的名称) - How to extract single image (with different name each time) from multiple videos in the one folder using ffmpeg bash script 使用 FFMPEG 将所有视频帧提取为图像 - Extract all video frames as images with FFMPEG 使用ffmpeg从视频中提取帧-标头问题? - Extract frames from video with ffmpeg - header problem? 如何通过使用ffmpeg从目录循环到图像来转换视频? - How to convert videos by looping from the directory to images using ffmpeg? 如何使用Matlab从视频中以特定间隔提取帧 - How to extract frames at particular intervals from video using matlab 使用python将目录内的压缩文件夹中的所有文件提取到其他目录而不使用文件夹 - Extract all files from a zipped folder inside a directory to other directory without folder using python 如何提取/查看多帧DICOM文件的所有帧? - How to extract/view all frames of a multi-frame DICOM file? 使用 FFmpeg 使用 .bat 文件将文件夹中的所有图像转换为 mp4 或 avi [Windows] - Using FFmpeg to convert all images in a folder to mp4 or avi using a .bat file [Windows] 如何使用TWICImage获取动画GIF的所有帧? - How to get all frames of an animated GIF using TWICImage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM