2015-07-11 290 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