Ffmpeg concat +处理时发现的无效数据+检查有效的avi文件



我使用ffmpeg将多个avi文件连接(合并)到单个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是否有效)

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

我假设如果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表示如果errorlevel不大于或等于1,则表示为0(或负)。

在mylist.txt中,您必须删除行首的'file',因为您使用的代码会返回"file"在调用文本文件

之前

最新更新