Skip to content

Commit

Permalink
Fixed a couple of streaming bugs
Browse files Browse the repository at this point in the history
* If a video was cached at a non-listed quality it wasn't included in the streaming list.
* Videos without valid PTS data could not be streamed.
  • Loading branch information
SimplyBoo committed Mar 3, 2020
1 parent f6ab93a commit f2def52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/src/cache/import-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,15 @@ export class ImportUtils {
const mediaQuality =
media.metadata.width > media.metadata.height ? media.metadata.height : media.metadata.width;

const qualities = Config.get().transcoder.streamQualities.filter(quality => {
const streamQualities = Config.get().transcoder.streamQualities.filter(quality => {
return quality <= mediaQuality;
});

// Explicitly include qualities the medias cached at.
const qualities = Array.from(
new Set([...streamQualities, ...(media.metadata.qualityCache || [])]),
).sort();

let data = '#EXTM3U';
for (const quality of qualities.sort()) {
// Can't round because otherwise they come out as needing the same bandwidth.
Expand Down Expand Up @@ -431,7 +436,7 @@ export class ImportUtils {
throw new Error('Cannot stream non-video type');
}
const results = await Util.promisify(ChildProcess.exec)(
`ffprobe -loglevel error -skip_frame nokey -select_streams v:0 -show_entries frame=pkt_pts_time -of csv=print_section=0 "${media.absolutePath}"`,
`ffprobe -fflags +genpts -loglevel error -skip_frame nokey -select_streams v:0 -show_entries frame=pkt_pts_time -of csv=print_section=0 "${media.absolutePath}"`,
);
return results.stdout
.split('\n')
Expand Down
13 changes: 13 additions & 0 deletions server/src/database/mongodb/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ export class Updater {
await Updater.recreateMediaCollection(db, mediaSchema);
await Updater.saveUpdate(updatesCollection, '010_add-created-at');
}

// Media missing the PTS data completely broke streaming. This drops all those bad
// caches. Should only need to be done once rather than a task.
if (!(await Updater.hasRun(updatesCollection, '011_drop-invalid-segment-cache'))) {
console.log('Applying update 011_drop-invalid-segment-cache...');
await db
.collection('media')
.updateMany(
{ 'metadata.segments.standard.0.start': NaN },
{ $unset: { 'metadata.segments': '' } },
);
await Updater.saveUpdate(updatesCollection, '011_drop-invalid-segment-cache');
}
}

private static async recreateMediaCollection(db: Db, mediaSchema: object): Promise<void> {
Expand Down

0 comments on commit f2def52

Please sign in to comment.