-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixing #171 Be able to select encoder before selecting video
- Loading branch information
1 parent
9b429b3
commit d59111e
Showing
12 changed files
with
105 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import List, Dict | ||
import logging | ||
|
||
from fastflix.models.video import SubtitleTrack, AudioTrack | ||
from fastflix.encoders.common.audio import lossless | ||
|
||
|
||
logger = logging.getLogger("fastflix") | ||
|
||
|
||
def get_stream_pos(streams) -> Dict: | ||
return {x.index: i for i, x in enumerate(streams, start=1)} | ||
|
||
|
||
def build_audio(audio_tracks: List[AudioTrack], audio_streams): | ||
command_list = [] | ||
copies = [] | ||
track_ids = set() | ||
stream_ids = get_stream_pos(audio_streams) | ||
|
||
for track in sorted(audio_tracks, key=lambda x: x.outdex): | ||
if track.index in track_ids: | ||
logger.warning("NVEncC does not support copy and duplicate of audio tracks!") | ||
track_ids.add(track.index) | ||
audio_id = stream_ids[track.index] | ||
if track.language: | ||
command_list.append(f"--audio-metadata {audio_id}?language={track.language}") | ||
if not track.conversion_codec or track.conversion_codec == "none": | ||
copies.append(str(audio_id)) | ||
elif track.conversion_codec: | ||
downmix = f"--audio-stream {audio_id}?:{track.downmix}" if track.downmix else "" | ||
bitrate = "" | ||
if track.conversion_codec not in lossless: | ||
bitrate = f"--audio-bitrate {audio_id}?{track.conversion_bitrate.rstrip('k')} " | ||
command_list.append( | ||
f"{downmix} --audio-codec {audio_id}?{track.conversion_codec} {bitrate} " | ||
f"--audio-metadata {audio_id}?clear" | ||
) | ||
|
||
if track.title: | ||
command_list.append( | ||
f'--audio-metadata {audio_id}?title="{track.title}" ' | ||
f'--audio-metadata {audio_id}?handler="{track.title}" ' | ||
) | ||
|
||
return f" --audio-copy {','.join(copies)} {' '.join(command_list)}" if copies else f" {' '.join(command_list)}" | ||
|
||
|
||
def build_subtitle(subtitle_tracks: List[SubtitleTrack], subtitle_streams) -> str: | ||
command_list = [] | ||
copies = [] | ||
stream_ids = get_stream_pos(subtitle_streams) | ||
|
||
for track in sorted(subtitle_tracks, key=lambda x: x.outdex): | ||
sub_id = stream_ids[track.index] | ||
if track.burn_in: | ||
command_list.append(f"--vpp-subburn track={sub_id}") | ||
else: | ||
copies.append(str(sub_id)) | ||
if track.disposition: | ||
command_list.append(f"--sub-disposition {sub_id}?{track.disposition}") | ||
command_list.append(f"--sub-metadata {sub_id}?language='{track.language}'") | ||
|
||
return f" --sub-copy {','.join(copies)} {' '.join(command_list)}" if copies else f" {' '.join(command_list)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters