在目录中的所有组合用mp4文件的ffmpeg [英] Combining All MP4s in Directory with ffmpeg

查看:157
本文介绍了在目录中的所有组合用mp4文件的ffmpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在摔跤试图让这个批处理文件的语法正确的,我不能为我的生命弄清楚为什么有些东西不工作。

1)的可变的i是没有得到递增。

2)STRC级联似乎并不希望......嗯,拼接。

 集I = 0
设置STRC = CONCAT:在%% F(* .MP4)做(
    集/ A I + = 1
    设置海峡=中间%I%.TS    集STRC =%STRC%%STR%|    ffmpeg的-i%% F-c复制-bsf:v h264_mp4toannexb -f MPEGTS%STR%
)设置STRC =%STRC:-1%
ffmpeg的-i%STRC%-c副本-bsf:一个aac_adtstoasc Output.mp4


解决方案

您是不是第一,谁掉进了著名的延迟扩张陷阱(你不会是最后一个)

您需要延迟扩展,如果你想使用一个变量,你在同一个块改变(一个块是括号内的一系列命令

而不是%VAR%

延迟变量与引用!无功!

原因是这样的, CMD 解析code。一个完整的行或块一次解析,以在分析时其值替换正常的变量。延迟变量在运行时进行评估。

两个简单的批次来证明:

  SETLOCAL enabledelayedexpansion
设置VAR =你好
如果1 == 1(
  集VAR =世界
  回声%VAR%!VAR!

 为/ L %% i的(1,1,5-)做(
  回声%随机%!随机!

注:还行被视为块:

 设置VAR =老
设置VAR =新的&放大器;回声%VAR%

延迟扩展:

  SETLOCAL enabledelayedexpansion
设置VAR =老
设置VAR =新的&放大器;回音!VAR!

I've been wrestling trying to get the syntax right on this batch file and I can't for the LIFE of me figure out why some things aren't working.

1) The variable 'i' is not getting incremented. and 2) Concatenation on strc doesn't seem to want to...well, concatenate.

set i=0
set "strc=concat:"

for %%f in (*.mp4) do (
    set /a i+=1
    set "str=intermediate%i%.ts"

    set strc="%strc% %str%|"

    ffmpeg -i "%%f" -c copy -bsf:v h264_mp4toannexb -f mpegts "%str%"
)

set strc="%strc:-1%"
ffmpeg -i "%strc%" -c copy -bsf:a aac_adtstoasc Output.mp4

解决方案

You are not the first, who fell into the famous "delayed expansion trap" (and you won't be the last)

You need delayed expansion if you want to use a variable, that you changed in the same block (a block is a series of commands within brackets (and ))

Delayed variables are referenced with !var! instead of %var%

Reason is the way, cmd parses the code. A complete line or block is parsed at once, replacing normal variables with their value at parse time. Delayed variables are evaluated at runtime.

Two simple batches to demonstrate:

setlocal enabledelayedexpansion
set "var=hello"
if 1==1 (
  set "var=world"
  echo %var% !var!
)

.

for /L %%i in (1,1,5) do (
  echo %random% !random!
)

Note: also a line is treated as a block:

set "var=old"
set "var=new" & echo %var% 

with delayed expansion:

setlocal enabledelayedexpansion
set "var=old"
set "var=new" & echo !var! 

这篇关于在目录中的所有组合用mp4文件的ffmpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