mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 17:36:18 -05:00
Transcode modal: allow a container-only remux
Keeping both streams is no longer refused: ffmpeg copies them into the chosen container with fast start. The container select starts at the file's own container, the hint explains what a remux does, and the button reads Remux when nothing is re-encoded. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
ca1dc82aa9
commit
749d5ac32b
5 changed files with 100 additions and 22 deletions
|
|
@ -148,6 +148,12 @@ export function JobProgress({jobId, onFinished}) {
|
|||
* The selects start at the user's preferred codecs from the Videos settings (the same preference
|
||||
* lists the downloader honors), so the common case is a glance and a click.
|
||||
*/
|
||||
/** The container of a video file, when it is one ffmpeg can write for us. */
|
||||
export function currentContainer(video) {
|
||||
const suffix = String(video?.video_path || '').split('.').pop().toLowerCase();
|
||||
return transcodeContainerOptions.some(i => i.value === suffix) ? suffix : null;
|
||||
}
|
||||
|
||||
export function TranscodeModal({open, onClose, fileGroupId, video, onComplete}) {
|
||||
const wrolModeEnabled = useWROLMode();
|
||||
const [videoCodec, setVideoCodec] = useState(TRANSCODE_COPY);
|
||||
|
|
@ -166,6 +172,8 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete})
|
|||
// Each opening starts over: a finished Job's progress must not linger on the next open.
|
||||
setJobId(null);
|
||||
setDefaultsLoaded(false);
|
||||
// Start from the file's own container so a codec-only change keeps it.
|
||||
setContainer(currentContainer(video) || 'mp4');
|
||||
let stale = false;
|
||||
const load = async () => {
|
||||
try {
|
||||
|
|
@ -185,7 +193,9 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete})
|
|||
};
|
||||
}, [open]);
|
||||
|
||||
const nothingToDo = videoCodec === TRANSCODE_COPY && audioCodec === TRANSCODE_COPY;
|
||||
// Both streams kept: a remux. Cheap, and it fixes the container (or adds fast start).
|
||||
const remuxOnly = videoCodec === TRANSCODE_COPY && audioCodec === TRANSCODE_COPY;
|
||||
const sameContainer = container === currentContainer(video);
|
||||
|
||||
const handleStart = async () => {
|
||||
setSubmitting(true);
|
||||
|
|
@ -246,8 +256,10 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete})
|
|||
onChange={value => setContainer(value || 'mp4')}
|
||||
allowDeselect={false}
|
||||
/>
|
||||
{nothingToDo && defaultsLoaded && <Text size='sm' c='var(--muted)'>
|
||||
Choose at least one codec to convert.
|
||||
{remuxOnly && defaultsLoaded && <Text size='sm' c='var(--muted)'>
|
||||
{sameContainer
|
||||
? 'Both streams are kept: the file is rewritten as-is with fast start (moves the index to the front for quicker playback start).'
|
||||
: `Both streams are kept: only the container changes to ${container} (a quick remux, no quality loss).`}
|
||||
</Text>}
|
||||
</>}
|
||||
{jobId && <JobProgress jobId={jobId} onFinished={handleFinished}/>}
|
||||
|
|
@ -260,9 +272,9 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete})
|
|||
icon='film'
|
||||
onClick={handleStart}
|
||||
loading={submitting}
|
||||
disabled={submitting || nothingToDo || !defaultsLoaded || !!wrolModeEnabled}
|
||||
disabled={submitting || !defaultsLoaded || !!wrolModeEnabled}
|
||||
>
|
||||
Transcode
|
||||
{remuxOnly ? 'Remux' : 'Transcode'}
|
||||
</Button>}
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import React from 'react';
|
||||
import {act, fireEvent, screen, waitFor} from '@testing-library/react';
|
||||
import {renderWithProviders} from '../test-utils';
|
||||
import {currentCodecs, EditVideoModal, JobProgress, preferredTarget, TranscodeModal, VideoEditMenu} from './VideoEditMenu';
|
||||
import {
|
||||
currentCodecs, currentContainer, EditVideoModal, JobProgress, preferredTarget, TranscodeModal, VideoEditMenu,
|
||||
} from './VideoEditMenu';
|
||||
import {TRANSCODE_COPY, transcodeAudioCodecOptions, transcodeVideoCodecOptions} from './Vars';
|
||||
|
||||
jest.mock('../api', () => ({
|
||||
|
|
@ -39,6 +41,13 @@ describe('helpers', () => {
|
|||
expect(currentCodecs(null)).toEqual({video: [], audio: []});
|
||||
});
|
||||
|
||||
test('currentContainer reads the file suffix, only for containers we can write', () => {
|
||||
expect(currentContainer({video_path: 'videos/a/movie.MP4'})).toBe('mp4');
|
||||
expect(currentContainer({video_path: 'videos/a/movie.mkv'})).toBe('mkv');
|
||||
expect(currentContainer({video_path: 'videos/a/movie.webm'})).toBeNull();
|
||||
expect(currentContainer(null)).toBeNull();
|
||||
});
|
||||
|
||||
test('preferredTarget picks the first preference ffmpeg can produce', () => {
|
||||
expect(preferredTarget(['vp9', 'h264'], transcodeVideoCodecOptions)).toBe('h264');
|
||||
expect(preferredTarget(['vp9', 'av1'], transcodeVideoCodecOptions)).toBe(TRANSCODE_COPY);
|
||||
|
|
@ -77,13 +86,30 @@ describe('TranscodeModal', () => {
|
|||
expect(await screen.findByText('pending')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('refuses to start when every stream is kept', async () => {
|
||||
test('keeping every stream is a remux into the chosen container', async () => {
|
||||
fetchVideoDownloadDefaults.mockResolvedValue({video_codecs: [], audio_codecs: []});
|
||||
// A webm cannot be kept (not a container we write), so the select starts at mp4: a change.
|
||||
renderWithProviders(<TranscodeModal open={true} onClose={jest.fn()} fileGroupId={7} video={video}/>);
|
||||
|
||||
await waitFor(() => expect(screen.getByText('Choose at least one codec to convert.')).toBeInTheDocument());
|
||||
expect(screen.getByRole('button', {name: /Transcode/})).toBeDisabled();
|
||||
expect(transcodeVideo).not.toHaveBeenCalled();
|
||||
await waitFor(() => expect(selectInput('Container')).toHaveValue('mp4'));
|
||||
expect(await screen.findByText(/only the container changes to mp4/)).toBeInTheDocument();
|
||||
|
||||
const button = screen.getByRole('button', {name: 'Remux'});
|
||||
expect(button).toBeEnabled();
|
||||
fireEvent.click(button);
|
||||
await waitFor(() => expect(transcodeVideo).toHaveBeenCalledWith(7, {
|
||||
video_codec: null, audio_codec: null, container: 'mp4',
|
||||
}));
|
||||
});
|
||||
|
||||
test('a remux into the same container is described as a fast-start rewrite', async () => {
|
||||
fetchVideoDownloadDefaults.mockResolvedValue({video_codecs: [], audio_codecs: []});
|
||||
const mkv = {...video, video_path: 'videos/movie.mkv'};
|
||||
renderWithProviders(<TranscodeModal open={true} onClose={jest.fn()} fileGroupId={7} video={mkv}/>);
|
||||
|
||||
await waitFor(() => expect(selectInput('Container')).toHaveValue('mkv'));
|
||||
expect(await screen.findByText(/rewritten as-is with fast start/)).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', {name: 'Remux'})).toBeEnabled();
|
||||
});
|
||||
|
||||
test('WROL Mode disables starting a transcode', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue