Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • F ffmpeg-python
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 402
    • Issues 402
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 34
    • Merge requests 34
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Karl Kroening
  • ffmpeg-python
  • Issues
  • #507
Closed
Open
Issue created Mar 13, 2021 by Administrator@rootContributor

Question: Concating video created from images; adding logo to result

Created by: bralbral

Good day!

I want to add a start_screen and end_screen, and logo for all duration of raw video.

I looked at examples and did something like this...

My code :

import ffmpeg

input_args = {
    "hwaccel": "nvdec",
    "vcodec": "h264_cuvid",
    "c:v": "h264_cuvid"
}

output_args = {
    "vcodec": "h264_nvenc",
    "c:v": "h264_nvenc",
    "preset": "slow",
    "crf": 23,
    "acodec": "copy"
}

def video_info(filepath: str) -> dict:
  try:
      probe = ffmpeg.probe(input_filename)
      video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
      if video_stream is None:
          print('No video stream found', file=sys.stderr)
      width = int(video_stream['width'])
      height = int(video_stream['height'])
      num_frames = int(video_stream['nb_frames'])
      return dict(width=width, height=height, num_frames=num_frames)
  except ffmpeg.Error as e:
      print(e.stderr, file=sys.stderr)


input_filename = path.join(RAW_VIDEOS_FOLDER, listdir(RAW_VIDEOS_FOLDER)[0])
info = video_info(input_filename)

logo_height = int(info['height'] / 15)
logo_width = int(info['width'] / 15)
logo_pos_x = int(info['width']) - logo_width
logo_pos_y = int(info['height']) - logo_height

raw = ffmpeg.input(input_filename, **input_args)
raw_audio = raw.audio

logo = ffmpeg.input(LOGO).filter('scale', height=logo_height, width=logo_width)
screen = ffmpeg.input(SCREEN).filter('scale', height=info['height'], width=info['width'])


stream = ffmpeg.overlay(raw, logo, x=logo_pos_x, y=0)


joined = ffmpeg.concat(
    screen.video, screen.audio, stream.video, raw_audio, screen.video, screen.audio, v=1, a=1, unsafe=True)

stream = ffmpeg.output(joined.video, joined.audio, path.join(READY_VIDEOS_FOLDER,'output.mp4'), **output_args)

try:
  ffmpeg.run(stream, overwrite_output=True, capture_stdout=True, capture_stderr=True)
except ffmpeg.Error as e:
    print('stdout:', e.stdout.decode('utf8'))
    print('stderr:', e.stderr.decode('utf8'))
    raise e

Error:

ValueError: Encountered scale(height=720, width=1280) <16e5e56a04d1> with multiple outgoing edges with same upstream label None; a split filter is probably required

What's wrong?

Pure ffmpeg command looks like

ffmpeg -i BeSureToWear.mp4 -i BeSureToWear.mp4 -filter_complex '[0:v] [0:a:0] [1:v] [1:a:0] concat=n=2:v=1:a=1 [v] [a]' -map '[v]' -map '[a]' BeSureToWearConcat.mp4

Assignee
Assign to
Time tracking