lisamelton / other_video_transcoding

Other tools to transcode videos.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recommendations for audio settings?

KirkMunro opened this issue Β· comments

Hi Lisa (and everyone else).

After recently replacing my old laptop, I'm finally transcoding my video collection (yay!), and I'm using Lisa's wonderful other-transcode utility to do it.

I'm very happy (thrilled, really) with the quality of the video that Im getting from my transcoded movies and shows. Before I go too far along though I wanted to ask for recommendations for audio. Essentially I want the following:

  1. Audio as good as the original.
  2. English and French audio tracks (if both are available).
  3. If possible, on older titles that only use a mono track, encode that in such a way that it plays in both headphones/speakers rather than just one.

My compression space concerns were more about the video than the audio, so I'm looking for recommendations on the arguments I should use.

The arguments I was using in my first pass at encoding movies and shows I had ripped are as follows:
--nvenc --hevc --add-audio eng --add-audio fra --crop auto --add-subtitle auto --eac3

Based on documentation I thought using --add-audio twice with both eng and fra would have grabbed both tracks, but that turns out not to be the case, so I'm missing something. Also I'm unsure about using --eac3...I don't think that's really what I want, if I want audio to be brought across using the best results possible to continue to enjoy stereo sounds in our integrated surround sound speakers if we're watching movies in our living room.

Oh, one more thing...is there a way for the output file to show forced subtitles in the language associated with the audio track that is playing? When I began experimenting with this years ago I believe I could only burn-in forced subtitles in a single language. Just wondering if that has changed any, such that forced subtitles show up in the selected language automatically in transcoded movies/shows.

Thank you in advance for your time, and thank you Lisa for this wonderful utility.

@KirkMunro Thank you for using my tools! And being so enthusiastic about them. 😊

The only way you're going to get audio as good as the original is simply to copy the original audio tracks. But then you're not transcoding and not saving any space.

If your input audio tracks are in a lossless format then using the --eac3 option is your best choice. Even if the originals aren't lossless, it's still an excellent choice. Trust me, unless you're small child or a tall dog, you're not going to be able to hear any difference.

As to why your French audio tracks aren't being added, I really need to see a media scan of one of your problematic movies to get a clue as to what is going on. I'll take a look if you attach a dump of that information here.

Regarding forced subtitles, yes you can only burn in one. It doesn't really make sense to burn in more than one.

And while you could technically modify the FFmpeg command generated by other-transcode to set the forced bit on more than one added subtitle, this would be problematic and confusing for most players.

I hope that helps. πŸ’–

@KirkMunro Thank you for using my tools! And being so enthusiastic about them. 😊

You're welcome. I'll always prefer CLI tools over a GUI (easier for building automated solutions and repeating steps), and your tools just make it so easy to do the transcoding, it's really a pleasure.

I hope that helps. πŸ’–

It does help. I ran a few more tests, and it's working now for me. I'm not sure why the French audio wasn't being added...chalk it up to human error, I guess, since I was running a script late at night and may have missed something. At any rate, here are the arguments I think I'm going to move forward with:

other-transcode --nvenc --hevc --crop auto --add-audio eng --add-audio fre --eac3 --copy-track-names --add-subtitle auto --burn-subtitle auto filename

That seems to do the job nicely for the most part.

The burn-in of forced subtitles using a single language vs being able to show them automatically without the burn-in is a small annoyance, so I'm still reading about it and experimenting. I'm using the Infuse app with my movies stored on my NAS at the moment, and from what I read here it seems like it's possible to have the forced subtitles show properly, as long as the subtitle tracks that are forced are marked accordingly in the mkv file. I'm not sure how to do that yet...hopefully there's an easy way so that I can just pass in the appropriate parameters and it'll just work. That, or make a few additional calls using CLI tools to identify the forced tracks and then use that information in the call to other-transcode if it won't do it automatically.

And while you could technically modify the FFmpeg command generated by other-transcode to set the forced bit on more than one added subtitle, this would be problematic and confusing for most players.

Hello again Lisa. 😊

I've been experimenting some more, and this is exactly what I decided to try. At first I experimented with other-transcode, using mediainfo to identify the subtitles that I put into my source mkv file, dynamically identifying the arguments that I wanted to use with other-transcode. Here's an example of what that looked like (using PowerShell on Windows):

