Xabe.FFmpeg icon indicating copy to clipboard operation
Xabe.FFmpeg copied to clipboard

not able to use on intel hevc_qsv as video codec

Open georgnistor opened this issue 3 years ago • 2 comments

Hi, I am new to this library. I have just installed 5.0.2 via nuget and tried to encode on my system which has a RocketLake CPU.

I am unable to encode with qsv, the encoding works fine but it uses the cpu cores.

I cannot select hevc_qsv as video encoder.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Xabe.FFmpeg;

namespace xabe_1
{
    class Program
    {
        static void Main(string[] args)
        {

            //FFmpeg.ExecutablesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FFmpeg");
            FFmpeg.SetExecutablesPath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

            testFFMPEG().Wait();
        }

        static async Task testFFMPEG()
        {
            
            
            string outputPath = @"F:\encodded\george.mkv";
            IMediaInfo mediaInfo = await FFmpeg.GetMediaInfo(@"F:\encodded\input.sample.mkv");

            foreach(var vstream in mediaInfo.VideoStreams.ToList())
            {
                Console.WriteLine("stream: {0}", vstream.Duration);
            }

            IStream videoStream = mediaInfo.VideoStreams.FirstOrDefault()?.SetCodec(VideoCodec.hevc).SetBitrate(9000000);
            IStream audioStream = mediaInfo.AudioStreams.FirstOrDefault()?.SetCodec(AudioCodec.flac).SetChannels(2);

            var cancellationTokenSource = new CancellationTokenSource();

            var myConversion = FFmpeg.Conversions.New();


            myConversion.OnProgress += (sender, args) =>
            {
                var percent = (int)(Math.Round(args.Duration.TotalSeconds / args.TotalLength.TotalSeconds, 2) * 100);
                Console.WriteLine($"[{args.Duration} / {args.TotalLength}] {percent}%");
            };


            myConversion.OnDataReceived += (sender, args) =>
            {
                Console.WriteLine($"{args.Data}{Environment.NewLine}");
            };


            myConversion.UseHardwareAcceleration(HardwareAccelerator.qsv, VideoCodec.h264, VideoCodec.hevc, 0)
                                                .SetPixelFormat(PixelFormat.yuv420p10le).UseMultiThread(4).SetPreset(ConversionPreset.UltraFast);
                                                //.AddParameter("-hwaccel qsv", ParameterPosition.PreInput)
                                                //.AddParameter("-c:v hevc_qsv", ParameterPosition.PostInput);


            cancellationTokenSource.CancelAfter(30000);

            try 
            {
                await myConversion.AddStream(audioStream, videoStream).SetOutput(outputPath).Start(cancellationTokenSource.Token);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
            }
            
        }
    }
}

georgnistor avatar Jun 30 '21 12:06 georgnistor

hi, I have managed to import the project source code to my project and use it. I have modified VideoCodecs.cs to add def for hevc_qsv and now it runs with GPU Processing.

Could you please add it in the the version of the nuget package, assembly?

        ///<summary>
        ///      libx264
        ///</summary>
        libx264,

        ///<summary>
        ///      hevc_qsv (intel quicksync)
        ///</summary>
        hevc_qsv

georgnistor avatar Jun 30 '21 18:06 georgnistor

Hello @georgnistor VideoCodec already has libx264 format. I'm going to add hevc_qsv.

Till the new version will be published you can use overloaded UseHardwareAcceleration method public IConversion UseHardwareAcceleration(string hardwareAccelerator, string decoder, string encoder, int device = 0)\

Loot at that code: image

tomaszzmuda avatar Jul 03 '21 15:07 tomaszzmuda