首页 > 解决方案 > 尝试合并视频时 Ffmpeg 无效数据

问题描述

我有一个以下函数用于在 Python 中合并视频而无需使用 FFmpeg 重新编码:

def merge():
    """
    This function merges a group of videos into one long video.
    It is used for merging parts that are cut from original video into a new one.
    The videos are merged using ffmpeg and for the ffmpeg
    to use the concat method on them, the video names must be put inside
    the vidlist.txt file.
    New video is saved to the file named output.mp4.
    """
    command = "ffmpeg -hide_banner -loglevel error -f concat -safe 0 -i vidlist.txt -c copy output.mp4"
    # merge multiple parts of the video
    subprocess.call(command, shell=True)

我将要合并的视频的路径存储在 vidlist.txt 文件中,该文件如下所示:

file 'out11.mp4'
file 'out21.mp4'

但是,我收到以下错误:

vidlist.txt: Invalid data found when processing input

这是报告文件:

ffmpeg started on 2020-07-30 at 20:23:53
Report written to "ffmpeg-20200730-202353.log"
Log level: 48
Command line:
ffmpeg -hide_banner -f concat -safe 0 -i "C:\\Users\\miliv\\videocutter\\utils\\vidlist.txt" -c copy output.mp4 -report
Splitting the commandline.
Reading option '-hide_banner' ... matched as option 'hide_banner' (do not show program banner) with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'concat'.
Reading option '-safe' ... matched as AVOption 'safe' with argument '0'.
Reading option '-i' ... matched as input url with argument 'C:\Users\miliv\videocutter\utils\vidlist.txt'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option 'output.mp4' ... matched as output url.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option hide_banner (do not show program banner) with argument 1.
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url C:\Users\miliv\videocutter\utils\vidlist.txt.
Applying option f (force format) with argument concat.
Successfully parsed a group of options.
Opening an input file: C:\Users\miliv\videocutter\utils\vidlist.txt.
[concat @ 000001aaafb8e400] Opening 'C:\Users\miliv\videocutter\utils\vidlist.txt' for reading
[file @ 000001aaafb8f500] Setting default whitelist 'file,crypto,data'
[AVIOContext @ 000001aaafb97700] Statistics: 0 bytes read, 0 seeks
C:\Users\miliv\videocutter\utils\vidlist.txt: Invalid data found when processing input

标签: pythonffmpeg

解决方案


问题是我试图在关闭 vidlist.txt 文件之前合并视频,然后不允许 ffmpeg 打开它


推荐阅读