0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

動画を⚪️秒間隔で静止画として切り取る方法

Posted at

プログラムはNode.jsで作成する。

◾️前準備

npm init
npm install fluent-ffmpeg

◾️index.js

const ffmpeg = require("fluent-ffmpeg");

// 入力MP4ファイルのパスと出力ディレクトリのパスを指定
const inputFilePath = "input.mp4";
const outputDirectory = "output/";

// 切り出す間隔(秒)
const interval = 0.5;

// 出力ディレクトリが存在しない場合、作成する
const fs = require("fs");
if (!fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory);
}

// MP4ファイルを処理し、1秒ごとに画像を切り出す
ffmpeg(inputFilePath)
.on("filenames", (filenames) => {
console.log(JPEG画像を生成中: ${filenames.join(", ")});
})
.on("end", () => {
console.log("JPEG画像の生成が完了しました。");
})
.on("error", (err) => {
console.error(エラー: ${err});
})
.outputOptions([-vf fps=1/${interval}, "-q:v 2"])
.output(${outputDirectory}%04d.jpg)
.run();

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?