简体   繁体   English

FFMPEG 多次截图命令

[英]FFMPEG multiple screenshots command

iam trying to code a function which creates images from video files using ffmpeg.我正在尝试编码 function,它使用 ffmpeg 从视频文件创建图像。

But now i want to know how can i make that with ffmpeg commands exactly, because i use wrapper and now i have some limitations, so i must go in the native way.但现在我想知道如何使用 ffmpeg命令准确地做到这一点,因为我使用包装器,现在我有一些限制,所以我必须以本机方式使用 go。

So, first of all i have decided to use a Wrapper which is called node-fluent-ffmpeg.所以,首先我决定使用一个叫做 node-fluent-ffmpeg 的包装器。

And this is my work-around with the Wrapper:这是我使用 Wrapper 的解决方法:

ffmpeg({
        source: `The video file...`,
      })
        .on("filenames", async (filenames) => {
        })
        .on("error", function (err) {
          console.log("Error in filenames section: " + JSON.stringify(err));
        })
        .on("end", function () {
          console.log("Screenshots taken");
        })
        .screenshots({
          count: 60,
          folder: "tmp/",
          filename: "thumbnail-at-%i.png",
          size: "1600x900",
        })
        .on("end", function (stdout, stderr) {
            let newImg = await fs.createReadStream(`/tmp/${img}`);
            destparams = await {
              Bucket: dstBucket,
              Key: "uploaded-" + img,
              Body: newImg,
              ContentType: "image",
            };
           await s3.putObject(destparams).promise();

}); });

Notes for understanding me better:更好地理解我的注意事项:

  • I still want to make it in node.js我还是想在node.js

  • Let's assume the file is: "The video file..."假设文件是:“视频文件...”

  • I am taking 60 screenshots from the video in a random way, like it does not matter the length of the video it will just take 60 screenshots from start until the end of the video.我以随机方式从视频中截取 60 个屏幕截图,就像视频的长度无关紧要一样,从视频开始到结束只截取 60 个屏幕截图。

  • Every screenshot taken will have a prefixed and ordered number and name for every frame.截取的每张屏幕截图都会有一个前缀和有序的数字和每一帧的名称。 For example: thumbnail-at-1.png, thumbnail-at-2.png, thumbnail-at-3.png and it continues until it reaches the 60 screenshot limit.例如: thumbnail-at-1.png、thumbnail-at-2.png、thumbnail-at-3.png 并一直持续到达到 60 个屏幕截图限制。

  • Every screenshot will be saved with a 1600x900 resolution.每个屏幕截图都将以 1600x900 的分辨率保存。

  • Every screenshot will be saved in the TMP folder.每个屏幕截图都将保存在 TMP 文件夹中。

  • Do not mind reading this: After all I'll upload every screenshot to a s3 bucket.不要介意阅读此内容:毕竟我会将每个屏幕截图上传到 s3 存储桶。

  • I had search trough a lot of old forums, but it seems that ffmpeg has a poor documentation (I have been stuck, so hard to understand).我搜索了很多旧论坛,但似乎 ffmpeg 的文档很差(我被卡住了,很难理解)。

So my main goal is:所以我的主要目标是:

How i can make exactly that function that i have shown in the code sample and the quick notes, with the FFMPEG commands?我如何使用 FFMPEG 命令准确制作代码示例和快速注释中显示的 function? (Not with the wrapper) (不带包装纸)

(Sorry that i'm trying to make it simpler) (对不起,我试图让它更简单)

I mean, Which commands i must use, with the FFMPEG commands in the following code sample?我的意思是,我必须使用哪些命令,以及以下代码示例中的 FFMPEG 命令?

By the way: it is node.js,顺便说一句:它是node.js,

Do not really know what to do, sorry真的不知道该怎么办,抱歉

spawnSync(
      "/opt/ffmpeg/ffmpeg",
      [
        "-i",
        ``,
        "-f",
        "",
        ``
      ],
      { stdio: "inherit" }
 );

Thanks for your patience!谢谢你的耐心!

Enviroment:环境:

  • Node.js 12.x Node.js 12.x
  • FFMPEG (4.3.1) FFMPEG (4.3.1)

The main problem would be getting the duration of the video, so as long as you have ffprobe you should be able to do this:主要问题是获取视频的持续时间,所以只要你有 ffprobe 你就应该能够做到这一点:

Get duration then divide by 60, convert the number to a timestamp .获取持续时间然后除以 60,将数字转换为时间戳

ffprobe -v quiet -print_format json -show_format -show_streams "<FILENAME>"

Then parse the JSON for format.duration , then divide it by the number of screens you want.然后将 JSON 解析为format.duration ,然后除以你想要的屏幕数。

Then loop over 60 times to get a single frame at a specific timestamp by doing dateformat('H:i:s', i * (format.duration / 60)) (pseudo):然后通过执行dateformat('H:i:s', i * (format.duration / 60)) (伪)循环 60 多次以在特定时间戳获得单个帧:

ffmpeg -ss 00:00:00 -i "infile.mp4" -t 00:00:01 -r 1 -f mjpeg "thumbnail-at-0.png"
ffmpeg -ss 00:00:10 -i "infile.mp4" -t 00:00:01 -r 1 -f mjpeg "thumbnail-at-1.png"
ffmpeg -ss 00:00:20 -i "infile.mp4" -t 00:00:01 -r 1 -f mjpeg "thumbnail-at-2.png"
...
ffmpeg -ss 00:09:30 -i "infile.mp4" -t 00:00:01 -r 1 -f mjpeg "thumbnail-at-57.png"
ffmpeg -ss 00:09:40 -i "infile.mp4" -t 00:00:01 -r 1 -f mjpeg "thumbnail-at-58.png"
ffmpeg -ss 00:09:50 -i "infile.mp4" -t 00:00:01 -r 1 -f mjpeg "thumbnail-at-59.png"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM