Skip to content

Commit

Permalink
fix: check if codecs is defined
Browse files Browse the repository at this point in the history
fixes #545
  • Loading branch information
fent committed Dec 23, 2019
1 parent 10bddc6 commit cf34c45
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const videoEncodingRanks = [
const getBitrate = (format) => parseInt(format.bitrate) || 0;
const audioScore = (format) => {
const abitrate = format.audioBitrate || 0;
const aenc = audioEncodingRanks.findIndex(enc => format.codecs.includes(enc));
const aenc = audioEncodingRanks.findIndex(enc => format.codecs && format.codecs.includes(enc));
return abitrate + aenc / 10;
};

Expand All @@ -50,8 +50,8 @@ exports.sortFormats = (a, b) => {
let aascore = audioScore(a);
let bascore = audioScore(b);
if (aascore === bascore) {
const avenc = videoEncodingRanks.findIndex(enc => a.codecs.includes(enc));
const bvenc = videoEncodingRanks.findIndex(enc => b.codecs.includes(enc));
const avenc = videoEncodingRanks.findIndex(enc => a.codecs && a.codecs.includes(enc));
const bvenc = videoEncodingRanks.findIndex(enc => b.codecs && b.codecs.includes(enc));
return bvenc - avenc;
} else {
return bascore - aascore;
Expand Down

0 comments on commit cf34c45

Please sign in to comment.