NReco video cut

2019-07-11 12:46发布

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.

标签: ffmpeg
1条回答
地球回转人心会变
2楼-- · 2019-07-11 13:32

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"
                });
        }
查看更多
登录 后发表回答