Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video/Audio Concat #95

Open
gmav opened this issue Dec 5, 2018 · 1 comment
Open

Video/Audio Concat #95

gmav opened this issue Dec 5, 2018 · 1 comment

Comments

@gmav
Copy link

gmav commented Dec 5, 2018

Hello i'm trying to concat two mp4 files, both contain video/audio stream. After some search i've found a working solution:

var commandFactory = CommandFactory.Create();
var command = commandFactory
.CreateOutputCommand()
.AddInput(@"c:\temp\vvv1.mp4")
.AddInput(@"c:\temp\\vvv2.mp4");

var videoConcat = command
.Select<VideoStream>(0)
.Select<VideoStream>(1)
.Filter(Filterchain.FilterTo<VideoStream>(new Concat()));

var audioConcat = command
.Select<AudioStream>(0)
.Select<AudioStream>(1)
.Filter(Filterchain.FilterTo<AudioStream>(new Concat(1, 0)));

command.Select(videoConcat, audioConcat)
.MapTo<Mp4>(@"c:\temp\output.mp4", SettingsCollection.ForOutput(new OverwriteOutput()));
commandFactory.Render();

Is there a way to do it in a single stage?

@Casey-Bateman
Copy link
Contributor

Sorry for a late reply,

It looks like you are doing an encode concat, are the video and audio streams in the same input format? If so you can do a mux concat, basically you would add the two inputs to a txt file, then pass the txt through ffmpeg as an input with the Codec copy command, It will concatenate the two files end to end.

The input file looks like this

file 'c:\temp\vvv1.mp4'
file 'c:\temp\vvv2.mp4'

The output command, as i would recommend it, would look like this

ffmpeg -auto_convert 1 -f concat -i "c:\temp\mytextfile.txt" -c copy -shortest -movflags +faststart "c:\temp\output.mp4"

The code to do this in Hudl.Ffmpeg looks like this

            var commandFactory = CommandFactory.Create();

            var inputSettings = SettingsCollection.ForInput(
                new AutoConvert(),
                new FormatInput(FormatType.Concat));

            var outputSettings = SettingsCollection.ForOutput(
                new OverwriteOutput(),
                new MovFlags(MovFlags.EnableFastStart),
                new TrimShortest(),
                new CodecAudio(AudioCodecType.Copy),
                new CodecVideo(VideoCodecType.Copy));

            commandFactory.CreateOutputCommand()
                            .AddInput("c:\temp\mytextfile.txt", inputSettings)
                            .To<Mp4>("c:\temp\output.mp4", outputSettings);

            commandFactory.Render();
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants