cordova-plugin-video-editor
cordova-plugin-video-editor copied to clipboard
iOS transcoded video duration discrepancy
After transcoding a 60 second video, I see that the duration info for the transcoded output file is much greater than 60 seconds:
"sourceInfo": {
"duration": 60.43333,
"size": 3896249,
"bitrate": 397518.2,
"width": 426,
"height": 240,
"orientation": "landscape"
},
"transcodeInfo": {
"duration": 4439.4,
"size": 3915382,
"bitrate": 401060.5,
"width": 426,
"height": 240,
"orientation": "landscape"
},
Of course, the actual video file isn't 4439 seconds long - it's still the original 60 seconds. The issue only appears when using getVideoInfo().
Here's another example:
"sourceInfo": {
"duration": 1.541667,
"size": 12136752,
"bitrate": 3001813,
"width": 1280,
"height": 720,
"orientation": "landscape"
},
"transcodeInfo": {
"duration": 2263.8,
"size": 2053258,
"bitrate": 417212.9,
"width": 426,
"height": 239,
"orientation": "landscape"
},
There doesn't seem to be an obvious pattern involving the source duration vs transcode duration from the files I've tested with so far.
I see this duration issue to occur every time I transcode a video on iOS. Any thoughts as to what might be going wrong?
I am seeing the same thing. Sometimes the duration is correct, but certain videos (and I can't tell what it is about the video) causes the duration to be wrong. From what I see, it seems to be doubling the time and multiplying it by 10.. Example. I have a video that is 12 seconds long and the duration is showing 233.6 (The video is probably 11.68 seconds). (11.68 * 2 = 23.36 * 10 = 233.6);
Just ran into this issue. Sharing with you my workaround.....
var factor = 73.3964; //god knows why
console.log("duration", transcodeInfo.duration, (transcodeInfo.duration/factor));
I think this issue is being caused by having a video that is trimmed down from a longer video. For instance, I had a 2.5 minute (150 seconds) video from which I trimmed and exported a 3 second clip via QuickTime. QuickTime correctly reports the trimmed clip as 3 seconds, but running it through VideoEditor.getVideoInfo reports the duration of the original source file: ~150 seconds.
This seems to only happen on the iOS platform. See VideoEditor.m for reference, and the timeRange attribute of AVAssetTrack.
I'm seeing the same thing as @jashick and getting a wildly different factor than @btafel . This is definitely an issue as I'm trying to limit videos by duration.
The factor also varies on a video to video basis... so I don't think I can just implement a factor.
Hi everybody. The same is happening to me! Is there any known fix or solution? Thanks
I'm also having the same problem. Someone has found a workaround?
@facconi @momomatteo This isn't super clean, but using straight JS gives an accurate duration:
@ViewChild('video') videoChild
video: any = {}
loadVideoMetadata() {
// Load metadata for video and get duration with JS
let videoEl = this.videoChild.nativeElement
videoEl.src = this.video.filepath
videoEl.load()
// Time-out loading the metadata after 3 seconds in case anything went wrong
let timeout = setTimeout(() => {
clearInterval(interval)
this.showError("Could not load the selected video.")
}, 3000)
// Keep checking until metadata has loaded
let interval = setInterval(() => {
if (videoEl.readyState > 0) {
clearTimeout(timeout)
clearInterval(interval)
this.video.duration = videoEl.duration
}
}, 200)
}
Did anyone ever find a resolution to this? Getting the same weird behavior on ios
god knows why 🤣 , but dividing by 73.3964 seems to work. thanks @btafel