title: Convert videoplayer.texture as texture2D in Unity3
body: <p>I have this little code snippet</p>
  
  <pre><code>void Update() {
          if (Input.GetMouseButtonDown(0)) {
              if (videoPlayer.isPlaying) {
                  Texture2D currentFrame = videoPlayer.texture as Texture2D;
                  videoPlayer.Stop();
                  string destPath = Path.Combine (Application.streamingAssetsPath, "dnn/ClickedFrame.png");
                  Debug.Log("destPath :"+ destPath);
                  if (currentFrame != null)
                  {
                      File.WriteAllBytes(destPath, currentFrame.EncodeToPNG());
                  }
                  else {
                      Debug.Log("Current Frame is null");
                  }
              }  
          }       
      }
  </code></pre>
  
  <p>I want to get current video frame texture and want to save on the disk. But each time its saying current frame is null. I guess casting has a problem. How can i convert texture to texture2d and save on the disk?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I found a way to do this job </p>
  
  <pre><code>convertedTex2D = new Texture2D(videoPlayer.texture.width, videoPlayer.texture.height, TextureFormat.ARGB32, false);
              convertedTex2D.ReadPixels(new Rect(0, 0, videoPlayer.texture.width, videoPlayer.texture.height), 0, 0);
              convertedTex2D.Apply();
  </code></pre>
  
  <p>Its working fine and convertig texture into texture2d but sometime i am getting this error. Trying to resolve it.</p>
  
  <blockquote>
    <p>ReadPixels was called to read pixels from system frame buffer, while
    not inside drawing frame. UnityEngine.Texture2D:ReadPixels(Rect,
    Int32, Int32) VideoPlayerManager:Update() (at
    Assets/VideoPlayerManager.cs:40)</p>
    
    <p>[d3d11] attempting to ReadPixels outside of RenderTexture bounds!
    Reading (0, 0, 1920, 1088) from (656, 595)</p>
  </blockquote>
  
  <p>Some Information about the error 
  I checked that :</p>
  
  <ol>
  <li>texture width = 1920 and texture height 1088</li>
  <li>screen width = 803 and  screen height 557</li>
  </ol>
  
  <p>when i used scree width and height then this is working correctly but i don't want to use it.</p>