Skip to content

Commit

Permalink
🧱 Include video in reencoded preview media
Browse files Browse the repository at this point in the history
  • Loading branch information
phlmn committed Dec 7, 2023
1 parent 868dc87 commit 8c05d9d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
17 changes: 10 additions & 7 deletions frontend/src/editor/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ export function PlayerBar({ documentId, editor }: { documentId: string; editor:
const [playbackRate, setPlaybackRate] = useLocalStorage('playbackRate', 1);

const sources = useMemo(() => {
const mappedFiles =
data?.media_files.map((media) => {
return {
src: media.url,
type: media.content_type,
};
}) || [];
// do not play the original file, it may be large
const relevantMediaFiles =
data?.media_files.filter((media) => !media.tags.includes('original')) || [];

const mappedFiles = relevantMediaFiles.map((media) => {
return {
src: media.url,
type: media.content_type,
};
});

return sortMediaFiles(mappedFiles);
}, [data?.media_files]);
Expand Down
5 changes: 4 additions & 1 deletion worker/transcribee_worker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ class Settings(BaseSettings):
"audio_bitrate": "128k",
"ac": "1",
},
"m4a": {
"video:mp4": {

This comment has been minimized.

Copy link
@pajowu

pajowu Dec 7, 2023

Member

Maybe we want both an audio only and a video version? And only use the (much larger) video version if the user enabled video previews

This comment has been minimized.

Copy link
@pajowu

pajowu Dec 7, 2023

Member

And possible also limit the resolution to smth like 360p?

This comment has been minimized.

Copy link
@phlmn

phlmn Dec 7, 2023

Author Member

Maybe we want both an audio only and a video version? And only use the (much larger) video version if the user enabled video previews

Yeah i guess maybe we want that in the future, but I think always showing the video is fine for now.

And possible also limit the resolution to smth like 360p?

Yes, we can do that. I think 360p is quite low though, at least if you detach the video via picture-in-picture

This comment has been minimized.

Copy link
@phlmn

phlmn Dec 9, 2023

Author Member

Added that btw :)

"format": "mp4",
"audio_bitrate": "128k",
"ac": "1",
"c:v": "libx264",
"crf": "26",
"preset": "faster",
},
}

Expand Down
36 changes: 23 additions & 13 deletions worker/transcribee_worker/reencode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ def get_duration(input_path: Path):
return float(ffmpeg.probe(input_path)["format"]["duration"])


def has_video(input_path: Path):
streams = ffmpeg.probe(input_path)["streams"]
for stream in streams:
if stream["codec_type"] == "video":
return True
return False


async def reencode(
input_path: Path,
output_path: Path,
output_params: dict[str, str],
progress_callback: ProgressCallbackType,
duration: float,
include_video: bool,
):
def work(_):
cmd: subprocess.Popen = (
ffmpeg.input(input_path)
.output(
filename=output_path,
map="0:a",
loglevel="quiet",
stats=None,
progress="-",
map_metadata="-1",
**output_params
)
.run_async(pipe_stdout=True)
)
pipeline = ffmpeg.input(input_path)
streams = [pipeline.audio]
if include_video and has_video(input_path):
streams.append(pipeline.video)

cmd: subprocess.Popen = ffmpeg.output(
*streams,
filename=output_path,
loglevel="quiet",
stats=None,
progress="-",
map_metadata="-1",
**output_params
).run_async(pipe_stdout=True)
assert cmd.stdout
raw_line: bytes
progress_dict = {}
Expand Down
3 changes: 2 additions & 1 deletion worker/transcribee_worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async def reencode(

n_profiles = len(settings.REENCODE_PROFILES)
for i, (profile, parameters) in enumerate(settings.REENCODE_PROFILES.items()):
output_path = self._get_tmpfile(f"reencode_{profile}")
output_path = self._get_tmpfile(f"reencode_{profile.replace(':', '_')}")

await reencode(
document_audio,
Expand All @@ -269,6 +269,7 @@ async def reencode(
**kwargs,
),
duration,
include_video=(profile.startswith("video:")),
)

tags = [f"profile:{profile}"] + [f"{k}:{v}" for k, v in parameters.items()]
Expand Down

0 comments on commit 8c05d9d

Please sign in to comment.