Disable the transcode with the same quality as the original tramsux

This commit is contained in:
Zoe Roux 2023-05-30 23:44:56 +09:00
parent 22d8ea8215
commit cec8400145
6 changed files with 28 additions and 14 deletions

View File

@ -34,7 +34,7 @@ import { useAtomValue, useSetAtom, useAtom } from "jotai";
import { useYoshiki } from "yoshiki"; import { useYoshiki } from "yoshiki";
import SubtitleOctopus from "libass-wasm"; import SubtitleOctopus from "libass-wasm";
import { playAtom, PlayMode, playModeAtom, subtitleAtom } from "./state"; import { playAtom, PlayMode, playModeAtom, subtitleAtom } from "./state";
import Hls from "hls.js"; import Hls, { Level } from "hls.js";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Menu } from "@kyoo/primitives"; import { Menu } from "@kyoo/primitives";
@ -58,6 +58,7 @@ const initHls = async () => {
xhr.setRequestHeader("X-CLIENT-ID", client_id); xhr.setRequestHeader("X-CLIENT-ID", client_id);
}, },
}); });
// hls.currentLevel = hls.startLevel;
}; };
const Video = forwardRef<{ seek: (value: number) => void }, VideoProps>(function _Video( const Video = forwardRef<{ seek: (value: number) => void }, VideoProps>(function _Video(
@ -262,6 +263,12 @@ export const QualitiesMenu = (props: ComponentProps<typeof Menu>) => {
return () => hls!.off(Hls.Events.LEVEL_SWITCHED, rerender); return () => hls!.off(Hls.Events.LEVEL_SWITCHED, rerender);
}); });
const levelName = (label: Level, auto?: boolean): string => {
const height = `${label.height}p`
if (auto) return height;
return label.uri.includes("original") ? `${t("player.transmux")} (${height})` : height;
}
return ( return (
<Menu {...props}> <Menu {...props}>
<Menu.Item <Menu.Item
@ -272,24 +279,24 @@ export const QualitiesMenu = (props: ComponentProps<typeof Menu>) => {
<Menu.Item <Menu.Item
label={ label={
hls != null && hls.autoLevelEnabled && hls.currentLevel >= 0 hls != null && hls.autoLevelEnabled && hls.currentLevel >= 0
? `${t("player.auto")} (${hls.levels[hls.currentLevel].height}p)` ? `${t("player.auto")} (${levelName(hls.levels[hls.currentLevel], true)})`
: t("player.auto") : t("player.auto")
} }
selected={hls?.autoLevelEnabled && mode === PlayMode.Hls} selected={hls?.autoLevelEnabled && mode === PlayMode.Hls}
onSelect={() => { onSelect={() => {
setPlayMode(PlayMode.Hls); setPlayMode(PlayMode.Hls);
if (hls) hls.nextLevel = -1; if (hls) hls.currentLevel = -1;
}} }}
/> />
{hls?.levels {hls?.levels
.map((x, i) => ( .map((x, i) => (
<Menu.Item <Menu.Item
key={i.toString()} key={i.toString()}
label={`${x.height}p`} label={levelName(x)}
selected={mode === PlayMode.Hls && hls!.currentLevel === i && !hls?.autoLevelEnabled} selected={mode === PlayMode.Hls && hls!.currentLevel === i && !hls?.autoLevelEnabled}
onSelect={() => { onSelect={() => {
setPlayMode(PlayMode.Hls); setPlayMode(PlayMode.Hls);
hls!.nextLevel = i; hls!.currentLevel = i;
}} }}
/> />
)) ))

View File

@ -49,6 +49,7 @@
"subtitle-none": "None", "subtitle-none": "None",
"fullscreen": "Fullscreen", "fullscreen": "Fullscreen",
"direct": "Pristine", "direct": "Pristine",
"transmux": "Original",
"auto": "Auto" "auto": "Auto"
}, },
"search": { "search": {

View File

@ -49,6 +49,7 @@
"subtitle-none": "Aucun", "subtitle-none": "Aucun",
"fullscreen": "Plein-écran", "fullscreen": "Plein-écran",
"direct": "Pristine", "direct": "Pristine",
"transmux": "Original",
"auto": "Auto" "auto": "Auto"
}, },
"search": { "search": {

View File

@ -28,10 +28,10 @@ async fn get_audio_transcoded(
.await .await
.map_err(|_| ApiError::NotFound)?; .map_err(|_| ApiError::NotFound)?;
transcoder transcoder.transcode_audio(path, audio).await.map_err(|e| {
.transcode_audio(path, audio) eprintln!("Error while transcoding audio: {}", e);
.await ApiError::InternalError
.map_err(|_| ApiError::InternalError) })
} }
/// Get audio chunk /// Get audio chunk

View File

@ -1,7 +1,7 @@
use crate::identify::identify; use crate::identify::identify;
use crate::paths::get_path; use crate::paths::get_path;
use crate::utils::Signalable;
use crate::transcode::*; use crate::transcode::*;
use crate::utils::Signalable;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::RwLock; use std::sync::RwLock;
@ -30,7 +30,9 @@ impl Transcoder {
master.push_str("#EXT-X-STREAM-INF:"); master.push_str("#EXT-X-STREAM-INF:");
master.push_str(format!("AVERAGE-BANDWIDTH={},", info.video.bitrate).as_str()); master.push_str(format!("AVERAGE-BANDWIDTH={},", info.video.bitrate).as_str());
// Approximate a bit more because we can't know the maximum bandwidth. // Approximate a bit more because we can't know the maximum bandwidth.
master.push_str(format!("BANDWIDTH={},", (info.video.bitrate as f32 * 1.2) as u32).as_str()); master.push_str(
format!("BANDWIDTH={},", (info.video.bitrate as f32 * 1.2) as u32).as_str(),
);
master.push_str( master.push_str(
format!("RESOLUTION={}x{},", info.video.width, info.video.height).as_str(), format!("RESOLUTION={}x{},", info.video.width, info.video.height).as_str(),
); );
@ -42,7 +44,9 @@ impl Transcoder {
} }
let aspect_ratio = info.video.width as f32 / info.video.height as f32; let aspect_ratio = info.video.width as f32 / info.video.height as f32;
for quality in Quality::iter().filter(|x| x.height() <= info.video.quality.height()) { // Do not include a quality with the same height as the original (simpler for automatic
// selection on the client side.)
for quality in Quality::iter().filter(|x| x.height() < info.video.quality.height()) {
// Doc: https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/creating_a_multivariant_playlist // Doc: https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/creating_a_multivariant_playlist
master.push_str("#EXT-X-STREAM-INF:"); master.push_str("#EXT-X-STREAM-INF:");
master.push_str(format!("AVERAGE-BANDWIDTH={},", quality.average_bitrate()).as_str()); master.push_str(format!("AVERAGE-BANDWIDTH={},", quality.average_bitrate()).as_str());

View File

@ -219,7 +219,7 @@ async fn start_transcode(
let mut cmd = Command::new("ffmpeg"); let mut cmd = Command::new("ffmpeg");
cmd.args(&["-progress", "pipe:1"]) cmd.args(&["-progress", "pipe:1"])
.arg("-nostats") .args(&["-nostats", "-hide_banner", "-loglevel", "warning"])
.args(&["-ss", start_time.to_string().as_str()]) .args(&["-ss", start_time.to_string().as_str()])
.args(&["-i", path.as_str()]) .args(&["-i", path.as_str()])
.args(&["-f", "hls"]) .args(&["-f", "hls"])
@ -250,7 +250,8 @@ async fn start_transcode(
let value = &value[1..]; let value = &value[1..];
// Can't use ms since ms and us are both set to us /shrug // Can't use ms since ms and us are both set to us /shrug
if key == "out_time_us" { if key == "out_time_us" {
let _ = tx.send(value.parse::<u32>().unwrap() / 1_000_000); // Sometimes, the value is invalid (or negative), default to 0 in those cases
let _ = tx.send(value.parse::<u32>().unwrap_or(0) / 1_000_000);
} }
} }
} }