UnityPlugin-AVProVideo icon indicating copy to clipboard operation
UnityPlugin-AVProVideo copied to clipboard

AVPro Video's Support of Playing encrypted mp4 or Play Video From Memory

Open eiyamomo opened this issue 1 year ago • 12 comments

Before I asked this question, I have tried to search online or going through existing issues. Yet I can't find any solution for this.

I am creating a FMV-like game using Unity which includes a lot of videoclips (which currently in mp4).

I would like to encrypt the video files so the player would play the game (rather than find and play those videoclips locally)

It seems that AvPro Video's media player only support playing Video from File Path. I was hoping I could just load the encrypted video, decrypt it, then feed it to AvPro Video's mediaplayer. But I couldn't find out how.

the cycle of "load encrypted video -> decrypt -> write into local -> delete after finished playing" doesn't seem to be feasible as it might introduce uncertainties in terms of delays/performance hit/etc.

a lot of question I have found even traced back to 2020-2021, which really concerns me.

As today of June 2024, just wondering if there is any way (or alternative way) that is currently supported by AvPro Video to achieve being able to play encrypted videoclips?

Any help would be appreciated.

Thanks in advance.

eiyamomo avatar Jun 27 '24 02:06 eiyamomo

Which platform are you looking at using?

Chris-RH avatar Jun 27 '24 08:06 Chris-RH

Windows platform for steam(for now at least).

eiyamomo avatar Jun 27 '24 12:06 eiyamomo

I was finally able to get OpenMediaFromBuffer working

By load the encrypted mp4, decrypt it into a byte[]

then set the videoAPI to be directshow

mediaPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.DirectShow;

However the videoclip's aspect ratio / resolution got changed.

It was originally 2560x1440, but it got changed to 720x480.

[AVProVideo] Using playback path: DirectShow ([email protected]) UnityEngine.Debug:Log (object) RenderHeads.Media.AVProVideo.Helper:LogInfo (string,UnityEngine.Object) (at Assets/AVProVideo/Runtime/Scripts/Internal/Helper.cs:183) RenderHeads.Media.AVProVideo.WindowsMediaPlayer:Update () (at Assets/AVProVideo/Runtime/Scripts/Internal/Players/WindowsMediaPlayer.cs:818) RenderHeads.Media.AVProVideo.MediaPlayer:Update () (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:823)

is there way to keep it at 2560x1440?

tried to search the api documentation, but didn't find anything

Edit#1: I am using AVPro Video - Ultra Edition - 2.9.3

Edit#2: It works for mp4 up to 1920x1080p, but not for 1440p or 4k This is not only happening to OpenMediaFromBuffer but in general to AvPro Video when the videoAPI is set to DirectShow.

eiyamomo avatar Jun 29 '24 18:06 eiyamomo

Are you able to send us a sample of the media you are playing please? Either here or to [email protected]

Chris-RH avatar Jul 01 '24 06:07 Chris-RH

When I tried - You can just try it in the editor.

Set the videoapi to directshow, then use the browse(of the mediaplayer gameobject)

If you play any mp4 greater than 1080p, under the media info(mediaplayer gameobject), you will see it says 720×480.

While anything under or including 1080p it will be fine.

On Mon, Jul 1, 2024 at 02:48 Chris-RH @.***> wrote:

Are you able to send us a sample of the media you are playing please? Either here or to @.***

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1918#issuecomment-2199367641, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEUUIXI6LAWDGQBBYK36GQTZKD3VDAVCNFSM6AAAAABJ7ADVQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJZGM3DONRUGE . You are receiving this because you authored the thread.Message ID: @.***>

eiyamomo avatar Jul 01 '24 10:07 eiyamomo

Which version of AVPro Video are you using? I can't reproduce this in the mediaplayer demo scene.

Chris-RH avatar Jul 01 '24 12:07 Chris-RH

Version 2.9.3

By adding a mediaplayer component to the gameobject, and set the videoapi to directshow(then browse the videoclip)

On Mon, Jul 1, 2024 at 08:24 Chris-RH @.***> wrote:

Which version of AVPro Video are you using? I can't reproduce this in the mediaplayer demo scene.

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1918#issuecomment-2200006583, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEUUIXKBI6XBXMUKKPAIQW3ZKFC7NAVCNFSM6AAAAABJ7ADVQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBQGAYDMNJYGM . You are receiving this because you authored the thread.Message ID: @.***>

eiyamomo avatar Jul 01 '24 12:07 eiyamomo

Do you see the same issue in MediaFoundation and WinRT?

Chris-RH avatar Jul 02 '24 13:07 Chris-RH

Morning Chris,

Never tried WinRT, but it was working on MediaFoundation.

However, based on the historical issues opened and contributed by another dev/support from RH.

Mediaplayer.OpenMediafromBuffer only works if the VideoAPI is set to be Directshow.

In order to play an encrypted mp4 (where I load the video, decrypt it to byte[]) I have to use Directshow.

On Tue, Jul 2, 2024 at 9:12 AM Chris-RH @.***> wrote:

Do you see the same issue in MediaFoundation and WinRT?

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1918#issuecomment-2203123321, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEUUIXLKEMJ6NO6SXL6RB6LZKKRLTAVCNFSM6AAAAABJ7ADVQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBTGEZDGMZSGE . You are receiving this because you authored the thread.Message ID: @.***>

eiyamomo avatar Jul 02 '24 13:07 eiyamomo

You need to try WinRT please

Chris-RH avatar Jul 12 '24 09:07 Chris-RH

You need to try WinRT please

Hi Chris,

I have tried WinRT, no it doesn't have this issue.

But it is not related to the issue I am reporting.

In order to use the OpenMediaFromBuffer, The VideoAPI has to be set to DirectShow.

But when VideoAPI is set to be DirectShow in the MediaPlayer, It will decrease the Resolution of the Video (if it is greater than 1080p)

It will be downsized to [email protected]

NOTE: I am not sure why you keep mentioning about WinRT. Have you check my last Comment?

eiyamomo avatar Jul 13 '24 02:07 eiyamomo

@eiyamomo

AVPro can stream videos from local http server. You can setup http server in c# using TcpListener. You need to implement PartialContent (206) http responses. Then open video using url (example: http://localhost:port/myfile.mp4). Server can read from various streams and decrypt on the fly (if possible) and write response.

This solution have some IO overhead and needs fine tuning of buffer sizes. But it is generic enough and have little to no restrictions.

I use it to restream videos obtained through SMB protocol (as c# network stream) on Android and iOS.

Last8Exile avatar Aug 12 '24 15:08 Last8Exile

@eiyamomo You are correct, OpenMediaFromBuffer is only an option when using the DirectShow API. DirectShow relies on external filters (installed to the PC). We have seen the best results using the LAV filters. What codec is the video? 1080p could just be a limitation of the codec (in combination with the filters being used).

Ste-RH avatar Sep 09 '24 16:09 Ste-RH

@eiyamomo What codec is the video?

Chris-RH avatar Sep 19 '24 14:09 Chris-RH

Hi Chris-RH

The codec of my video is H264-MPEG-4 AVC

I don't think it is the Codec. As it is not just the video file of my game. I also tried other video files which are 4k resolution.

They can all play at its corresponding Resolutions (1440p or 4k)

But when the file is being encrypted and trying to play by using OpenMediaFromBuffer (which requires directShow API)

*It will force the resolution to become *720x480.

On Thu, Sep 19, 2024 at 10:38 AM Chris-RH @.***> wrote:

@eiyamomo https://github.com/eiyamomo What codec is the video?

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1918#issuecomment-2361188378, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEUUIXJKPCI7VBZXLXN4NTDZXLOXFAVCNFSM6AAAAABJ7ADVQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRRGE4DQMZXHA . You are receiving this because you were mentioned.Message ID: @.***>

eiyamomo avatar Sep 19 '24 18:09 eiyamomo

Hi @eiyamomo,

I've had a look into this and a few notes:

  • 'OpenMediaFromBuffer()' does only work with DirectShow
  • By default the Microsoft H.264 decoder used by DirectShow only supprts up to 1920x1088 videos
  • From version 2 of AVPro we included some dynamic format change code for DirectShow that permits higher resolutions
  • The consquenece of the dynamic format change is initally the video is recgonised at a lower resolution (720x480) then later resized to the correct resolution

I've just tried loading our sample 'Cones-360Mono-4K30-H264.mp4' video via our 'Demo_MediaPlayer' scene (albeit in Video 3.0) using DirectShow and get the following log output:

[AVProVideo] Using playback path: DirectShow ([email protected])

Registering a native texture with width=720 while the actual texture has width=3840

[AVProVideo] Texture size changed: 3840 X 1920

The net result is the video plays at the correct resolution but only after the resize event has corrected it - does this mirror what you're seeing? (As this is expected behaviour to get around the quirk of the MS H.264 decoder limitation)

Cheers,

RichRH avatar Oct 01 '24 16:10 RichRH

Hi Richard,

Regarding the three line in console.

I am only seeing the first one.

Just to be clear. Is this only supported in AvPro video 2?

Since i am using last version. (avpro video 2 was released 2-3 months after i made the purchase, can't justify another purchase Right after i just purchased it.

AVProVideo] Using playback path: DirectShow @.**)

Registering a native texture with width=720 while the actual texture has width=3840

[AVProVideo] Texture size changed: 3840 X 192*0

On Tue, Oct 1, 2024 at 12:27 Richard Turnbull @.***> wrote:

Hi @eiyamomo https://github.com/eiyamomo,

I've had a look into this and a few notes:

  • 'OpenMediaFromBuffer()' does only work with DirectShow
  • By default the Microsoft H.264 decoder used by DirectShow only supprts up to 1920x1088 videos
  • From version 2 of AVPro we included some dynamic format change code for DirectShow that permits higher resolutions
  • The consquenece of the dynamic format change is initally the video is recgonised at a lower resolution (720x480) then later resized to the correct resolution

I've just tried loading our sample 'Cones-360Mono-4K30-H264.mp4' video via our 'Demo_MediaPlayer' scene (albeit in Video 3.0) using DirectShow and get the following log output:

[AVProVideo] Using playback path: DirectShow @.***)

Registering a native texture with width=720 while the actual texture has width=3840

[AVProVideo] Texture size changed: 3840 X 1920

The net result is the video plays at the correct resolution but only after the resize event has corrected it - does this mirror what you're seeing? (As this is expected behaviour to get around the quirk of the MS H.264 decoder limitation)

Cheers,

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1918#issuecomment-2386460689, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEUUIXJOTVWBKTKWHZVU4MLZZLENLAVCNFSM6AAAAABJ7ADVQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBWGQ3DANRYHE . You are receiving this because you were mentioned.Message ID: @.***>

eiyamomo avatar Oct 01 '24 16:10 eiyamomo

Hi @eiyamomo,

"Just to be clear. Is this only supported in AvPro video 2?" <- It should in any version from 2 onwards. I've just tried 2.9.3 Trial and get the following:

image

The logging is slightly different but the end result is the same dynamically resized video rendered in 4K.

Cheers,

RichRH avatar Oct 10 '24 11:10 RichRH