Closed VXsz closed 2 years ago
Looks like you're running an out-of-date version of the script, the error you're getting was fixed previously and is preventing the stream-codec-combinations
option from doing what it's supposed to do, does updating and thus fixing that feature get your closer to what you're looking for?
I appreciate you putting together the example of what you're aiming for, but do you have any log files of an input file that would produce the results in the example? Being able to see how the input streams are mapped is helpful for figuring out a sorting algorithm as its a little unclear what input file would generate the output scenario you are showing
prefer-more-channels = False
default-more-channels = True
You may also get that AAC track to be default by changing default-more-channels
to False
Either way though I would say if you could update to fix the stream-codec-combination
feature and then post a sample of a file that has all these commentary tracks and then an example of what you want it to be I can see how that might be able to be achieved on a more consistent basis
setDefaultAudioStream
is the function that handles determining the default audio track and is a bit more complex than the function that handles sorting sortStreams
but you can review those to get some insight into how its currently handled
also ignoring it if it's not 5.1/7.1 (since I'm targeting 5.1/7.1 audio) would be a huge feature
So you mean a feature to ignore input tracks if they have less than a certain number of channels? That could potentially be doable but may need some checks/balances to ensure that you don't end up with no audio tracks
Looks like you're running an out-of-date version of the script, the error you're getting was fixed previously and is preventing the
stream-codec-combinations
option from doing what it's supposed to do, does updating and thus fixing that feature get your closer to what you're looking for?
I have updated the script (looks like when I tried to update a few days ago it didn't go through), the crashing issue got fixed, thank you
I appreciate you putting together the example of what you're aiming for, but do you have any log files of an input file that would produce the results in the example? Being able to see how the input streams are mapped is helpful for figuring out a sorting algorithm as its a little unclear what input file would generate the output scenario you are showing
Sure, this is the input/original mapping:
{
"format": "matroska,webm",
"format-fullname": "unknown",
"video": {
"index": 0,
"codec": "hevc",
"bitrate": 45092100,
"pix_fmt": "yuv420p10le",
"profile": "2",
"fps": 23.976023976023978,
"framedata": {
"pix_fmt": "yuv420p10le",
"color_space": "bt2020nc",
"color_primaries": "bt2020",
"color_transfer": "smpte2084",
"side_data_list": [
{
"side_data_type": "Mastering display metadata",
"red_x": "34000/50000",
"red_y": "16000/50000",
"green_x": "13250/50000",
"green_y": "34500/50000",
"blue_x": "7500/50000",
"blue_y": "3000/50000",
"white_point_x": "15635/50000",
"white_point_y": "16450/50000",
"min_luminance": "50/10000",
"max_luminance": "10000000/10000"
},
{
"side_data_type": "Content light level metadata",
"max_content": 0,
"max_average": 0
},
{
"side_data_type": "Dolby Vision RPU Data"
},
{
"side_data_type": "Dolby Vision Metadata",
"rpu_type": 2,
"rpu_format": 18,
"vdr_rpu_profile": 1,
"vdr_rpu_level": 0,
"chroma_resampling_explicit_filter_flag": 0,
"coef_data_type": 0,
"coef_log2_denom": 23,
"vdr_rpu_normalized_idc": 1,
"bl_video_full_range_flag": 0,
"bl_bit_depth": 10,
"el_bit_depth": 10,
"vdr_bit_depth": 12,
"spatial_resampling_filter_flag": 0,
"el_spatial_resampling_filter_flag": 0,
"disable_residual_flag": 1,
"vdr_rpu_id": 0,
"mapping_color_space": 0,
"mapping_chroma_format_idc": 0,
"nlq_method_idc": -1,
"nlq_method_idc_name": "none",
"num_x_partitions": 1,
"num_y_partitions": 1,
"components": [
{
"pivots": "0 1023",
"pieces": [
{
"mapping_idc": 0,
"mapping_idc_name": "polynomial",
"poly_order": 1,
"poly_coef": "0 8388608"
}
]
},
{
"pivots": "0 1023",
"pieces": [
{
"mapping_idc": 0,
"mapping_idc_name": "polynomial",
"poly_order": 1,
"poly_coef": "0 8388608"
}
]
},
{
"pivots": "0 1023",
"pieces": [
{
"mapping_idc": 0,
"mapping_idc_name": "polynomial",
"poly_order": 1,
"poly_coef": "0 8388608"
}
]
}
],
"dm_metadata_id": 0,
"scene_refresh_flag": 1,
"ycc_to_rgb_matrix": "9574/8192 0/8192 13802/8192 9574/8192 -1540/8192 -5348/8192 9574/8192 17610/8192 0/8192",
"ycc_to_rgb_offset": "16777216/268435456 134217728/268435456 134217728/268435456",
"rgb_to_lms_matrix": "7222/16384 8771/16384 390/16384 2654/16384 12430/16384 1300/16384 0/16384 422/16384 15962/16384",
"signal_eotf": 65535,
"signal_eotf_param0": 0,
"signal_eotf_param1": 0,
"signal_eotf_param2": 0,
"signal_bit_depth": 12,
"signal_color_space": 0,
"signal_chroma_format": 0,
"signal_full_range_flag": 1,
"source_min_pq": 62,
"source_max_pq": 3696,
"source_diagonal": 42
}
]
},
"dimensions": "3840x2160",
"level": 5.1,
"field_order": "unknown"
},
"audio": [
{
"index": 1,
"codec": "truehd",
"bitrate": 7508979,
"channels": 8,
"samplerate": 48000,
"language": "eng",
"disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions"
},
{
"index": 2,
"codec": "ac3",
"bitrate": 640000,
"channels": 6,
"samplerate": 48000,
"language": "eng",
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions"
}
],
"subtitle": [
{
"index": 3,
"codec": "hdmv_pgs_subtitle",
"bitrate": 36085,
"disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"language": "eng"
},
{
"index": 4,
"codec": "hdmv_pgs_subtitle",
"bitrate": 17658,
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"language": "zho"
},
{
"index": 5,
"codec": "hdmv_pgs_subtitle",
"bitrate": 29810,
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"language": "fra"
},
{
"index": 6,
"codec": "hdmv_pgs_subtitle",
"bitrate": 31362,
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"language": "deu"
},
{
"index": 7,
"codec": "hdmv_pgs_subtitle",
"bitrate": 22334,
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"language": "jpn"
},
{
"index": 8,
"codec": "hdmv_pgs_subtitle",
"bitrate": 29998,
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"language": "spa"
}
],
"attachment": []
}
And this is the output mapping with my settings:
"source": [
"Guardians.of.the.Galaxy.Vol.2.2017.HYBRiD.2160p.BluRay.REMUX.HEVC.DV.TrueHD.Atmos.7.1-Flights.mkv"
],
"format": "mp4",
"video": {
"codec": "copy",
"map": 0,
"bitrate": 42960.6948,
"crf": -1,
"maxrate": null,
"bufsize": null,
"level": 0.0,
"profile": null,
"preset": null,
"pix_fmt": null,
"field_order": "unknown",
"width": null,
"filter": null,
"params": null,
"framedata": null,
"title": "4K HDR",
"debug": "video.hdr"
},
"audio": [
{
"map": 2,
"codec": "copy",
"channels": 6,
"bitrate": 640.0,
"profile": null,
"quality": 5,
"filter": null,
"samplerate": null,
"sampleformat": "",
"language": "eng",
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"bsf": null,
"title": "AC-3",
"debug": "audio"
},
{
"map": 1,
"codec": "libfdk_aac",
"channels": 8,
"bitrate": 7508.979,
"profile": null,
"quality": 5,
"filter": null,
"samplerate": null,
"sampleformat": "",
"language": "eng",
"disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"bsf": null,
"title": "TrueHD Atmos 7.1",
"debug": "audio"
},
{
"map": 1,
"codec": "copy",
"channels": 8,
"language": "eng",
"disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
"title": "TrueHD Atmos 7.1",
"debug": "audio-copy-original"
}
],
"subtitle": [],
"attachment": []
}
2022-03-13 09:25:27 - resources.mediaprocessor - INFO - Preopts
2022-03-13 09:25:27 - resources.mediaprocessor - INFO - []
2022-03-13 09:25:27 - resources.mediaprocessor - INFO - Postopts
2022-03-13 09:25:27 - resources.mediaprocessor - INFO - [
"-threads",
"0",
"-metadata:g",
"encoding_tool=SMA",
"-strict",
"experimental",
"-tag:v",
"hvc1"
]
You may also get that AAC track to be default by changing
default-more-channels
toFalse
I changed it and it still has the same sorting, AC3 is the first (as you can see above from the mapping), and even through the libfdk_aac track is supposedly map: 1
the end result is actual getting mapped second in audio tracks (after AC3), like this:
AC3 AAC DTS-HD/TrueHD
Either way though I would say if you could update to fix the
stream-codec-combination
feature and then post a sample of a file that has all these commentary tracks and then an example of what you want it to be I can see how that might be able to be achieved on a more consistent basis
I currently don't have a media with commentary so I can't check or give an example, but I can insert some Saw movies since their remuxes seem to have tons of commentary tracks, and most are untagged (I think that's the reason) so the commentary tracks actually are the first ones (that play) so those who want to watch the media will actually have to switch to the last audio track to get the normal audio, but that's another issue that isn't my current focus (I can open an issue later if you'd like)
As for the setDefaultAudioStream
suggestion, I'll try reading the code but I'm not sure if I will be able to actually understand or get much from the code, but I'll give it a shot
So you mean a feature to ignore input tracks if they have less than a certain number of channels? That could potentially be doable but may need some checks/balances to ensure that you don't end up with no audio tracks
my idea was that if there's an AC3 **5.1** track, save our time and don't encode with libfdk_aac
and if there's an AC3 **2.0**, then we don't want stereo so let's encode with libfdk_aac
, basically don't encode if there's an easy-to-play audio track that's 5.1 and not stereo, I hope that idea got through, but there's could be a problem with stereo media (sitecoms and such which usually have 2.0 audio, even the lossless), in that case I think using the stream-codec-combinations
would help in this case to check if the source is actually stereo too or not (before doing what's above) so media with stereo tracks doesn't result in an empty audio, and if the video doesn't contain any lossless tracks then just passthrough the audio track(s) since encoding from lossy to lossy would result in just worse quality audio (and probably higher bit-rate than the original)
So the map is just telling FFMPEG what source stream your new stream is being created from, being map 1 just means it was stream 1 in the source file
If you include TrueHD on your codec list that should get you down to 2 output streams and prevent that extra AAC stream from getting created
I have a new approach that I've been working on for sorting to give a little more end user control, see this branch here
https://github.com/mdhiggins/sickbeard_mp4_automator/tree/newsort
This removes the following options
[Audio]
prefer-more-channels = True
default-more-channels = True
And adds the following options
[Audio]
sorting = language, channels.d, d.comment
default-sorting = channels.d, d.comment
[Subtitle]
sorting = language, d.comment, d.default.d, d.forced.d
This lets you prioritize your sorting however you want and opens up for it to be expanded to additional parameters
The valid options are
codec
language
channels
bitrate
d.*
The d.* prefix is the disposition flag so you can sort by dispositions like comment for commentary
You can also add a suffix of .a
or .d
for ascending or descending to change up the sort order
The default values should reflect how the sorting worked in the previous version
The codec sorter is a little tricky. It uses your list of codecs and will match the order in which they are specified, but ignores the first option on the list since that is typically your encoder and I didn't want people to be forced to have that always be sorted first
Using your own settings
codec = libfdk_aac, ac3, eac3, aac, opus, truehd
Should give you the order you want with a sort order of ac3, eac3, aac, opus, truehd
Let me know if that is getting you closer to what you're aiming for
Decided to get a little more aggressive with some of these changes on the newsort branch
Still removed the 2 options mentioned previously but now sectioned off the sorting options as follows
[Audio.Sorting]
sorting = language, channels.d, d.comment
default-sorting = channels.d, d.comment
codecs =
final-sort = False
[Subtitle.Sorting]
sorting = language, d.comment, d.default.d, d.forced.d
codecs =
The codecs option in the sorting sections lets you specify codec sorting without impacting your other codec lists, figured this would be less confusing and give more flexibility
The final-sort
option adds a final sort sweep to the audio options after they've been generated, this will potentially break up 'affiliated' audio tracks but give greater sorting control, so you can play around with toggling that as well
Edit:
So to achieve your goal of
AAC AC3 AC3 (Commentary 1) AC3 (Commentary 2) DTS-HD DTS-HD (Commentary 1) DTS-HD (Commentary 2)
you should be able to use
[Audio.Sorting]
sorting = language, d.comment, codec
default-sorting = codec
codecs = aac, ac3, dts, truehd
final-sort = True
Also increased the scenarios in which a duplicate stream can be purged using the stream-codec-combination technique
Added some additional sorting options
codec
language
channels
bitrate
d.*
map
smamap
map
will sort by the original map values of the source file
smamap
is similar but a more complex variant, will sort by the sorted input source streams while accounting for stream-codec-combinations
Both of these new sort options exist to keep streams that came from the same source stream together
Going to try to merge this branch this weekend if you have any time to test or provide feedback it would be much appreciated
Merged into master
Hey, sorry about the very late reply, but I just got busy with other stuff, sorry about that I'll try checking it out this weekend, thanks for everything (and the merge!)
No problem keep me posted
I did make some small tweaks today just to simplify some of the sorting code, going to summarize the changes so you don't get confused when you test compared to what I've written earlier in this post
removed the smamap
sort option in favor of a universal map
option
removed the final-sort
option entirely, sorting is always done as the final step instead of both before and after; if you want to sort based on the source stream just use the above map option
Going to close this issue out due to inactivity, should hopefully be fixed with the sorting overhaul
Feel free to reopen or continue comments if there's any questions or issues
Is your feature request related to a problem? Please describe. I have a few remuxes which have AC3 5.1 audio tracks within them (along the original lossless track), problem is that I'd like to use my libfdk_aac track to be the first (& default) instead of the AC3 one, the problem in this case happens when the AC3 track is 5.1, it prefers it over the new AAC track
Describe the solution you'd like A way to choose my new encoded audio to be the first & default instead of any other audio
Also, it would be great if there's a way to make the sorting like this:
AAC AC3 AC3 (Commentary 1) AC3 (Commentary 2) DTS-HD DTS-HD (Commentary 1) DTS-HD (Commentary 2)
Instead of this:
AAC AC3 DTS-HD AC3 (Commentary 1) DTS-HD (Commentary 1) AC3 (Commentary 2) DTS-HD (Commentary 2)
Through this feature isn't that necessary
Describe alternatives you've considered I have tried to make it stop encoding if the same audio exist by using the
stream-codec-combinations
setting in the config, but I maybe not understanding it correctly as it seems to be crashing (log & config for this below), it seems to still want to encode (even through the ac3 audio codec is in the approved list and is from the same lossless track), I'm guessing this setting is just so it reconginzes similair tracks, and any unapproved tracks would still be encoded, but I still don't get why it keeps crashingalso ignoring it if it's not 5.1/7.1 (since I'm targeting 5.1/7.1 audio) would be a huge feature
Current crash log:
Config: