我完全是C的新手,我来自PHP背景,但碰巧我用PHP编写的代码需要转换成C。起初是Java,现在是C。
在完成了一些教程之后,我了解了C的基本知识,并编写了以下代码,以便在C程序中运行ffmpeg.exe

#include <stdio.h>
#include <stdlib.h>

int main()
{

    char *app = "D:\\ffmpeg\\bin\\ffmpeg.exe -i";
    char *input = " D:\\video.mpg";
    char *output = " D:\\frames\\image%d.jpg";
    char *param = " -r 10";
    char str[300];
    snprintf(str, sizeof str, "%s%s%s%s", app, input, param, output);
    // str contains "D:\ffmpeg\bin\ffmpeg.exe -i D:\video.mpg -r 10 D:\frames"\image%d.jpg
    system(str); // <-- working fine, frames are being extracted
    /*
        do something here to store each extracted frame in an array
        so that the array contains image1.jpg, image2.jpg, image3.jpg...and so on
    */
    getch();
    return 0;
}

在编译和运行程序时,我将按预期在输出文件夹中获取帧。问题是我想在提取每个帧名时将其存储在数组中。到目前为止,我还没有遇到类似的问题,所以我决定为它创建一个新线程。我希望这是可能的,希望你能给我一个正确的方向。

最佳答案

现在,由于文件名不显示为使用popen或fork的系统命令的输出,因此将不起作用。我建议您在输出目录(D:\ frames)上执行nftw。它将列出文件夹中的所有文件。
示例代码:
http://linux.die.net/man/3/nftw

关于c - 将提取的帧名称存储在数组中-ffmpeg,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14954852/

10-13 06:41