Get-ChildItem Raw -Filter *.mkv | ForEach-Object {
	    $mediaInfo = mediainfo $_.FullName --output=JSON | ConvertFrom-Json
	    $forcedSubtitleTrackCount = $mediaInfo.media.track.where{$_.'@type' -eq 'Text'}.Count
	    $otherTranscodeArgumentString = '--nvenc --hevc --crop auto --add-audio eng --add-audio fre --eac3 --copy-track-names'
	    for ($i = 1; $i -le $forcedSubtitleTrackCount; $i++) {
	        $otherTranscodeArgumentString += " --add-subtitle ${i}=forced"
	    }
	    $otherTranscodeArguments = $otherTranscodeArgumentString -split ' '
	    Write-Host "Executing: other-transcode ${otherTranscodeArgumentString} '$($_.FullName)'" -ForegroundColor Cyan
	    other-transcode @otherTranscodeArguments $_.FullName
}

My thinking was that I could simply add multiple --add-subtitle N=forced arguments to the command to force each of the subtitle tracks that are actually forced subtitle tracks. I was using a rip of my Star Wars (1977) DVD as the source. Here is the ffmpeg command that was run as a result of my script:

ffmpeg -loglevel error -stats -i "D:\VideoLibrary\Raw\Star Wars Episode IV - A New Hope (1977).mkv" -vsync cfr -map 0:0 -filter:v crop=720:366:0:56 -c:v hevc_nvenc -pix_fmt:v p010le -b:v 1000k -maxrate:v 6000k -bufsize:v 6000k -color_primaries:v smpte170m -color_trc:v smpte170m -colorspace:v smpte170m -metadata:s:v title= -disposition:v default -map 0:1 -c:a:0 copy -disposition:a:0 default -map 0:2 -c:a:1 copy -disposition:a:1 0 -map 0:3 -c:s:0 copy -disposition:s:0 default+forced -map 0:4 -c:s:1 copy -disposition:s:1 0 -metadata:g title= -default_mode passthrough "Star Wars Episode IV - A New Hope (1977).mkv"

That didn't work though, because the ffmpeg command generated this way didn't set the second subtitle track (the French one) as forced (see the value of 0). Also, for some reason the first subtitle track was being marked as default, but that also seems undesirable/unnecessary. I then copied and modified that ffmpeg command, changing the subtitle disposition values for both track 1 (English forced subtitles) and track 2 (French forced subtitles). Here's the resulting command I used:

ffmpeg -loglevel error -stats -i "D:\VideoLibrary\Raw\Star Wars Episode IV - A New Hope (1977).mkv" -vsync cfr -map 0:0 -filter:v crop=720:366:0:56 -c:v hevc_nvenc -pix_fmt:v p010le -b:v 1000k -maxrate:v 6000k -bufsize:v 6000k -color_primaries:v smpte170m -color_trc:v smpte170m -colorspace:v smpte170m -metadata:s:v title= -disposition:v default -map 0:1 -c:a:0 copy -disposition:a:0 default -map 0:2 -c:a:1 copy -disposition:a:1 0 -map 0:3 -c:s:0 copy -disposition:s:0 forced -map 0:4 -c:s:1 copy -disposition:s:1 forced -metadata:g title= -default_mode passthrough "Star Wars Episode IV - A New Hope (1977).mkv"

This produced the desired results, with both the English and French subtitle tracks being properly identified as forced subtitles (which is what they are, even if they aren't properly flagged that way on the source DVD). With this file, when I play the video in VLC player or using the Infuse App on my phone, in both cases I get the English audio track playing by default with the English forced subtitle track. The only hiccup is if I switch to the French audio track the player doesn't automatically switch to the French forced subtitle track, but I can switch that manually and then I get the audio and forced subtitles like I would hear/see them if I were watching the movie using the DVD in my blu-ray player.

I'm going to reach out to the Infuse team about the forced subtitle track not automatically switching to match the audio track (that's how it should work, to mirror how it works in DVD/Blu-ray players), but I also thought I should ask you @lisamelton, is there an easier way for me to get the ffmpeg arguments that I want from other-transcode without having to use it to generate an ffmpeg command that I need to modify to get working properly?

