NReco video cut

2019-07-11 13:18发布

问题:

I have written a function to cut a video using NReco library.

public void SplitVideo(string SourceFile,string DestinationFile,int StartTime,int EndTime)
        {
            var ffMpegConverter = new FFMpegConverter();
            ffMpegConverter.ConvertMedia(SourceFile, null, DestinationFile, null,
                new ConvertSettings()
                {
                    Seek = StartTime,
                    MaxDuration = (EndTime-StartTime), // chunk duration
                    VideoCodec = "copy",
                    AudioCodec = "copy"
                });
        }

This is working and give me a video starting from the beginning of the video to the max duration i have assign. It is not starting from the seek value position and to the max duration. Can some one help me on this.

回答1:

I have found the answer for this issue. May this help someone.

I was using worong codecs. You have to use correct codec type according to the file type you are converting. here i am using a mp4 file. So i had to use libx264 and mp3. Beelow is the sample code

public void SplitVideo(string SourceFile,string DestinationFile,int StartTime,int EndTime)
        {
            var ffMpegConverter = new FFMpegConverter();
            ffMpegConverter.ConvertMedia(SourceFile, null, DestinationFile, null,
                new ConvertSettings()
                {
                    Seek = StartTime,
                    MaxDuration = (EndTime-StartTime), // chunk duration
                    VideoCodec = "libx264",
                    AudioCodec = "mp3"
                });
        }


标签: ffmpeg