FFMPEG 错误代码:"Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_scale_10"; [complex_filter], [-loop 1], [覆盖]

FFMPEG Error Code: "Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_scale_10"; [complex_filter], [-loop 1], [overlay]

我目前正在尝试使用 ffmpeg。

我想制作一个具有 .jpg 背景图像的视频,上面覆盖了多个视频。

目前我可以在黑色背景上叠加任意数量的视频。但是我试图将静态图像添加到背景,然后它不再起作用了。

我的 FFMPEG 命令行是

command = f"ffmpeg -loop 1 -i background.jpg -i vid1.mp4 -i vid2.mp4 -i vid3.mp4 -i vid4.mp4 -filter_complex "nullsrc=size=1920x1080 [base]; 
    [0:v] setpts=PTS-STARTPTS, scale=320x240 [low]; 
    [1:v] setpts=PTS-STARTPTS, scale=320x240 [upperleft]; 
    [2:v] setpts=PTS-STARTPTS, scale=320x240 [upperright]; 
    [3:v] setpts=PTS-STARTPTS, scale=320x240 [lowerleft]; 
    [4:v] setpts=PTS-STARTPTS; scale=320x240 [lowerright]; 
    [base][upperleft] overlay=shortest=1 [tmp0]; 
    [tmp0][low] overlay=shortest=1:x=420:y=240 [tmp1]; 
    [tmp1][upperright] overlay=shortest=1:x=320 [tmp2]; 
    [tmp2][lowerleft] overlay=shortest=1:y=240 [tmp3]; 
    [tmp3][lowerright] overlay=shortest=1:x=320:y=240" 
    -c:v libx264 output.mkv"

这将生成以下错误消息

Input #0, image2, from '/home/leroy/Schreibtisch/FFMPEG_TEST/bild.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 71996 kb/s
    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/home/leroy/Schreibtisch/FFMPEG_TEST/1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2015-08-07T09:13:36.000000Z
  Duration: 00:00:30.53, start: 0.000000, bitrate: 4675 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 4486 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2015-08-07T09:13:36.000000Z
      handler_name    : L-SMASH Video Handler
      encoder         : AVC Coding
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      creation_time   : 2015-08-07T09:13:36.000000Z
      handler_name    : L-SMASH Audio Handler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/home/leroy/Schreibtisch/FFMPEG_TEST/2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20T21:29:11.000000Z
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
    Stream #2:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
      encoder         : JVT/AVC Coding
    Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '/home/leroy/Schreibtisch/FFMPEG_TEST/3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20T21:29:11.000000Z
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
    Stream #3:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
      encoder         : JVT/AVC Coding
    Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from '/home/leroy/Schreibtisch/FFMPEG_TEST/4.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20T21:29:11.000000Z
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
    Stream #4:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
      encoder         : JVT/AVC Coding
    Stream #4:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z

Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_scale_10

我使用了 Ubuntu 18.04.LST 并在 Python3.6.9.

中编程

我的完整代码是:

from pathlib import Path
import os
suffix = '.mp4'
suffix1 = '.jpg'
os.system("clear")


input_path = Path.home() / "/home/leroy/Schreibtisch/FFMPEG_TEST"
file_paths = [subp for subp in input_path.rglob('*') if  suffix == subp.suffix or suffix1 == subp.suffix]
file_paths.sort()
output_path =  Path.home() / "/home/leroy/Schreibtisch/FFMPEG_TEST/new"
output_path.mkdir(parents=True, exist_ok=True)


vid1 = '/home/leroy/Schreibtisch/FFMPEG_TEST/1.mp4'
vid2 = '/home/leroy/Schreibtisch/FFMPEG_TEST/2.mp4'
vid3 = '/home/leroy/Schreibtisch/FFMPEG_TEST/3.mp4'
vid4 = '/home/leroy/Schreibtisch/FFMPEG_TEST/4.mp4'
background = '/home/leroy/Schreibtisch/FFMPEG_TEST/bild.jpg'


command = f"ffmpeg -loop 1 -i {background} -i {vid1} -i {vid2} -i {vid3} -i {vid4} -filter_complex \
\"nullsrc=size=1920x1080 [base]; \
[0:v] setpts=PTS-STARTPTS, scale=320x240 [low]; \
[1:v] setpts=PTS-STARTPTS, scale=320x240 [upperleft]; \
[2:v] setpts=PTS-STARTPTS, scale=320x240 [upperright]; \
[3:v] setpts=PTS-STARTPTS, scale=320x240 [lowerleft]; \
[4:v] setpts=PTS-STARTPTS; scale=320x240 [lowerright]; \
[base][upperleft] overlay=shortest=1 [tmp0]; \
[tmp0][low] overlay=shortest=1:x=420:y=240 [tmp1]; \
[tmp1][upperright] overlay=shortest=1:x=320 [tmp2]; \
[tmp2][lowerleft] overlay=shortest=1:y=240 [tmp3]; \
[tmp3][lowerright] overlay=shortest=1:x=320:y=240 \" \
-c:v libx264 output.mkv"
print(command)
os.system(command)

有错字。

变化:

[4:v] setpts=PTS-STARTPTS; scale=320x240 [lowerright]; \

至:

[4:v] setpts=PTS-STARTPTS, scale=320x240 [lowerright]; \