我一直在尝试加载我从AVPro Movie Capture (Free Version)录制的视频。视频文件以GB为单位,因此我使用ffmpeg命令-y -i RawVideo.avi -qscale 7 FinalVideo.avi
对其进行了转换,并将其保存到StreamingAssets
。我得到了理想的结果。现在我想在视频播放器中播放转换后的视频文件进行预览。但问题是,当从URL播放视频时,音频非常不稳定。我在Windows播放器和VLC中播放它很好。问题仅出现在Unity的VideoPlayer
。
PreviewVideo类:
public class PreviewVideo : MonoBehaviour
{
public GameObject VideoSelection;
public GameObject RecordingCanvas;
public GameObject FacebookCanvas;
public GameObject Home;
public Sprite pauseImage;
public Sprite playImage;
public VideoPlayer videoPlayer;
public GameObject EmailCanvas;
// Use this for initialization
void Start ()
{
}
public void Referesh()
{
videoPlayer.gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load<Sprite> ("Thumbnails/" + StaticVariables.VideoToPlay);
videoPlayer.url = Application.streamingAssetsPath + "/FinalVideo.avi";
}
public void PlayVideo()
{
if (!videoPlayer.isPlaying) {
videoPlayer.Play ();
}
}
public void Back ()
{
this.gameObject.SetActive (false);
VideoSelection.SetActive (true);
}
public void HomeBtn ()
{
SceneManager.LoadScene (0);
}
public void SendEmailDialogue()
{
EmailCanvas.SetActive (true);
this.gameObject.SetActive (false);
}
public void FacebookShare()
{
FacebookCanvas.SetActive (true);
}
}
从RecordingCanvas类调用 Refresh()
:
public class RecordingCanvas : MonoBehaviour {
public GameObject VideoSelection;
public GameObject PreviewVideo;
public GameObject Home;
public GameObject canvas;
public RawImage rawImage;
public GameObject videoThumbnail;
float _seconds;
bool canStart = false;
public SpriteRenderer NumSprite;
public VideoPlayer videoPlayer;
WebCamTexture webcamTexture;
Process process;
void Start ()
{
Refresh ();
}
public void Refresh()
{
_seconds = 0;
NumSprite.gameObject.SetActive(true);
webcamTexture = new WebCamTexture (1280, 720);
webcamTexture.Stop ();
rawImage.texture = webcamTexture;
rawImage.material.mainTexture = webcamTexture;
webcamTexture.Play ();
videoPlayer.loopPointReached += VideoEndReached;
videoPlayer.gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load<Sprite> ("Thumbnails/" + StaticVariables.VideoToPlay);
videoThumbnail.GetComponent<SpriteRenderer> ().sprite = Resources.Load<Sprite> ("Thumbnails/" + StaticVariables.VideoToPlay);
videoPlayer.clip = Resources.Load<VideoClip> ("Videos/" + StaticVariables.VideoToPlay);
}
void Update()
{
_seconds += Time.deltaTime;
print ((int)_seconds);
if (_seconds < 1) {
NumSprite.sprite = Resources.Load<Sprite> ("Numbers/3");
}
else if(_seconds <2)
NumSprite.sprite = Resources.Load<Sprite>("Numbers/2");
else if(_seconds <3)
NumSprite.sprite = Resources.Load<Sprite>("Numbers/1");
if (_seconds >= 3 && _seconds <=4 ) {
canStart = true;
}
if (canStart) {
NumSprite.gameObject.SetActive(false);
canStart = false;
FindObjectOfType<CaptureGUI> ().StartCapture();
videoPlayer.Play ();
videoThumbnail.SetActive (false);
}
}
IEnumerator StartConversion()
{
yield return new WaitForSeconds (1.5f);
process = new Process();
if (File.Exists (Application.streamingAssetsPath + "/FinalVideo.avi"))
File.Delete(Application.streamingAssetsPath + "/FinalVideo.avi");
process.StartInfo.WorkingDirectory = Application.streamingAssetsPath;
process.StartInfo.FileName = Application.streamingAssetsPath + "/ffmpeg.exe";
process.StartInfo.Arguments = " -y -i " + StaticVariables.RawVideo + ".avi " + "-qscale 7 " + StaticVariables.FinalVideo + ".avi";
process.StartInfo.CreateNoWindow = false;
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(Process_Exited);
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit ();
canvas.SetActive (false);
PreviewVideo.SetActive (true);
FindObjectOfType<PreviewVideo> ().Referesh ();
File.Copy (Application.streamingAssetsPath + "/FinalVideo.avi", @"C:\xampp\htdocs\facebook\images\FinalVideo.avi", true);
this.gameObject.SetActive (false);
}
void Process_Exited(object sender, EventArgs e)
{
process.Dispose ();
}
void VideoEndReached(UnityEngine.Video.VideoPlayer vp)
{
videoPlayer.Stop ();
FindObjectOfType<CaptureGUI> ().StopCapture();
webcamTexture.Stop ();
canvas.SetActive (true);
StartCoroutine(StartConversion ());
}
}
我使用的是Unity版2017.1.1p4个人版。 Windows 10与高端PC。我正在为独立PC制作这个应用程序。
我被困在这里。无法继续前进。请帮我解决这个问题。