Native Video Editor返回奇怪的数据

时间:2017-10-12 19:35:29

标签: angular typescript ionic-framework ionic2 ionic3

我正在尝试使用视频编辑器获取有关视频的信息,但它确实有效。但它总是返回同一视频的不同数据,具体取决于视频是mp4还是mov。 我的视频是24秒,但它会返回

bitrate: 1061172
duration: 989.8
height: 1280
orientation: "landscape"
size: 1969937
width: 720

当它对视频进行转码时会返回不同的数据,但它不会在几秒钟内返回持续时间。

如何从此信息中获取视频长度?

从图库中选择视频

   openDeviceLibrary(type) 
    {
        var data = {};
        this.currentFile = this.imageFile = this.videoFile = null;

        switch (type) {
            case "video":
                data['mediaType'] = this.camera.MediaType.VIDEO;
                break;
            case "image":
                data['mediaType'] = this.camera.MediaType.PICTURE;
                break;
        }

        const options: CameraOptions = {
          quality: 100,
          destinationType: this.camera.DestinationType.FILE_URI,
          encodingType: this.camera.EncodingType.JPEG,
          mediaType: data['mediaType'],
          sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
        }

        this.camera.getPicture(options).then((data) => 
        {
            // data is either a base64 encoded string or a file URI
            // If it's base64:
            switch (type) 
            {
                case "video":
                    this.videoEditor.getVideoInfo({fileUri: data}).then((videoInfo) => {
                        console.log("videon info", videoInfo);
                        //it return duration in some weird unit where 1sec = 50 durations, .mov returns in seconds mp4 returns some weird unit
                        if(this.isVideoLong(data, videoInfo.duration)) {
                            this.presentAlert('custom', "Video's duration can't be more than "+this.videoDuration+" seconds");
                        } else {
                            this.callVideoEditor(data);
                        }
                    }).catch((error) => {
                        console.log(error); 
                    });
                    break;
                case "image":
                    //this.imageFile = 'data:image/jpeg;base64,' + data; //when testing base64
                    this.callCropper(data);
                    break;
            }
        }, (err) => {
            console.log(err);
        });
    }

转码视频

 private callVideoEditor(videoPath)
    {
        videoPath = this.returnFilePath(videoPath);
        this.currentFileName = "mimic_media_"+this.randomString()+".mp4";
        this.startSpinner = true; 
        this.videoEditor.transcodeVideo({
          fileUri: videoPath,
          outputFileName: this.currentFileName,
          outputFileType: this.videoEditor.OutputFileType.MPEG4,
          saveToLibrary: false
        })
        .then((fileUri: string) => {
            this.currentFile = this.videoFile = 'file://'+fileUri;
            this.createVideoThumb();
            console.log('video transcode success', this.videoFile);
        })
        .catch((error: any) => {
            console.log('video transcode error', error);
        });
    }

0 个答案:

没有答案