import React, { memo, Fragment } from 'react'; import { FaVideo, FaVideoSlash, FaFileExport, FaFileImport, FaVolumeUp, FaVolumeMute, FaBan, FaTrashAlt, FaInfoCircle } from 'react-icons/fa'; import { GoFileBinary } from 'react-icons/go'; import { MdSubtitles } from 'react-icons/md'; import Swal from 'sweetalert2'; import withReactContent from 'sweetalert2-react-content'; const ReactSwal = withReactContent(Swal); const { formatDuration } = require('./util'); const { getStreamFps } = require('./ffmpeg'); const Stream = memo(({ stream, onToggle, copyStream }) => { const bitrate = parseInt(stream.bit_rate, 10); const duration = parseInt(stream.duration, 10); let Icon; if (stream.codec_type === 'audio') { Icon = copyStream ? FaVolumeUp : FaVolumeMute; } else if (stream.codec_type === 'video') { Icon = copyStream ? FaVideo : FaVideoSlash; } else if (stream.codec_type === 'subtitle') { Icon = copyStream ? MdSubtitles : FaBan; } else { Icon = copyStream ? GoFileBinary : FaBan; } const streamFps = getStreamFps(stream); function onInfoClick(s) { ReactSwal.fire({ showCloseButton: true, icon: 'info', title: 'Stream info', html:
{JSON.stringify(s, null, 2)}
, }); } const onClick = () => onToggle && onToggle(stream.index); return ( {stream.index} {stream.codec_type} {stream.codec_tag !== '0x0000' && stream.codec_tag_string} {stream.codec_name} {!Number.isNaN(duration) && `${formatDuration({ seconds: duration })}`} {stream.nb_frames} {!Number.isNaN(bitrate) && `${(bitrate / 1e6).toFixed(1)}MBit/s`} {stream.width && stream.height && `${stream.width}x${stream.height}`} {stream.channels && `${stream.channels}c`} {stream.channel_layout} {streamFps && `${streamFps.toFixed(1)}fps`} onInfoClick(stream)} size={26} /> ); }); const StreamsSelector = memo(({ mainFilePath, streams: existingStreams, isCopyingStreamId, toggleCopyStreamId, setCopyStreamIdsForPath, onExtractAllStreamsPress, externalFiles, setExternalFiles, showAddStreamSourceDialog, }) => { if (!existingStreams) return null; async function removeFile(path) { setCopyStreamIdsForPath(path, () => ({})); setExternalFiles((old) => { const { [path]: val, ...rest } = old; return rest; }); } return (

Click to select which tracks to keep when exporting:

{existingStreams.map((stream) => ( toggleCopyStreamId(mainFilePath, streamId)} /> ))} {Object.entries(externalFiles).map(([path, { streams }]) => ( {streams.map((stream) => ( toggleCopyStreamId(path, streamId)} /> ))} ))}
Keep? Type Tag Codec Duration Frames Bitrate Data
removeFile(path)} /> {path}
Include tracks from other file
{Object.keys(externalFiles).length === 0 && (
Export each track as individual files
)}
); }); export default StreamsSelector;