One more thought on this. I'm curious why you think multiple forced subtitle tracks would be confusing for most players. Could you expand on that? As long there is only one forced subtitle track for a given language, that shouldn't confuse players at all. I'm surprised players show forced subtitle tracks as selectable, when instead they could simply auto-select them based on the selected audio track language whenever a user isn't specifically selecting another subtitle track...that seems to be how DVD and Blu-ray players work (you never see a subtitle track that only contains forced subtitles as one you can select).

I just looked at some other DVDs, seems the process I'm hoping to use is pretty straightforward:

  1. Rip contents using makemkv with desired French and English audio tracks and all French and English subtitle tracks.
  2. Use mediainfo to check subtitle track counts to identify which subtitle tracks are forced subtitle tracks (since they are not marked as such by makemkv). These are easy to identify -- they're the subtitle tracks with the lowest number of entries, usually an order of magnitude lower than non-forced subtitle tracks because they're only used for foreign/alien audio or for text displayed on screen in another language.
  3. Re-rip the DVD, with the same audio tracks, but only the forced subtitle tracks (after identifying them in the previous step).
  4. Use other-transcode to create the transcoded images, (hopefully) marking all subtitle tracks as forced, non-default (works for me because I'm stripping out subtitles that I don't care about).

For that last one though, I can't quite get what I'm after because of how other-transcode handles multiple --add-subtitle NUMBER=forced arguments. I'd prefer simply having a single --add-subtitle all=forced argument to add all subtitles with each of them marked as forced, and with none marked as default, while simply doing nothing if there are no subtitle tracks (easier to run a single command against a large number of mkv files to batch process them that way). Unless I use the --dry-run argument and pull out the ffmpeg command and then modify it before running it, that would do the trick.

Your other-transcode utility isn't open-source, is it? I mean, this repo seems just for docs, not for the actual code behind the utility. Otherwise I might be tempted to submit a PR (if you'd take it, of course).

commented

@KirkMunro, I'll leave the detailed answer for Lisa, but the source is a single file within the bin directory, or, right here: https://github.com/lisamelton/other_video_transcoding/blob/master/bin/other-transcode

@KirkMunro, I'll leave the detailed answer for Lisa, but the source is a single file within the bin directory, or, right here: https://github.com/lisamelton/other_video_transcoding/blob/master/bin/other-transcode

Thank you. It didn't occur to me to look in a bin folder for the source, but I could have checked to be sure.

@KirkMunro You can have multiple subtitle tracks in your input or your output that are considered "forced." However, only one subtitle should ever have its "forced" flag set. If you actually set that flag on multiple tracks, this will confuse the shit out of playback software about which track to select. The selected track might be the first in order or it might be random. Or it might even be none.

That's what I meant.

TL;DR: Do not set the "forced" flag on multiple tracks.

Hi @KirkMunro,

I've not tried to do what you are doing, but I think you want to use the Default flag rather than the Forced flag. As @lisamelton has correctly said, you should not use the Forced flag on more than one subtitle track, however you can set a Default track for every language. The only drawback is that the Default flag is only a hint for a player, but in my experience it is widely respected. (Caveat on that point: I use the Default flag for audio tracks normally, although I have used it for some foreign films with both an English audio track and a foreign audio track with English subtitles.)

For more details on the various flags you can use in an MKV, see: https://www.matroska.org/technical/notes.html
Unfortunately I can't link to the correct section, so you will need to scroll down to near the bottom of the page looking for the section titled "Track Flags".

For modifying track flags, I use mkvpropedit (https://mkvtoolnix.download/doc/mkvpropedit.html) which is part of the MKVToolNix package (https://mkvtoolnix.download). The command I use is the following where X is the track number. This does not re-encode the video, it just modifies the metadata, so you can quickly and easily experiment.
mkvpropedit input.mkv --edit track:sX --set flag-default=1

I hope this is helpful.

P.S. Hello everyone, I am still lurking around, but life's been a bit busy.

However, only one subtitle should ever have its "forced" flag set. If you actually set that flag on multiple tracks, this will confuse the shit out of playback software about which track to select. The selected track might be the first in order or it might be random. Or it might even be none.

That shouldn't be the case as long as you only have one forced track per language, right?

A forced track should only be auto-selected by playback software if it matches the language of the audio track that is currently playing. That's the design, so that people watching a movie in French see forced subtitles in French when there is foreign/alien dialogue, or when words are displayed on the screen that the movie creator takes the time to translate into the language of the audio track. So as long as there is only one forced track per language, there should be no confusion whatsoever by the playback software.

In fact, it seems from the (limited) testing that I have done that playback software doesn't handle forced subtitle tracks property at all, even if there is only one.

For example, I have the 2011 movie The Smurfs on DVD, converted into an mkv file. There are no forced subtitles in English, because when you watch the movie in English, all dialogue and text on screen is in English, so there is nothing to do. If you watch it with the French audio track though, forced subtitles are required for scenes where the cat Azrael talks (they didn't translate the cat's "language" into French), and they are also required when translatable words are displayed on the screen (a sign, a gift card). If I play that mkv file (that has no subtitle default track) in either the MPV player or the VLC player, both of those auto-select the first audio track (English) and both of those select the only forced subtitle track (French). That makes no sense, because nobody would realistically want those options. By default, they should play the English audio track with no subtitles, because a forced subtitle track should only be selected if the language for that track matches the audio track.

If you look at Star Wars (1977) as another example, that mkv file has multiple subtitle tracks that are designed to be forced: one per translated language (English, French, Spanish for my DVD). Without each of those subtitle tracks marked as forced, there is no way that any playback software can be programmed to be smart enough to (a) select the correct forced subtitle track when you change the audio track language, but only if you don't have a subtitle track chosen that you selected manually, and (b) be configured with an option to hide all forced subtitle tracks from the subtitle track selector, because they are not meant to be manually selected.

TL;DR: Do not set the "forced" flag on multiple tracks.

Without multiple forced subtitle tracks, how can any playback software possibly make the right decision when it comes to forced subtitles and the language of the currently selected audio track? Having only one means only that language matters, and everyone else is left to manual selection of their forced subtitle tracks, which they may have a hard time identifying if the only forced subtitle track is not in their language and if there are additional subtitle tracks matching their language. Having multiple, with a one-per-language restriction, at least allows playback software to make a smart decision and auto-select the right track when it is appropriate to do so.

I think the TL;DR should be as follows:

TL;DR: Do not set the "forced" flag on multiple (subtitle) tracks of the same language.

@KirkMunro No, that is not how it works in practice. Do not set the "forced" flag on multiple tracks, even if those tracks are in different languages. If playback software ever decides to choose a different subtitle track based on audio track language, then it will ignore all flags anyway.

@lisamelton I took a step back from this a bit after your last comment before deciding how to proceed. Having given it more thought, I still respectfully disagree with you on this one.

There are two reasons why I disagree:

  1. When multiple subtitle tracks are available, if a subtitle track that only contains forced subtitles isn't marked with the forced flag, then full stop, there is nothing the player can do to identify which subtitle track should be paired with which audio track, and there is nothing that the viewer can do to manually distinguish the forced subtitle track from non-forced subtitle tracks so that they can select it (aside from trial and error, but that's a terrible solution).
  2. When audio tracks are available in multiple languages in a movie that has either foreign (i.e. a language other than one of the languages represented in the audio tracks) or alien dialog or text with forced subtitles used to show the translation matching the language of the audio track that is playing, the mkv file simply must have multiple subtitle tracks, one for each of the audio tracks that is available.

Add those two things together, and I don't see any other way to allow for correct forced subtitle selection when more than one subtitle track consists solely of forced subtitles, but each in a different language.

Anyway, I've forked the other_video_transcoding project and modified it to have it working the way I need, setting up one or more forced subtitle tracks depending on the movie, which allows anyone watching these on any platform (PC, Apple TV, iPhone, etc.) to select the audio track and forced subtitle track that is needed to give them the same experience they get from watching a movie on DVD or Blu-ray.

Just as a point of interest, the MKV "spec" has some notes on this: https://www.matroska.org/technical/notes.html (Search for the "Track Flags" header)

A very brief summary of my understanding of these notes:

default flag: 1 per language.
forced flag: it's ambiguous how many tracks can have this flag

There's also some information on the mkvtoolnix wiki: https://gitlab.com/mbunkus/mkvtoolnix/-/wikis/Default-and-forced-flags-and-default-yes-no-in-the-GUI

That says that playback software must select forced tracks, regardless of any other preferences, which I understand to mean that only one track can have the forced flag. (how do you play/display 2 forced tracks at once?)

I also think the reasons you've stated for multiple forced tracks make a lot of sense, and if that lines up with how playback software actually behaves then that's ultimately all that matters. The real world takes priority over specifications every time :-)