I’m trying to get info about video using Video Editor and it works. But it always returns different data of the same video depending if video is mp4 or mov.
My video is 24 sec long but it returns
bitrate: 1061172
duration: 989.8
height: 1280
orientation: "landscape"
size: 1969937
width: 720
When it transcodes video it returns different data, but it doesn’t return duration in seconds ever.
How should I get video length from this info?
Select video from gallery
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);
});
}
Transcode video
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);
});
}