RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
238 stars 29 forks source link

When the video is at begening, call GetCurrentTime not return 0 #1371

Closed LimitlessMan36 closed 1 year ago

LimitlessMan36 commented 2 years ago

Problem description:

When the video is at begening, call GetCurrentTime not return 0. (Even after SEEK(0)) Is it a bug? Do you have an option to abstart this offset?

Device (which devices are you having the issue with - model, OS version number):

Windows 10 Profesional 10.0.19044

Media (tell us about your videos - number of videos, resolution, codec, frame-rate, example URLs):

I tried with one video you provide : BigBuckBunny-360p30-H264.mp4 Begin at 0,1333332 secondes GetDuration = 7,97 (If I remove 0,1333, it's exactly the size I got in my video editor) My video Editor is Wondershare Filmora

System Information:

AVPro Video: v2.6.6 (plugin v2.6.3f1-core) Target Platform: Standalone Unity: v2021.3.7f1 WindowsEditor OS: Desktop - System Product Name (System manufacturer) - Windows 10 (10.0.19044) 64bit - French CPU: AMD Ryzen 5 2600X Six-Core Processor - 12 threads - 16317KB GPU: NVIDIA GeForce GTX 1660 SUPER - NVIDIA - Direct3D 11.0 [level 11.1] - 5991KB - 16384

Chris-RH commented 1 year ago

Hi @LimitlessMan36,

  1. GetDuration will return the longest track duration, which in the case is the audio track.
  1. GetCurrentTime should return 0 at the start. I have read about weird time offsets occurring in Windows 10 and some information points to B-frames. If you're using FFMPEG and H.264 codec then you can encode without B-frames via: -x264-params "bframes=0" Could you re-encode and see what you get?

  2. What do you get with GetTextureTimeStamp?

LimitlessMan36 commented 1 year ago

Thank you Chris-RH, Realy clear answer.

Unfortunately, I can,t re-encode my video because I create a kind of video player.

I don't find GetTextureTimeStamp anywhere in your asset. Where can I find it?

LimitlessMan36 commented 1 year ago

Ok, I find it.

With GetCurrentTime : 0.0667332 With GetTextureTimeStamp : 667332

So same result.

While waiting for a more elegant solution (if we find a solution) I created a temporary class. I save the initial offset and I send the corected value :

public class MyVideoPlayer { private double _timeOffset;

private MediaPlayer _mediaPlayer;
private bool getBeginingOffset = false;

public MyVideoPlayer(MediaPlayer mediaPlayer)
{
    _mediaPlayer = mediaPlayer;
    _mediaPlayer.Events.AddListener(HandleEvent_MediaPlayer);        
}

public void Init()
{
    getBeginingOffset = true;
    _mediaPlayer.Control.Seek(0);
}

public double GetCurrentTime()
{
    return _mediaPlayer.Control.GetCurrentTime() - TimeOffset;
}

public double GetDuration()
{
    return _mediaPlayer.Info.GetDuration() - TimeOffset;
}

public void Seek(double time)
{
    _mediaPlayer.Control.Seek(time + TimeOffset);
}

void HandleEvent_MediaPlayer(MediaPlayer aVPro, MediaPlayerEvent.EventType eventType, ErrorCode code)
{
    // When Init MyVideoPlayer, a Seek(0) command has send to get the begining offset
    if (getBeginingOffset && eventType == MediaPlayerEvent.EventType.FinishedSeeking)
    {
        _timeOffset = _mediaPlayer.Control.GetCurrentTime();
        getBeginingOffset = false;
    }
}

}

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.