Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Question: Do you have a plan to support Ut Video Codec Suite? #407

Open
yumetodo opened this issue May 12, 2019 · 11 comments
Open

Question: Do you have a plan to support Ut Video Codec Suite? #407

yumetodo opened this issue May 12, 2019 · 11 comments

Comments

@yumetodo
Copy link

Ut Video Codec Suite is a fast lossless video codec(GPL2 software).
https://github.com/umezawatakeshi/utvideo

This project already supports Lagarith, however, Ut Video Codec Suite is about 3x faster ( or more!) than Lagarith.

Look up this benchmark.
2016-12-31: http://umezawa.dyndns.info/wordpress/?p=6203
After this benchmark, Ut Video Codec Suite release more fast codec( UtVideo T2 (UMxx)) on version 19.0.1.
The new benchmark shows the speed.
2018-06-03: http://umezawa.dyndns.info/wordpress/?p=6911#more-6911

@MathewSachin
Copy link
Owner

Lagarith support in Captura is through Vfw (Video for Windows) api in SharpAvi.
I saw that Ut Video also supports that but I'm unable to find itsFOURCC.

BTW, Lagarith is implemented in just a few lines. It doesn't really bring out its whole potential but it works.

public static AviCodec Lagarith { get; } = new AviCodec(new FourCC("LAGS"), "Lagarith (Install Manually)");

yield return new SharpAviItem(AviCodec.Lagarith, "Lagarith codec needs to be installed manually and configured to use RGB mode with Null Frames disabled.");

If someone finds the FOURCC, it's pretty easy to add the codec.
This is a good first issue for anyone willing to begin contributing to Captura.
I've added links to both the files which need to change.
Basically, copy the code for Lagarith codec, change the Codec name, FOURCC and put a simple description.
Also, make sure the codec works with Captura after adding the code. It will be available under SharpAvi writer.

@MathewSachin
Copy link
Owner

ULY0, ULY2, ULRA, ULRG are the FourCC codes according to Wikipedia.

@yumetodo
Copy link
Author

UMH2, UMY2, UMH4, UMY4, UMRA, UMRG is T2 family
FFmpeg/FFmpeg@92b3266

@yumetodo
Copy link
Author

RGB32, RGB24, YV24, YV16, YUY2 is supported as input color space. Which should be preferred?
encode

@MathewSachin
Copy link
Owner

Captura supports only RGB32 as of now.

I'm trying to write GPU based conversion of RGB32 to YUV formats which will surely improve the performance.

So, in future we might be able to use YUY2 or YV12.

@yumetodo
Copy link
Author

https://github.com/MathewSachin/Captura/releases/tag/v9.0.0-beta4
RGB to NV12 on GPU before sending frames to FFmpeg

Is that means the things you said last year became true?

@MathewSachin
Copy link
Owner

Yup. But, the only format I could convert to using MediaFoundation was NV12.
I'm not sure if this works on everyone's systems though.

@yumetodo
Copy link
Author

yumetodo commented Mar 30, 2020

BTW, Lagarith is implemented in just a few lines. It doesn't really bring out its whole potential but it works.

I just now trying to implement supporting ut video codec. However, it's not so much easy.

Captura v0.0.0.0
OS: Microsoft Windows 10 Home|C
64-bit OS
64-bit Process
4 processor(s)

Name: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
NumberOfCores: 2
NumberOfLogicalProcessors: 4

Name: 物理メモリ
Capacity: 8589934592

Name: 物理メモリ
Capacity: 8589934592

Name: NVIDIA GeForce 940MX
AdapterRAM: 2147483648

Name: Intel(R) HD Graphics 620
AdapterRAM: 1073741824

Desktop: {X=0,Y=0,Width=1920,Height=1080}
Screen: \\.\DISPLAY1: {X=0,Y=0,Width=1920,Height=1080}
Mic: マイク配列 (Conexant SmartAudio HD)
Speaker: スピーカー (Conexant SmartAudio HD)
Webcam: Integrated Camera


System.Reflection.TargetInvocationException: Error calling wrapped encoder. ---> System.InvalidOperationException: No compatible MPEG-4 encoder found.
   場所 SharpAvi.Codecs.Mpeg4VideoEncoderVcm..ctor(Int32 width, Int32 height, Double fps, Int32 frameCount, Int32 quality, FourCC[] codecPreference)
   場所 SharpAvi.Codecs.EncodingStreamFactory.<>c__DisplayClass2_0.<AddMpeg4VideoStream>b__0()
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper.<>c__DisplayClass15_0`1.<DispatcherInvokeAndPropagateException>b__0()
   --- 内部例外スタック トレースの終わり ---
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper.WrapAndRethrowException(Exception wrappedException)
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper.DispatcherInvokeAndPropagateException[TResult](Func`1 func)
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper..ctor(Func`1 encoderFactory)
   場所 SharpAvi.Codecs.EncodingStreamFactory.AddMpeg4VideoStream(AviWriter writer, Int32 width, Int32 height, Double fps, Int32 frameCount, Int32 quality, Nullable`1 codec, Boolean forceSingleThreadedAccess)
   場所 Captura.Models.AviWriter.CreateVideoStream(Int32 Width, Int32 Height) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.SharpAvi\AviWriter.cs:行 87
   場所 Captura.Models.AviWriter..ctor(String FileName, AviCodec Codec, IImageProvider ImageProvider, Int32 FrameRate, IAudioProvider AudioProvider) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.SharpAvi\AviWriter.cs:行 48
   場所 Captura.Models.SharpAviItem.GetVideoFileWriter(VideoWriterArgs Args) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.SharpAvi\SharpAviItem.cs:行 21
   場所 Captura.ViewModels.RecordingModel.GetVideoFileWriter(IImageProvider ImgProvider, IAudioProvider AudioProvider, RecordingModelParams RecordingParams, String FileName) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.Core\ViewModels\RecordingModel.cs:行 466
   場所 Captura.ViewModels.RecordingModel.GetVideoFileWriterWithPreview(IImageProvider ImgProvider, IAudioProvider AudioProvider, RecordingModelParams RecordingParams) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.Core\ViewModels\RecordingModel.cs:行 440
   場所 Captura.ViewModels.RecordingModel.SetupVideoRecorder(IAudioProvider AudioProvider, RecordingModelParams RecordingParams, IMouseKeyHook MouseKeyHook) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.Core\ViewModels\RecordingModel.cs:行 147
Captura v0.0.0.0
OS: Microsoft Windows 10 Home|C
64-bit OS
64-bit Process
4 processor(s)

Name: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
NumberOfCores: 2
NumberOfLogicalProcessors: 4

Name: 物理メモリ
Capacity: 8589934592

Name: 物理メモリ
Capacity: 8589934592

Name: NVIDIA GeForce 940MX
AdapterRAM: 2147483648

Name: Intel(R) HD Graphics 620
AdapterRAM: 1073741824

Desktop: {X=0,Y=0,Width=1920,Height=1080}
Screen: \\.\DISPLAY1: {X=0,Y=0,Width=1920,Height=1080}
Mic: マイク配列 (Conexant SmartAudio HD)
Speaker: スピーカー (Conexant SmartAudio HD)
Webcam: Integrated Camera


System.Reflection.TargetInvocationException: Error calling wrapped encoder. ---> System.InvalidOperationException: No compatible MPEG-4 encoder found.
   場所 SharpAvi.Codecs.Mpeg4VideoEncoderVcm..ctor(Int32 width, Int32 height, Double fps, Int32 frameCount, Int32 quality, FourCC[] codecPreference)
   場所 SharpAvi.Codecs.EncodingStreamFactory.<>c__DisplayClass2_0.<AddMpeg4VideoStream>b__0()
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper.<>c__DisplayClass15_0`1.<DispatcherInvokeAndPropagateException>b__0()
   --- 内部例外スタック トレースの終わり ---
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper.WrapAndRethrowException(Exception wrappedException)
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper.DispatcherInvokeAndPropagateException[TResult](Func`1 func)
   場所 SharpAvi.Codecs.SingleThreadedVideoEncoderWrapper..ctor(Func`1 encoderFactory)
   場所 SharpAvi.Codecs.EncodingStreamFactory.AddMpeg4VideoStream(AviWriter writer, Int32 width, Int32 height, Double fps, Int32 frameCount, Int32 quality, Nullable`1 codec, Boolean forceSingleThreadedAccess)
   場所 Captura.Models.AviWriter.CreateVideoStream(Int32 Width, Int32 Height) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.SharpAvi\AviWriter.cs:行 87
   場所 Captura.Models.AviWriter..ctor(String FileName, AviCodec Codec, IImageProvider ImageProvider, Int32 FrameRate, IAudioProvider AudioProvider) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.SharpAvi\AviWriter.cs:行 48
   場所 Captura.Models.SharpAviItem.GetVideoFileWriter(VideoWriterArgs Args) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.SharpAvi\SharpAviItem.cs:行 21
   場所 Captura.ViewModels.RecordingModel.GetVideoFileWriter(IImageProvider ImgProvider, IAudioProvider AudioProvider, RecordingModelParams RecordingParams, String FileName) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.Core\ViewModels\RecordingModel.cs:行 466
   場所 Captura.ViewModels.RecordingModel.GetVideoFileWriterWithPreview(IImageProvider ImgProvider, IAudioProvider AudioProvider, RecordingModelParams RecordingParams) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.Core\ViewModels\RecordingModel.cs:行 440
   場所 Captura.ViewModels.RecordingModel.SetupVideoRecorder(IAudioProvider AudioProvider, RecordingModelParams RecordingParams, IMouseKeyHook MouseKeyHook) 場所 C:\Users\yumetodo\Source\Repos\Captura\src\Captura.Core\ViewModels\RecordingModel.cs:行 147

