u2takey / ffmpeg-go

golang binding for ffmpeg
Apache License 2.0
1.75k stars 172 forks source link

Wrong input order after concat() for more than 10 inputs #68

Open LER0ever opened 1 year ago

LER0ever commented 1 year ago

Overview

When using the Concat() function for more than 10 inputs, the original ordering of those input files are not correctly preserved.

In the following small case below, 16 input streams are created (0, 1, 2, 3, ..., 14, 15), but the final output command has the order (0, 1, 10, 11, 12, 13, 14, 15, 2, 3, 4, ... 8, 9) as if the indices were sorted lexicographically.

Minimal reproducible case

Source code:

package main

import (
    "fmt"

    ffmpeg "github.com/u2takey/ffmpeg-go"
)

func main() {
    filelist := []string{}
    for i := 0; i < 16; i++ {
        filelist = append(filelist, fmt.Sprintf("test%d.mp4", i))
    }

    inputs := make([]*ffmpeg.Stream, 0, len(filelist))
    for _, v := range filelist {
        inputs = append(inputs, ffmpeg.Input(v))
    }
    ff_task := ffmpeg.Concat(inputs).Output("output.mp4").OverWriteOutput()
    println(ff_task.Compile())
    mermaid_view, _ := ff_task.View(ffmpeg.ViewTypeFlowChart)
    println(mermaid_view)
}

Compiled command:

ffmpeg -i test0.mp4 -i test1.mp4 -i test10.mp4 -i test11.mp4 -i test12.mp4 -i test13.mp4 
-i test14.mp4 -i test15.mp4 -i test2.mp4 -i test3.mp4 -i test4.mp4 -i test5.mp4 -i test6.mp4 
-i test7.mp4 -i test8.mp4 -i test9.mp4 
-filter_complex [0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15]concat=n=16[s0] 
-map [s0] output.mp4 -y

Mermaid dependency graph:

graph LR
    3941257213206123015[input]
    -6530390412756632220[input]
    7552133026329416720[input]
    -1796561310369158781[input]
    -4899040177159599726[input]
    4198974375479273573[input]
    -6574418899481965596[input]
    3897228726480789639[input]
    5418486196261043753[input]
    -473457997601007962[input]
    -1752532823643825405[input]
    7596161513054750096[input]
    4243002862204606949[input]
    -4855011690434266350[input]
    -2903915435716980545[input]
    6444814085353697628[input]
    -8934247347040772720[concat]
    -8268504780477368488[output]

    3941257213206123015 --> |0:<>| -8934247347040772720
    -6530390412756632220 --> |1:<>| -8934247347040772720
    7552133026329416720 --> |10:<>| -8934247347040772720
    -1796561310369158781 --> |11:<>| -8934247347040772720
    -4899040177159599726 --> |12:<>| -8934247347040772720
    4198974375479273573 --> |13:<>| -8934247347040772720
    -6574418899481965596 --> |14:<>| -8934247347040772720
    3897228726480789639 --> |15:<>| -8934247347040772720
    5418486196261043753 --> |2:<>| -8934247347040772720
    -473457997601007962 --> |3:<>| -8934247347040772720
    -1752532823643825405 --> |4:<>| -8934247347040772720
    7596161513054750096 --> |5:<>| -8934247347040772720
    4243002862204606949 --> |6:<>| -8934247347040772720
    -4855011690434266350 --> |7:<>| -8934247347040772720
    -2903915435716980545 --> |8:<>| -8934247347040772720
    6444814085353697628 --> |9:<>| -8934247347040772720
    -8934247347040772720 --> |0:<>| -8268504780477368488
pashonic commented 1 year ago

Any idea on when this can be fixed?