2015-07-11 291 views
0

我正在使用ffmpeg将多个avi文件连接(合并)为单个avi文件。 我正在使用以下命令。ffmpeg concat +处理时发现无效数据+检查有效的avi文件

ffmpeg -f concat -i mylist.txt -c copy out.avi 

文件合并列表中mylist.txt给出

Ex 'mylist.txt': 
file 'v01.avi' 
file 'v02.avi' 
file 'v03.avi' 
... 
file 'vxx.avi' 

然而,当文件的一个已损坏(或空)的问题。 在这种情况下,视频只包含文件直到损坏的文件。

在这种情况下,FFMPEG返回下列错误:

[concat @ 02b2ac80] Impossible to open 'v24.avi' 
mylist.txt: Invalid data found when processing input 

Q1)有没有办法来告诉ffmpeg的继续合并即使遇到一个无效的文件?

或者,我决定编写一个批处理文件,检查我的avi文件在合并之前是否有效。 我的第二个问题是,这个操作需要更多时间来进行合并。 Q2)有没有一种快速的方法来检查多个avi文件是否对ffmpeg有效? (如果它们无效,则删除,忽略或重命名它们)。

在此先感谢您的意见。

ssinfod。

有关信息,这里是我目前的DOS批处理文件。 (此批是因为ffprobe的工作,但速度很慢,检查我的AVI是valids)

GO.BAT

@ECHO OFF 
echo. 
echo == MERGING STARTED == 
echo. 
set f=C:\myfolder 
set outfile=output.avi 
set listfile=mylist.txt 
set count=1 

if exist %listfile% call :deletelistfile 
if exist %outfile% call :deleteoutfile 

echo == Checking if avi is valid (with ffprobe) == 
for %%f in (*.avi) DO (
    call ffprobe -v error %%f 
    if errorlevel 1 (
     echo "ERROR:Corrupted file" 
     move %%f %%f.bad 
     del %%f 
    ) 
) 

echo == List avi files to convert in listfile == 
for %%f in (*.avi) DO (
    echo file '%%f' >> %listfile% 
    set /a count+=1 
) 
ffmpeg -v error -f concat -i mylist.txt -c copy %outfile% 
echo. 
echo == MERGING COMPLETED == 
echo. 
GOTO :EOF 

:deletelistfile 
echo "Deleting mylist.txt" 
del %listfile% 
GOTO :EOF 

:deleteoutfile 
echo "Deleting output.avi" 
del %outfile% 
GOTO :EOF 

:EOF 

回答

1

我想这ffmpeg与出口值0,如果期间发生任何错误而终止操作。我没有安装ffmpeg,因此无法验证它。

所以我会假设列表中的所有的AVI文件都对串联的ffmpeg第一次运行有效。然后检查分配给errorlevel的退货代码。

如果返回码为0,所有AVI文件的连接成功并且可以退出批处理。

否则花费更多的时间代码来找出哪些AVI文件是无效的,他们整理出来并连接剩余的AVI的文件。

所以批处理文件可以是像下面(未测试):

@echo off 
set "ListFile=%TEMP%\mylist.txt" 
set "OutputFile=output.avi" 

:PrepareMerge 
if exist "%ListFile%" call :DeleteListFile 
if exist "%OutputFile%" call :DeleteOutputFile 

echo == List avi files to convert into list file == 
for %%F in (*.avi) do echo file '%%~fF'>>"%ListFile%" 
if not exist "%ListFile%" goto CleanUp 

echo == Merge the avi files to output file == 
ffmpeg.exe -v error -f concat -i "%ListFile%" -c copy "%OutputFile%" 
if not errorlevel 1 goto Success 

echo. 
echo ================================================= 
echo ERROR: One or more avi files are corrupt. 
echo ================================================= 
echo. 

echo == Checking which avi are valid (with ffprobe) == 
for %%F in (*.avi) do (
    ffprobe.exe -v error "%%~fF" 
    if errorlevel 1 (
     echo Corrupt file: %%~nxF 
     ren "%%~fF" "%%~nF.bad" 
    ) 
) 
goto PrepareMerge 

:DeleteListFile 
echo Deleting list file. 
del "%ListFile%" 
goto :EOF 

:DeleteOutputFile 
echo Deleting output file. 
del "%OutputFile%" 
goto :EOF 

:Success 
echo == MERGING COMPLETED == 
call :DeleteListFile 

:CleanUp 
set "ListFile=" 
set "OutputFile=" 

if not errorlevel 1意味着如果错误级别并不大于或等于1,这意味着为0(或负)。

+0

这是一个好主意,可以先尝试合并,并且只有在出现错误时才处理。我会尝试。谢谢。 – ssinfod