What is MPEG-4 Encoder? What is single thread video encoder wrapper?

Ut Video Codec is a multi-thread, non-MPEG-4 codec. Today, almost all vfw codec supports multi-thread. (AMV4 is an exception because it is enough fast in a single thread.) I don't know why SharpAvi team think SingleThreadedVideoEncoderWrapper is clever.

In any case, I'm currently debugging GetCompressor why it returns nullptr.

https://github.com/baSSiLL/SharpAvi/blob/da8f93369ddbdd3b3f2911bd16ccce7b7b0d0262/SharpAvi/Codecs/Mpeg4VideoEncoderVcm.cs#L75-L100

https://github.com/yumetodo/Captura/tree/feat/support_ut_video_codec

yumetodo@5c842a4

@yumetodo
Copy link
Author

yumetodo commented Mar 30, 2020

I cut out GetCompressor implementation and debugging now.

image

In compressorInfo returned via argument of ICGetInfo, flags is 0. As a result, compressorInfo.SupportsFastTemporalCompression is false.

https://github.com/baSSiLL/SharpAvi/blob/da8f93369ddbdd3b3f2911bd16ccce7b7b0d0262/SharpAvi/Codecs/VfwApi.cs#L99-L102

So, I investigated the Ut Video Codec implementation.

https://github.com/umezawatakeshi/utvideo/blob/077a6a6202a3b5d60d1716559759210f6cedd795/utv_vcm/DriverProc.cpp#L41-L42
https://github.com/umezawatakeshi/utvideo/blob/077a6a6202a3b5d60d1716559759210f6cedd795/utv_vcm/VCMCodec.cpp#L99-L117

icinfo->dwFlags      = m_pCodec->IsTemporalCompressionSupported() ? (VIDCF_TEMPORAL | VIDCF_FASTTEMPORALC | VIDCF_FASTTEMPORALD) : 0;

When m_pCodec->IsTemporalCompressionSupported() is false, flags will be 0.

image

I'm investigating why SharpAvi requests such a limitation.


BTW, As a result, only when UMxx family(UtVideo T2 familly), compressorInfo.SupportsFastTemporalCompression can be true.
http://umezawa.dyndns.info/archive/utvideo/utvideo-21.2.0-readme.en.html#fourcc

So, I change FourCC to UMH2 and tried again. And then, capture was worked!
yumetodo@47b108c

However, the produced movie file is broken.

  • Windows Media Player:
    image
  • Aviutl:
    image
    image

The produced broken avi file is here.
https://mega.nz/#!ulNxBSbb!mVcY6ieqywYIgBVhvlwy_CfwkV7VMEwYUckiNF_vJFI

@MathewSachin
Copy link
Owner

Umm... These things are quite over my head. I'm no expert when it comes to video encoding.
I checked and found that FFmpeg supports a codec named utvideo. How about trying to encode using FFmpeg?

@yumetodo
Copy link
Author

yumetodo commented Mar 31, 2020

FFmpeg(avcodec) doesn't support ut video codec as an encoder.

https://github.com/FFmpeg/FFmpeg/blob/fa164bc50e3400fbddf94bcafbfe33e2ce9ab24b/libavcodec/utvideodec.c#L1-L2

/*
 * Ut Video decoder

https://github.com/FFmpeg/FFmpeg/blob/fa164bc50e3400fbddf94bcafbfe33e2ce9ab24b/libavcodec/utvideodec.c#L1094-L1105

AVCodec ff_utvideo_decoder = {
    .name           = "utvideo",
    .long_name      = NULL_IF_CONFIG_SMALL("Ut Video"),
    .type           = AVMEDIA_TYPE_VIDEO,
    .id             = AV_CODEC_ID_UTVIDEO,
    .priv_data_size = sizeof(UtvideoContext),
    .init           = decode_init,
    .close          = decode_end,
    .decode         = decode_frame,
    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
};

https://github.com/FFmpeg/FFmpeg/blob/7322eab453f7d60c66846d22a14b77d3c9ae5cc3/libavcodec/allcodecs.c#L313

extern AVCodec ff_utvideo_decoder;

https://github.com/FFmpeg/FFmpeg/search?o=desc&q=avcodec%2Futvideodec&s=committer-date&type=Commits

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants