Skip to main content

Track Sorter

FFmpeg Builder: Track Sorter

This flow element will sort the audio and subtitles tracks given the parameters and update the order in FFmpeg Builder.

When FFmpeg Builder: Executor is run the tracks will be written in the order specified.

Deleted Tracks

Deleted tracks are always sorted after non-deleted tracks. This is the very first sort done.

Type

The type of tracks that should be reordered

Set Default

When this is enabled, the first track (audio or subtitle) will be set as the default track of its type.
Even if the the tracks do not get re-ordered, the first track will be now marked as default.

Sorters

SorterTypeSubtitleAudio
BitrateNumeric
ChannelsNumeric
CodecString
LanguageString
TitleString
tip

The Reversed variant of each sorter just reverses the order the sorter would usually sort the values in. For example, Bitrate Reversed with no sort value would sort the bitrates greatest to smallest.

No Value

If no value is entered for the sorter, then the sorting is based on the value

Numeric values (Bitrate, Channels) will be sorted by their respective values

Strings (Codec, Language) will be sorted alphabetically.

Value

If a sorter has a value set, then the sorting is done as matching vs not matching.

So if the track matches the sorter, it will be sorted before a track that does not match the sorter.

Regex Sorting

String values can be sorted via regular expressions.

For example Codec ^(ac3|dts)$ would sort any track whose codec is either ac3 or dts before any other tracks.

As mentioned earlier, sorting is done via matching/not matching so this does not sort ac3 then dts.

Math Operations

The following math operations can be used on Numeric values

OperationDescriptionExample
<Value is less than the preceding value<100
>Value is greater than the preceding value>128kbps
=Value equals the preceding value=10Mbps
<=Value is less or equal to the preceding value<=5.1
>=Value is greater than or equal to the preceding value>=5.1
!=Value equals the preceding value!=0

Unit Replacements

You can use these unit replacements when working with numeric values.

These are all case insensitive.

UnitReplacement
mbpsvalue * 1_000_000
kbpsvalue * 1_000
kbvalue * 1_000
mbvalue * 1_000_000
gbvalue * 1_000_000_000
tbvalue * 1_000_000_000_000
kibvalue * 1_024
mibvalue * 1_048_576
gibvalue * 1_073_741_824
tibvalue * 1_099_511_627_776

Languages

Languages are treated as a special case, and when sorting this field, it will look up the ISO 639-2 language code from the LanguageHelper and sort based on that code.

So you can enter English and it will match any track that equals en or eng. As all these will be looked up and become eng.

Original Language

There is a speical orig replacement that can be used to match the original language.

This requires the OriginalLanguage variable to be set earlier on in the flow to work.

See Movie Lookup, TV Show Lookup, TV Episode Lookup

Title

Titles are treated as a Contains check, unless using a regular expression. So you can enter commentary and that will match Directors Commentary etc.

tip

Use Title Reversed with commentary to move all commentary tracks to the end for easy removal.


Outputs

  1. Tracks have been reordered in FFmpeg Builder
  2. Tracks have NOT been reordered

Examples

FieldValueDescription
Channels>=5.1First sort the tracks so any that have channels greater or equal to 5.1 are first
LanguageorigNext move order by original langauge
Bitrate ReversedNo value set, so order the bitrate in descending order

So this example could produce, if the original language was German

ChannelsLanguageBitrateReason
5.1deu100000Greater than/equal 5.1, is German
7.1fre10000Greater than/equal 5.1
4.0ger100000is German
2.0jpn10000000Highest bitrate of remaining tracks
5.0eng100000