I want to know why Xabe.FFmpeg doesn't encode video files.

Asked 2 years ago, Updated 2 years ago, 286 views

In the presentation code, the .hevc file called test.mp4 should be loaded with the function t() and output as a file called sample.mp4, but the video file is not generated.Why is this?

Tried and Confirmed

What do you want to know

I want to know why the sample.mp4 file is not generated

Reference Site:
https://ffmpeg.xabe.net/docs.html

Windows 10 Visual Studio 2022 .Net 6.0

using Microsoft.VisualBasic;
using System;
using System.Collections.General;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Resources;
using Xabe.FFmpeg;

namespace HEVC_SimpleConverter
{
    public partial class Form 1:Form
    {
        private async void()
        {
            string outputPath="sample.mp4";
            IMediaInfo = wait FFmpeg.GetMediaInfo("test.mp4");

            ISstream videoStream=mediaInfo.VideoStreams.FirstOrDefault()
                ?.SetCodec (VideoCodec.h264);
            ISstream audioStream=mediaInfo.AudioStreams.FirstOrDefault()
                ?.SetCodec (AudioCodec.aac);

            FFmpeg.Conversations.New()
                .AddStream (audioStream, videoStream)
                .SetOutput(outputPath)
                .Start();
        }

        public Form 1()
        {
            InitializeComponent();
            t();
            Debug.WriteLine("aaaaa";
        }

        private void Form1_Load(object sender, EventArgse)
        {

        }
    }
}

c# net winforms

2022-11-07 13:27

2 Answers

Since t is an asynchronous method, passing through Debug.WriteLine does not necessarily mean that t has been processed.Also, let's not do async void except for event handlers.

Best Practices for Asynchronous Programming


2022-11-07 14:28

The reason is exactly what you said, but what should I do? The Form1_Load method, which is left empty every time I ask a question, is safe.

async Task(){
    var outputPath="sample.mp4";
    varmediaInfo = wait FFmpeg.GetMediaInfo("test.mp4");
    var videoStream=mediaInfo.VideoStreams.FirstOrDefault()?SetCodec(VideoCodec.h264);
    varaudioStream=mediaInfo.AudioStreams.FirstOrDefault()?SetCodec(AudioCodec.aac);
    wait FFmpeg.Conversions.New()
        .AddStream (audioStream, videoStream)
        .SetOutput(outputPath)
        .Start();
}

async void Form1_Load(object sender, EventArgse) {
    wait ();
    Debug.WriteLine("aaaaa";
}


2022-11-08 08:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.