ffmpegで動画を切り分けるときのSQL(駄)

MySQLで

select abs(TIME_TO_SEC(timediff('00:00:00', @time1:='00:13:03')));

とやると時間差を秒でとれる。(マイナス値になるので、absで絶対値になおしている)

というわけで

SET @comPrefix:='ffmpeg.exe -i %1 -vcodec copy -acodec copy ';
SET @filePrefix:=' "%~n1_';
SET @fileSuffix:='.mp4"';
select
 CONCAT(@comPrefix,'-t ',
 @point:=abs(TIME_TO_SEC(timediff('00:00:00', @time:='00:13:03'))),@filePrefix,replace(@time,':','_'),@fileSuffix) as command;
select
 CONCAT(@comPrefix,'-ss ',
 @total:=@point,
 ' -t ',
 @point:=abs(TIME_TO_SEC(timediff(@time, @time:='00:29:51'))),@filePrefix,replace(@time,':','_'),@fileSuffix) as command;
select
 CONCAT(@comPrefix,'-ss ',
 @total:=(@total + @point),
 ' -t ',
 @point:=abs(TIME_TO_SEC(timediff(@time, @time:='00:45:20'))),@filePrefix,replace(@time,':','_'),@fileSuffix) as command;
select
 CONCAT(@comPrefix,'-ss ',
 @total:=(@total + @point),
 ' -t ',
 @point:=abs(TIME_TO_SEC(timediff(@time, @time:='00:57:19'))),@filePrefix,replace(@time,':','_'),@fileSuffix) as command;

キュー時間をいくつか書けば下記のような結果に。

ffmpeg.exe -i %1 -vcodec copy -acodec copy -t 783 "%~n1_00_13_03.mp4"
ffmpeg.exe -i %1 -vcodec copy -acodec copy -ss 783 -t 1008 "%~n1_00_29_51.mp4"
ffmpeg.exe -i %1 -vcodec copy -acodec copy -ss 1791 -t 929 "%~n1_00_45_20.mp4"
ffmpeg.exe -i %1 -vcodec copy -acodec copy -ss 2720 -t 719 "%~n1_00_57_19.mp4"

これやってから、-ssと-tにHH:mm:ssが使える事を知りました。
はっはっは…。

…ははっ…。

なんでJSじゃなくてSQLなのっていうツッコミはなしです。

だってそのときMySQL Workbenchが起動してたから。

投稿者: あゆたや

札幌のWEB系の人です。バイトしながら個人制作も請けてます。一度寝たらなかなか起きません。