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

[Bug]Sometimes the compressed video file would be corrupted. #173

Open
sbs-surendhar-kabilan opened this issue Mar 3, 2022 · 0 comments

Comments

@sbs-surendhar-kabilan
Copy link

sbs-surendhar-kabilan commented Mar 3, 2022

We are using OtaliaStudios.TranscoderLib ITranscoderListener to compress the video in our application.

Current behavior:
Sometimes the compressed video file would be corrupted and getting exceptions in our application.

Expected behavior:
After compressing the video, the video should be playable and not corrupt.

In our application, please see the code snippet that we were used for compressing the video.

VideoTranscoder.TranscodeVideoAsync(inputPath, outputPath);

public static async Task TranscodeVideoAsync(string sourceVideoPath, string outputpath)
{

        string path = System.IO.Path.GetDirectoryName(outputpath);
        AVAssetExportSession export = new AVAssetExportSession(sourceVideoPath);
        string outputFilePath = Path.Combine(path, $"{DateTime.Now.ToString(DateString.strDMYHMS, AppState.CultureInfo)}.mp4");
        export.OutputPath = outputFilePath;

        await export.ExportTaskAsync();

        MemoryStream output = new MemoryStream();
        using (Stream source = File.OpenRead(outputFilePath))
            await source.CopyToAsync(output);

        output.Seek(0, SeekOrigin.Begin);
        return outputFilePath;

}

public async Task ExportTaskAsync()
{

             DefaultVideoStrategy videoStrategy = new DefaultVideoStrategy.Builder()
                .AddResizer(new ExactResizer(720, 1280))
                .BitRate(4096)
                .FrameRate(40)
                .KeyFrameInterval(3f)
                .Build();

            DefaultAudioStrategy audioStrategy = new DefaultAudioStrategy.Builder()
                   .SampleRate(DefaultAudioStrategy.SampleRateAsInput)
             .BitRate(DefaultAudioStrategy.BitrateUnknown).Build();

            await _semaphore.WaitAsync();
            Transcoder.Into(this.OutputPath)
                .AddDataSource(_assetPath)
                .SetVideoTrackStrategy(DefaultVideoStrategies.For720x1280())
                .SetAudioTrackStrategy(audioStrategy)
                .SetListener(this)
                .Transcode();
            await _semaphore.WaitAsync();

}

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

1 participant