From 8f8fda96c3cb5c90bab99e45a08ee2559ee0a53e Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 18 Oct 2026 06:53:11 +0000 Subject: [PATCH] feat(video): make a copy every browser plays of what phones and cameras record With video.playable_copies on (off by default), the transcribe step makes one copy of media browsers can't play (HEVC, AVI, MTS, AMR, Windows Media) as H.264 and AAC in MP4, at most video.playable_height lines high. The player gets the copy; /media, IIIF and feeds still give the file itself. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QFUNzy1QZy5HhKAyJxTAYJ --- README.md | 6 +- changelog.d/playable-copies.md | 5 + docs/requirements.md | 1 + docs/video.md | 18 +++ .../app/api/v1/routes/recordings.py | 15 +- fastapi_backend/app/domain/deletion.py | 3 +- fastapi_backend/app/domain/jobs.py | 14 ++ fastapi_backend/app/domain/playable.py | 130 ++++++++++++++++++ fastapi_backend/app/domain/settings.py | 3 + fastapi_backend/app/domain/store.py | 3 + fastapi_backend/tests/api/test_playable.py | 75 ++++++++++ nextjs-frontend/app/openapi-client/sdk.gen.ts | 4 +- .../components/settings/bodies.tsx | 3 + nextjs-frontend/components/settings/model.ts | 21 ++- nextjs-frontend/openapi.json | 2 +- 15 files changed, 293 insertions(+), 10 deletions(-) create mode 100644 changelog.d/playable-copies.md create mode 100644 fastapi_backend/app/domain/playable.py create mode 100644 fastapi_backend/tests/api/test_playable.py diff --git a/README.md b/README.md index 957e41754..bc37ef7c6 100644 --- a/README.md +++ b/README.md @@ -132,9 +132,11 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p the assistant, from private networks you allow in Settings too; and import videos and podcasts by their address (off by default). Say what a file or a page is as it comes in (a podcast, an interview, a scan), in Import, by API or to the assistant, and its content type's pipeline runs from the start. A file, page or video the namespace already - has links to the one there instead of being imported again. + has links to the one there instead of being imported again. Media browsers can't play, such as an AVI or HEVC from a + phone, can get a copy they can (off by default). ([Sensors](docs/sensors.md), [processing](docs/processing.md), [Apache Tika](docs/configuration.md#apache-tika), - [import webhooks](docs/api.md#import-webhooks); [checks](docs/requirements.md#bring-in-everything)) + [import webhooks](docs/api.md#import-webhooks), [playable copies](docs/video.md#playable-copies); + [checks](docs/requirements.md#bring-in-everything)) - **Clip from the browser.** The Lens web clipper for Chrome, Edge, Firefox and Safari turns a page, a selection or a part you pick into Markdown, lets you look it over, and sends it to a namespace. New releases reach installed copies through the browser's store or a self-hosted update file. In Chrome and Edge, its side panel is a chat with the diff --git a/changelog.d/playable-copies.md b/changelog.d/playable-copies.md new file mode 100644 index 000000000..49cb5776f --- /dev/null +++ b/changelog.d/playable-copies.md @@ -0,0 +1,5 @@ +- **Playable copies.** With Settings › Video › Playable copies on (off by default), media browsers can't play, such as + HEVC in a .mov, AVI, MTS or AMR, gets one copy they can (H.264 and AAC in MP4, at most 720 lines high by default), + made by the transcribe step. The player gets the copy; downloads still give the file itself + ([Playable copies](docs/video.md#playable-copies)). + diff --git a/docs/requirements.md b/docs/requirements.md index c64662ffc..d332bf8e8 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -154,6 +154,7 @@ request, to another check that proves the same thing; loosening a requirement or | Import webhooks for scanners and phone shortcuts | [test_import_hooks.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_import_hooks.py) `test_pushing_files_urls_and_text`, `test_owners_manage_hooks`; [import-hooks.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/import-hooks.test.tsx) | | Connect with Google; Dropbox, OneDrive and Google Drive sign in through rclone on the server | [test_gmail_source.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_gmail_source.py) `test_connecting_the_account_in_the_browser`; [test_drive_google.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_drive_google.py) `test_drive_connects_with_google_for_rclone`; [test_rclone_signin.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_rclone_signin.py) `test_drive_signs_in_through_rclone_with_no_google_app`, `test_a_browser_on_the_server_reaches_rclone_itself`, `test_onedrive_finds_the_accounts_own_drive` | | Uploads of audio, PDFs, Office files, photos, JSON and archives | [test_uploads.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_uploads.py) `test_uploading_audio_in_chunks`, `test_json_uploaded_is_read_as_records`; [test_documents.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_documents.py) `test_a_pdf_becomes_a_document_with_its_pages_and_text`, `test_scans_and_images_are_read_by_ocr`; [test_conversion.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_conversion.py) `test_office_and_text_files_become_documents`; [test_anytopdf.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_anytopdf.py) `test_an_uploaded_zip_keeps_its_files`; [test_archives.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_archives.py) `test_reading_an_archive`; [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `import-file`, `import-paste` | +| Media browsers can't play (an AVI, HEVC, AMR) gets a copy they can, for the player only, off by default; files they play get none | [test_playable.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_playable.py) `test_a_camera_clip_gets_a_copy_every_browser_plays`, `test_a_file_browsers_play_gets_no_copy` | | An uploaded video, end to end | No check yet ([#486](https://github.com/adeelahmad/lense/issues/486)) | | Apache Tika (opt-in) reads documents nothing else here can | [test_tika.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_tika.py) `test_off_by_default_nothing_changes`, `test_what_nothing_here_can_convert_tika_reads_as_text` | | Web pages captured one at a time, from a link list or a bookmarks file, by API or by asking; private networks only when allowed | [test_webcapture.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_webcapture.py) `test_a_web_page_becomes_a_document`, `test_an_admin_allows_a_private_network_in_settings`, `test_private_addresses_are_refused`; [test_web_links.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_web_links.py) `test_one_or_several_addresses_as_a_list`, `test_a_bookmarks_file_becomes_pages_to_capture`; [test_setup_assistant.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_setup_assistant.py) `test_the_assistant_captures_web_pages` | diff --git a/docs/video.md b/docs/video.md index bee8a6d66..c60e92519 100644 --- a/docs/video.md +++ b/docs/video.md @@ -48,6 +48,24 @@ videos, documents and images. A published video recording becomes a IIIF Video on a Canvas with its width, height and duration. It gets a thumbnail, a "Text on screen" annotation layer targeting `#xywh=…&t=…`, and its shots as a Range. +## Playable copies + +Phones and cameras write files many browsers can't play: HEVC video in a .mov, AVI, MPEG transport streams, AMR voice +memos, Windows Media. Turn on Settings › Video › Playable copies (`video.playable_copies`, off by default, since +transcoding a long video keeps a small machine busy for a while) and the transcribe step makes one copy of such a +recording's media, even when its transcript came with it: + +- video becomes H.264 at most `video.playable_height` lines high (360, 480, 720 or 1080; 720 by default) with AAC sound + in MP4, and sound alone becomes AAC in MP4; +- the copy is kept in `data_dir/playable/`, encrypted like the rest when the namespace is, and deleted with the + recording; +- the player (`/api/v1/recordings//audio`) gets the copy, while `/api/v1/recordings//media`, IIIF and feeds + still give the file itself; +- a file browsers already play (H.264, VP8, VP9 or AV1 video; AAC, MP3, Opus, Vorbis, FLAC or PCM sound, in MP4, + WebM, Ogg, MP3, FLAC or WAV) gets no copy. + +Recordings transcribed before the setting was on get their copy when their transcribe step runs again. + ## The video recording page Video recordings open in their own layout. diff --git a/fastapi_backend/app/api/v1/routes/recordings.py b/fastapi_backend/app/api/v1/routes/recordings.py index d462df078..b8178f7e1 100644 --- a/fastapi_backend/app/api/v1/routes/recordings.py +++ b/fastapi_backend/app/api/v1/routes/recordings.py @@ -30,6 +30,7 @@ library, moving, nsfw, + playable, render, sources, store, @@ -587,10 +588,14 @@ def _media_type(rec: dict[str, Any], path: Any) -> str | None: return None -def serve_audio(db: DB, cfg: dict[str, Any], rec: dict[str, Any], rid: int, request: Request) -> Response: - """The recording's audio (or video) file with byte ranges: local, from a local source, from the cache, or streamed.""" +def serve_audio(db: DB, cfg: dict[str, Any], rec: dict[str, Any], rid: int, request: Request, player: bool = False) -> Response: + """The recording's audio (or video) file with byte ranges: local, from a local source, from the cache, or streamed. + For the player, its playable copy when one was made (playable.py); the file itself otherwise.""" if rec.get("source") != "audio": raise HTTPException(404, "no audio for this recording") + copy = playable.copy_of(db, cfg, rid) if player else None + if copy: + return file_response(copy[0], request, copy[1], db, cfg) path = render.has_audio(db, cfg, rid) if path: return file_response(path, request, _media_type(rec, path), db, cfg) @@ -615,8 +620,10 @@ def serve_audio(db: DB, cfg: dict[str, Any], rec: dict[str, Any], rid: int, requ @router.get("/{rid}/audio", response_class=Response, responses={200: {"content": {"audio/*": {}}}, 206: {"description": "a byte range"}}) def get_audio(rid: int, request: Request, acl: Acl, db: Db, cfg: Cfg, s: str = "") -> Response: - """The audio, with byte ranges. Accepts a bearer token, a share link (``?s=``) or a signed link.""" - return serve_audio(db, cfg, acl.recording(rid, share=s), rid, request) + """The audio (or video) for the player, with byte ranges: a copy every browser plays when Settings › Video made one, + else the file itself (``/media`` always gives the file). Accepts a bearer token, a share link (``?s=``) or a signed + link.""" + return serve_audio(db, cfg, acl.recording(rid, share=s), rid, request, player=True) @router.get("/{rid}/wordcloud.svg", response_class=Response, responses={200: {"content": {"image/svg+xml": {}}}}) diff --git a/fastapi_backend/app/domain/deletion.py b/fastapi_backend/app/domain/deletion.py index 9c4ae5ded..c82f5d087 100644 --- a/fastapi_backend/app/domain/deletion.py +++ b/fastapi_backend/app/domain/deletion.py @@ -20,7 +20,7 @@ import pathlib import shutil -from . import access as acc, files as filemod, keyring, notebook, render, store, video +from . import access as acc, files as filemod, keyring, notebook, playable, render, store, video R = store.R log = logging.getLogger("lens") @@ -99,6 +99,7 @@ def _files(db, cfg, rec, rid, ns): ] if rec.get("converted_from") and rec.get("path") and keyring.owned(cfg, rec["path"]): out.append(pathlib.Path(rec["path"])) + out += playable.copies(cfg, rid) exports = data / "exports" / (ns or "_") mine = { (o.get("value") or {}).get("file") diff --git a/fastapi_backend/app/domain/jobs.py b/fastapi_backend/app/domain/jobs.py index bc3ac026c..ecc086667 100644 --- a/fastapi_backend/app/domain/jobs.py +++ b/fastapi_backend/app/domain/jobs.py @@ -73,6 +73,20 @@ def _read(db, cfg, rid, say, spec=None): def _transcribe(db, cfg, rid, say, spec=None): + """A recording transcribed (or a document read), then, with Settings › Video › Playable copies on, a copy of its + media every browser plays made (playable.py), even when the transcript came with the media.""" + from . import playable + + try: + done = _transcribe_media(db, cfg, rid, say, spec) + except Skip: + playable.ensure(db, cfg, rid, say) + raise + playable.ensure(db, cfg, rid, say) + return done + + +def _transcribe_media(db, cfg, rid, say, spec=None): rec = db.one("SELECT source, engine, status, envelope, web, path, space, title FROM $r", r=R("recording", rid)) or {} if rec.get("source") in ("document", "image"): # a run queued before documents had a step of their own return _read(db, cfg, rid, say, spec) diff --git a/fastapi_backend/app/domain/playable.py b/fastapi_backend/app/domain/playable.py new file mode 100644 index 000000000..2d7976656 --- /dev/null +++ b/fastapi_backend/app/domain/playable.py @@ -0,0 +1,130 @@ +"""Playable copies: media that every browser plays, made of what phones and cameras record (`video.playable_copies`). + +Phones and camcorders write files many browsers can't play: HEVC video in a .mov, AVI, MPEG transport streams (.mts), +AMR voice memos, Windows Media. With the setting on (off by default: transcoding a long video takes a small machine a +while), the transcribe step makes a copy of such a recording's media once, next to its other files +(data_dir/playable/.mp4 or .m4a, encrypted like the rest when the namespace is): H.264 video at most +`playable_height` lines high and AAC sound in MP4, or AAC alone for sound. The player then gets the copy; the original +stays as it was, and downloads of the original still give it. A file a browser already plays (H.264, VP8, VP9 or AV1 +video; AAC, MP3, Opus, Vorbis, FLAC or PCM sound, in MP4, WebM, Ogg, MP3, FLAC or WAV) gets no copy. +""" + +from __future__ import annotations + +import json +import pathlib +import subprocess + +from . import ingest, keyring, store + +R = store.R +VIDEO = {"h264", "vp8", "vp9", "av1"} +AUDIO = {"aac", "mp3", "opus", "vorbis", "flac", "pcm_s16le", "pcm_s24le", "pcm_s32le", "pcm_u8", "pcm_f32le"} +CONTAINERS = {".mp4", ".m4a", ".m4v", ".webm", ".mp3", ".ogg", ".oga", ".opus", ".wav", ".flac", ".aac"} +SECONDS = 6 * 3600 # the longest ffmpeg may take over one copy + + +def on(cfg): + return bool((cfg.get("video") or {}).get("playable_copies")) + + +def codecs(path): + """(the video codec or None, the audio codec or None) of a media file, by ffprobe; (None, None) when unreadable.""" + try: + out = subprocess.run( + ["ffprobe", "-v", "error", "-format_whitelist", ingest.MEDIA_DEMUXERS, "-show_streams", "-of", "json", str(path)], + capture_output=True, + text=True, + timeout=120, + ) + streams = json.loads(out.stdout or "{}").get("streams") or [] + except (OSError, ValueError, subprocess.TimeoutExpired): + return None, None + video = next( + (s.get("codec_name") for s in streams if s.get("codec_type") == "video" and not (s.get("disposition") or {}).get("attached_pic")), + None, + ) + audio = next((s.get("codec_name") for s in streams if s.get("codec_type") == "audio"), None) + return video, audio + + +def needed(path, name=None): + """Whether a browser may fail to play this file: its kind of file, or a codec in it, isn't one they all play.""" + video, audio = codecs(path) + if video is None and audio is None: + return False # nothing ffprobe can read: nothing ffmpeg could copy either + suffix = pathlib.PurePosixPath(str(name or path)).suffix.lower() + return suffix not in CONTAINERS or (video is not None and video not in VIDEO) or (audio is not None and audio not in AUDIO) + + +def path_of(cfg, rid, video=True): + return pathlib.Path(cfg["data_dir"]) / "playable" / f"{int(rid)}{'.mp4' if video else '.m4a'}" + + +def copies(cfg, rid): + """Both places a recording's copy may be, for deletion.py.""" + return [path_of(cfg, rid, True), path_of(cfg, rid, False)] + + +def copy_of(db, cfg, rid): + """The playable copy of a recording's media, when one was made and is still there: (its path, its media type), else + None.""" + rec = db.one("SELECT playable FROM $r", r=R("recording", rid)) or {} + got = rec.get("playable") or {} + if not got.get("type"): + return None + p = path_of(cfg, rid, video=got["type"].startswith("video/")) + return (str(p), got["type"]) if p.is_file() else None + + +def ensure(db, cfg, rid, say=print, force=False): + """Make a recording's playable copy when the setting is on and its media needs one; the copy's path, else None.""" + if not on(cfg): + return None + have = copy_of(db, cfg, rid) + if have and not force: + return have[0] + rec = db.one("SELECT path, remote, space, source FROM $r", r=R("recording", rid)) or {} + if rec.get("source") != "audio": + return None + name = (rec.get("remote") or {}).get("path") or rec.get("path") + src = ingest.audio_path(db, cfg, rec) + if not needed(src, name): + return None + video, _ = codecs(src) + dest = path_of(cfg, rid, video=video is not None) + dest.parent.mkdir(parents=True, exist_ok=True) + tmp = dest.with_name("." + dest.name) + height = int((cfg.get("video") or {}).get("playable_height") or 720) + args = ["-c:v", "libx264", "-preset", "veryfast", "-crf", "23", "-pix_fmt", "yuv420p", "-vf", f"scale=-2:'min({height},ih)'"] + argv = ["ffmpeg", "-nostdin", "-y", "-v", "error", "-format_whitelist", ingest.MEDIA_DEMUXERS, "-i", str(src), "-map", "0:a:0?"] + argv += (["-map", "0:v:0", *args] if video else ["-vn"]) + [ + "-c:a", + "aac", + "-b:a", + "128k", + "-movflags", + "+faststart", + "-f", + "mp4", + str(tmp), + ] + try: + done = subprocess.run(argv, capture_output=True, text=True, timeout=SECONDS) + if done.returncode != 0 or not tmp.is_file(): + say(f" couldn't make a playable copy: {((done.stderr or '').strip().splitlines() or ['ffmpeg failed'])[-1]}") + return None + tmp.replace(dest) + except (OSError, subprocess.TimeoutExpired) as e: # no ffmpeg, or a copy taking too long: the original still plays + say(f" couldn't make a playable copy: {e}") + return None + finally: + tmp.unlink(missing_ok=True) + keyring.protect(db, cfg, rec.get("space"), dest) + db.q( + "UPDATE $r SET playable = $p", + r=R("recording", rid), + p={"type": "video/mp4" if video else "audio/mp4", "made_at": store.now()}, + ) + say(f" made a copy every browser plays ({'video' if video else 'sound'}, {dest.stat().st_size // 1024} KB)") + return str(dest) diff --git a/fastapi_backend/app/domain/settings.py b/fastapi_backend/app/domain/settings.py index 9214f69de..54326afd5 100644 --- a/fastapi_backend/app/domain/settings.py +++ b/fastapi_backend/app/domain/settings.py @@ -109,6 +109,8 @@ # the model files (yolox_model, ultralytics_model) are startup settings only, like yunet_model "object_engine", "object_min_score", + "playable_copies", + "playable_height", ), "nsfw": None, "enhance": None, @@ -178,6 +180,7 @@ ("video", "face_engine"): {"opencv", "insightface", "anytopdf", "none"}, ("video", "object_engine"): {"yolox", "ultralytics", "anytopdf", "off"}, ("enhance", "image_engine"): {"classic", "realesrgan"}, + ("video", "playable_height"): {360, 480, 720, 1080}, ("decisions", "engine"): {"auto", "jev", "laya", "llm", "off"}, ("voice", "input"): {"auto", "server", "browser"}, ("voice", "stt"): {"same", "sensevoice", "whisper", "mlx-whisper", "openai", "elevenlabs", "assemblyai", "deepgram"}, diff --git a/fastapi_backend/app/domain/store.py b/fastapi_backend/app/domain/store.py index 2af94a4d7..f0a0f34df 100644 --- a/fastapi_backend/app/domain/store.py +++ b/fastapi_backend/app/domain/store.py @@ -541,6 +541,9 @@ def labels(): "yolox_model": None, "ultralytics_model": None, "object_min_score": 0.4, + # playable copies (playable.py): off by default, since transcoding a long video takes a small machine a while + "playable_copies": False, + "playable_height": 720, }, # NSFW classification (nsfw.py, docs/nsfw.md): off until an admin turns it on here, or an owner for their namespace # (which can also choose its own threshold and display). A local model (ViT, Apache-2.0, fetched on first use) scores diff --git a/fastapi_backend/tests/api/test_playable.py b/fastapi_backend/tests/api/test_playable.py new file mode 100644 index 000000000..51a4b1a58 --- /dev/null +++ b/fastapi_backend/tests/api/test_playable.py @@ -0,0 +1,75 @@ +"""Playable copies (playable.py): media browsers can't play gets a copy they can, made once, with the setting on.""" + +from __future__ import annotations + +import pathlib +import subprocess + +import pytest + +from app.domain import deletion, ingest, jobs, playable +from tests.helpers import login, make_user, quiet +from tests.video_helpers import make_video, needs_ffmpeg + +pytestmark = needs_ffmpeg + + +def make_avi(path): + """Two seconds of MPEG-4 Part 2 video and PCM sound in an AVI, the kind of file an old camera writes.""" + cmd = ["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-f", "lavfi", "-i", "testsrc=s=320x240:d=2:r=10"] + cmd += ["-f", "lavfi", "-i", "sine=frequency=440:duration=2", "-c:v", "mpeg4", "-c:a", "pcm_s16le", "-shortest", str(path)] + subprocess.run(cmd, capture_output=True, check=True) + + +def _import(db, cfg, folder, media): + tr = folder / f"{media.stem}.txt" + tr.write_text("[00:00] Mara: Here is the camera's clip.") + return ingest.import_transcript(db, cfg, "pods", tr, audio=media, log=quiet) + + +def test_a_camera_clip_gets_a_copy_every_browser_plays(request, cfg, db, folder): + avi = folder / "camera.avi" + make_avi(avi) + rid = _import(db, cfg, folder, avi) + said: list[str] = [] + assert playable.codecs(avi) == ("mpeg4", "pcm_s16le") + assert playable.needed(avi) + with pytest.raises(jobs.Skip): # the transcript came with it + jobs._transcribe(db, cfg, rid, said.append) + assert playable.copy_of(db, cfg, rid) is None # off by default: nothing made + assert not playable.path_of(cfg, rid).exists() + + cfg["video"]["playable_copies"], cfg["video"]["playable_height"] = True, 180 + with pytest.raises(jobs.Skip): + jobs._transcribe(db, cfg, rid, said.append) + path, ctype = playable.copy_of(db, cfg, rid) + assert ctype == "video/mp4" and any("every browser plays" in s for s in said) + assert playable.codecs(path) == ("h264", "aac") + height = subprocess.run( + ["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=height", "-of", "csv=p=0", path], + capture_output=True, + text=True, + ).stdout.strip() + assert height == "180" # no taller than the setting + assert playable.ensure(db, cfg, rid, said.append) == path # made once, not again + + make_user(db, "root@x.io", "root password 1", admin=True) + c = request.getfixturevalue("client") + h = login(c, "root@x.io", "root password 1") + r = c.get(f"/api/v1/recordings/{rid}/audio", headers={**h, "Range": "bytes=0-99"}) + assert (r.status_code, r.headers["content-type"], r.content[4:8]) == (206, "video/mp4", b"ftyp") # the player's copy + r = c.get(f"/api/v1/recordings/{rid}/media", headers={**h, "Range": "bytes=0-3"}) + assert (r.status_code, r.content) == (206, b"RIFF") # the file itself, to save + + deletion.delete(db, cfg, rid) + assert not pathlib.Path(path).exists() + + +def test_a_file_browsers_play_gets_no_copy(cfg, db, folder): + mp4 = folder / "phone.mp4" + make_video(mp4) + rid = _import(db, cfg, folder, mp4) + cfg["video"]["playable_copies"] = True + assert not playable.needed(mp4) + assert playable.ensure(db, cfg, rid, quiet) is None + assert playable.copy_of(db, cfg, rid) is None diff --git a/nextjs-frontend/app/openapi-client/sdk.gen.ts b/nextjs-frontend/app/openapi-client/sdk.gen.ts index c8d27df03..4b2d68c8a 100644 --- a/nextjs-frontend/app/openapi-client/sdk.gen.ts +++ b/nextjs-frontend/app/openapi-client/sdk.gen.ts @@ -6009,7 +6009,9 @@ export class Resources { /** * Get Audio * - * The audio, with byte ranges. Accepts a bearer token, a share link (``?s=``) or a signed link. + * The audio (or video) for the player, with byte ranges: a copy every browser plays when Settings › Video made one, + * else the file itself (``/media`` always gives the file). Accepts a bearer token, a share link (``?s=``) or a signed + * link. */ public static getAudio( options: Options, diff --git a/nextjs-frontend/components/settings/bodies.tsx b/nextjs-frontend/components/settings/bodies.tsx index f265c39da..7cb11c707 100644 --- a/nextjs-frontend/components/settings/bodies.tsx +++ b/nextjs-frontend/components/settings/bodies.tsx @@ -313,6 +313,9 @@ export function SectionBody({ ctx }: { ctx: BodyCtx }) { + Playback + + {v("video.playable_copies") ? : null} Text on screen diff --git a/nextjs-frontend/components/settings/model.ts b/nextjs-frontend/components/settings/model.ts index e3eec78b7..771c533a7 100644 --- a/nextjs-frontend/components/settings/model.ts +++ b/nextjs-frontend/components/settings/model.ts @@ -2541,6 +2541,25 @@ export const FIELDS: FieldSpec[] = [ label: "Review threshold", ...pct(), }, + { + section: "video", + key: "playable_copies", + label: "Playable copies", + kind: "switch", + hint: "Make a copy every browser plays of HEVC, AVI, MTS, AMR and other media phones and cameras record", + }, + { + section: "video", + key: "playable_height", + label: "Playable copy size", + kind: "select", + options: [ + { value: "360", label: "360 lines" }, + { value: "480", label: "480 lines" }, + { value: "720", label: "720 lines" }, + { value: "1080", label: "1080 lines" }, + ], + }, { section: "video", key: "publish_faces", @@ -4107,7 +4126,7 @@ export function parse(f: FieldSpec, ui: unknown): Parsed { return { value: n }; } case "select": - if (f.key === "frame_width") return { value: Number(ui) }; + if (f.key === "frame_width" || f.key === "playable_height") return { value: Number(ui) }; if (f.section === "nfs" && f.key === "account") return { value: ui === "" || ui == null ? null : Number(ui) }; if ((f.section === "files" || f.section === "backups") && f.key === "connection") return { value: ui === "" || ui == null ? null : Number(ui) }; diff --git a/nextjs-frontend/openapi.json b/nextjs-frontend/openapi.json index 4b41cd86a..8c9cf445c 100644 --- a/nextjs-frontend/openapi.json +++ b/nextjs-frontend/openapi.json @@ -10988,7 +10988,7 @@ "resources" ], "summary": "Get Audio", - "description": "The audio, with byte ranges. Accepts a bearer token, a share link (``?s=``) or a signed link.", + "description": "The audio (or video) for the player, with byte ranges: a copy every browser plays when Settings \u203a Video made one,\nelse the file itself (``/media`` always gives the file). Accepts a bearer token, a share link (``?s=``) or a signed\nlink.", "operationId": "get_audio", "parameters": [ {