aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2021-08-27 19:39:44 -0700
committerJesús <heckyel@hyperbola.info>2021-08-29 21:56:00 -0500
commit81e61f9893f369f2a4d8d2950aed9ee8b756e320 (patch)
tree1c20ad158804525e429c0ded021b874818782309 /youtube
parentae68c84a26055e1fea481e26063ed99cf832ede9 (diff)
downloadyt-local-81e61f9893f369f2a4d8d2950aed9ee8b756e320.tar.lz
yt-local-81e61f9893f369f2a4d8d2950aed9ee8b756e320.tar.xz
yt-local-81e61f9893f369f2a4d8d2950aed9ee8b756e320.zip
av-merge: buffer same duration of audio and video
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube')
-rw-r--r--youtube/static/js/av-merge.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/youtube/static/js/av-merge.js b/youtube/static/js/av-merge.js
index 583ce1f..0754feb 100644
--- a/youtube/static/js/av-merge.js
+++ b/youtube/static/js/av-merge.js
@@ -29,6 +29,10 @@ function avInitialize(...args){
function AVMerge(video, srcPair, startTime){
this.videoSource = srcPair[0];
this.audioSource = srcPair[1];
+ if (this.videoSource.bitrate && this.audioSource.bitrate)
+ this.avRatio = this.audioSource.bitrate/this.videoSource.bitrate;
+ else
+ this.avRatio = 1/10;
this.videoStream = null;
this.audioStream = null;
this.seeking = false;
@@ -64,8 +68,10 @@ AVMerge.prototype.sourceOpen = function(_) {
if (this.opened)
return;
this.opened = true;
- this.videoStream = new Stream(this, this.videoSource, this.startTime);
- this.audioStream = new Stream(this, this.audioSource, this.startTime);
+ this.videoStream = new Stream(this, this.videoSource, this.startTime,
+ this.avRatio);
+ this.audioStream = new Stream(this, this.audioSource, this.startTime,
+ this.avRatio);
this.videoStream.setup();
this.audioStream.setup();
@@ -116,7 +122,7 @@ AVMerge.prototype.videoEndOfStream = function() {
this.videoEndOfStreamCalled = true;
}
-function Stream(avMerge, source, startTime) {
+function Stream(avMerge, source, startTime, avRatio) {
this.avMerge = avMerge;
this.video = avMerge.video;
this.url = source['url'];
@@ -124,7 +130,7 @@ function Stream(avMerge, source, startTime) {
this.mimeCodec = source['mime_codec']
this.streamType = source['acodec'] ? 'audio' : 'video';
if (this.streamType == 'audio') {
- this.bufferTarget = 5*10**6; // 5 megabytes
+ this.bufferTarget = avRatio*50*10**6;
} else {
this.bufferTarget = 50*10**6; // 50 megabytes
}