ffmpeg-python icon indicating copy to clipboard operation
ffmpeg-python copied to clipboard

Help : Stream Concat issue.

Open 808Code opened this issue 1 year ago • 0 comments

These are the list of my video streams :

streams = [crop(405, 720, 0, 0)[None] <1419607ede0d>,
crop(405, 720, 168.0, 0)[None] <60513abfe190>,
crop(405, 720, 105.0, 0)[None] <146a20b22810>,
crop(405, 720, 170.0, 0)[None] <5c287e877550>,
crop(405, 720, 722.5, 0)[None] <2f24c0d564b0>,
crop(405, 720, 0, 0)[None] <1e03ffc24d4a>]```

Where 0 and 5 are returns of these function:

def zoom_out_stream(input_file, start_time, end_time, width, height):
  return (
    ffmpeg.input(input_file, ss=start_time, to=end_time).filter(
        'scale', f'min({width},iw)', f'min({height},ih)', force_original_aspect_ratio='decrease'
    ).filter(
        'pad', width+1, height+1, -1, -1, 'black'
    ).filter('crop', width, height , 0, 0)
  )

while others are return of these :

def zoom_in_stream(input_file, start_time, end_time, width, height,x, y):
    return (
        ffmpeg
        .input(input_file, ss=start_time, to=end_time)
        .filter('crop', width, height , x, y)
    )

When i try to concat the above mentioned lists with the code :

concatenated_stream = ffmpeg.concat(*streams)


output_settings = {
    'c:v': 'libx264',  # Video codec
    'preset': 'ultrafast',  # Preset for encoding speed
}

# Output filename
output_filename ='output.mp4'

# Build ffmpeg command
ffmpeg_cmd = ffmpeg.output(concatenated_stream, output_filename, **output_settings)

try:
    ffmpeg_cmd.run(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

I keep getting the error :

Stream mapping:
  Stream #0:0 (h264) -> scale
  Stream #1:0 (h264) -> crop
  Stream #2:0 (h264) -> crop
  Stream #3:0 (h264) -> crop
  Stream #4:0 (h264) -> crop
  Stream #5:0 (h264) -> scale
  concat -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[Parsed_concat_10 @ 0x5ab6baa53080] Input link in0:v0 parameters (size 404x720, SAR 1:1) do not match the corresponding output link in0:v0 parameters (404x720, SAR 1216:1215)
[Parsed_concat_10 @ 0x5ab6baa53080] Failed to configure output pad on Parsed_concat_10
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #5:0
Conversion failed!

Any idea how i can solve this all the streams have been cropped to the same width and height as mentioned in the streams list.

808Code avatar Jun 10 '24 17:06 808Code