您的位置:首页 > 其它

利用ffmpeg切割与合并视频(一)调用ffmpeg程序直接切割

2013-03-27 12:24 489 查看
ffmpeg -ss 00:00:00 -i D:\media\Linux.mpg -vcodec copy -acodec copy -t 00:01:00 C:\Users\a\Desktop\output.mpg

选项介绍:

-ss 截取视频的开始时间 单位为秒

-t 截取视频的时长,单位为秒

-vcodec 视频编码

-acodec 音频编码

-i 输入文件

前提:ffmpeg在系统的Path目录下,这样执行的时候才会找到这个命令

下面这个程序可以将Linux.mpg分割成长度为len分钟的若干个文件。

缺点:由于无法得知源文件的具体长度,无法计算需要分多少份,只好用system(“pause”)在每次分割完成后暂停,然后根据程序的执行情况,手动地用Ctrl+C结束程序的执行。

/* * @brief test001 use ffmpeg.exe directly * @author ray * @date 2013.3.27 */

#include <stdio.h>

#include <stdlib.h>

int main()

{

char szcmd[128];//command

char szoutfile[128];

int hh = 0;

int mm = 0;

int ss = 0;

const int len = 1;//增加步长:1分钟

int res = 0;

int ms, me;

do

{

hh = mm / 60;

ms = mm-hh*60;

me= ms + len;

sprintf(szoutfile, "%d-%d-%d.mpg", hh, ms, me);

sprintf(szcmd, "ffmpeg -i D:\\media\\5min.mpg -ss %d:%d:%d -t 00:01:00 -vcodec copy -acodec copy %s", hh, ms, ss, szoutfile);

puts(szcmd);//same as printf("%s\n",s)

res = system(szcmd); //发出一个DOS命令

mm += 1;

system("pause");

} while (res == 0);

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: