FastFlix
FastFlix copied to clipboard
libopus for channels >2 needs channel layout with -af
You get an error in FastFlix if you try to encode 5.1/7.1 audio to opus. If you try to encode audio with libopus for more then 2 channels, you have to add the parameter for channel layouts in ffmpeg like this:
for 5.1
-mapping_family 1 -af aformat=channel_layouts=5.1
for 7.1
-mapping_family 1 -af aformat=channel_layouts=7.1
so a complete 5.1 audio line would look like this:
-c:a libopus -b:a 256000 -mapping_family 1 -af aformat=channel_layouts=5.1
Currently Fastflix is not presenting this to ffmpeg, so an encode fails.
Thanks for the detailed info on the error and how to fix it!
It's probably a good idea long term to specify channel layout explicitly anyway, so that may be the true "fix".
I think mapping family can be ignored, as it should be auto-detected.
For time being, can add a custom audio filter for that track via the "custom ffmpeg options" field.
i.e. if it is output track 2
(the one on the right side of the :
)
-filter:2 aformat=channel_layouts=<layout>
layouts can be found https://ffmpeg.org/ffmpeg-utils.html#channel-layout-syntax
I just tested it on the command line and yes, the mapping param can be ignored as it seems to autodetect it just fine (0 = stereo/mono, 1 = channel >2). And fixed my initial entry, of course you have to put 7.1 in for 7.1 channels, silly copy&paste error.
and thanks for the work around! Was not aware that you can put the format in there! Is there also a way to adjust the bitrate of audio somewhere besides your fixed values? the opus team itself recommands only 450k bitrate for 7.1, so the current options are either not enough or to much. :-) I know, luxury problems. :-)
Sorry I missed the follow up comment! Currently it's not modifiable, however I will switch from using a 32x multiplier to a 16x one for bitrate selection ranges, as I have had multiple people request more options for that. Long term I want to make it customizable like CRF / Bitrate for video.
Also btw, which is a easier solution: If audio gets encoded, all you need to specify is:
-af aformat=channel_layouts="7.1|5.1|stereo|mono"
It will correctly choose the channel layout combined with -ac
, as the |
acts as "or" statement.
It simplifies the code, idk. if you want to change the current implementation.
@Alkl58 that is a cool tidbit, I did not know that!
Actually in the latest beta I just have you select the actual channel layout itself, as that seemed easiest lol (there are a few odd ones missing, as it's the union between what's supported with ffmpeg and the other NVEncC encoder)
Fixed in 4.2.0 https://github.com/cdgriffith/FastFlix/releases/tag/4.2.0
Hello, sorry if this is the wrong place to post this but despite having the newest version of FastFlix i still can't transcode some 5.1 streams into Opus as i get the above mentioned error. If there is only one 5.1 sound track and im transcoding to Opus 5.1 I can use the above mentioned command line options and the audio will be converted but leaving that out or more than one audio track and i still get the error ... extra annoying as it happens after all the 8+ hours of video compression as been done. Am i doing something wrong? or have I missed something? Thanks.
Hi @djsat2 can you share what the command is that you are trying to run and the error it is giving? (Please remove any sensitive content / file names)
Also remember you can always encode the audio separately than the video and remux them together later, so you don't have to just throw the encoded video away! (Requires re-encoding just audio with FFmpeg then using a muxer, either FFmpeg on the command line or others)
Hello, i replicated the error using a sample freebie video with 5.1 channel sound and used NVENC as the codec for speed (normally use x265), managed to replicate the same error by injecting "-mapping_family 1 -af aformat=channel_layouts=5.1" using the 'Custom FFMPEG options" field.
The commands are (2-pass):
"C:\Users\XXXXXX\AppData\Roaming\FFmpeg\bin\ffmpeg.exe" -y -i "C:\Video\Tests\dts_orchestra_long_core_1080p-thedigitaltheater.mkv" -max_muxing_queue_size 1024 -filter_complex "[0:0]crop=1920:1072:0:4[v]" -map "[v]" -c:v hevc_nvenc -pix_fmt p010le -tune:v hq -spatial_aq:v 0 -tier:v main -rc-lookahead:v 0 -gpu -1 -b_ref_mode disabled -profile:v main -pass 1 -passlogfile "C:\Users\XXXXXX\AppData\Roaming\FastFlix\temp_1e3d6b4bfaa07b007def4750\pass_log_file_88d1f86ea6a2df725002" -b:v 6000k -preset:v slow -2pass 1 -an -sn -dn -f mp4 NUL
"C:\Users\XXXXXX\AppData\Roaming\FFmpeg\bin\ffmpeg.exe" -y -i "C:\Video\Tests\dts_orchestra_long_core_1080p-thedigitaltheater.mkv" -max_muxing_queue_size 1024 -filter_complex "[0:0]crop=1920:1072:0:4[v]" -map "[v]" -c:v hevc_nvenc -pix_fmt p010le -tune:v hq -spatial_aq:v 0 -tier:v main -rc-lookahead:v 0 -gpu -1 -b_ref_mode disabled -profile:v main -pass 2 -passlogfile "C:\Users\XXXXX\AppData\Roaming\FastFlix\temp_1e3d6b4bfaa07b007def4750\pass_log_file_88d1f86ea6a2df725002" -2pass 1 -b:v 6000k -preset:v slow -mapping_family 1 -af aformat=channel_layouts=5.1 -map_metadata -1 -map_chapters 0 -map 0:1 -metadata:s:1 title="" -metadata:s:1 handler="" -c:1 libopus -b:1 384k -default_mode infer_no_subs "C:\Video\Tests\dts_orchestra_long_core_1080p-thedigitaltheater-fastflix-b619.mkv"
From looking at the log file, the errors are:
2021-06-09 14:15:44,201 - [libopus @ 00000196d82668c0] Invalid channel layout 5.1(side) for specified mapping family -1. 2021-06-09 14:15:44,203 - Error initializing output stream 0:1 -- Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height 2021-06-09 14:15:44,207 - Conversion failed!
Let me know if you need anything more from me.
Ok so it looks like the issue here is that when not downmixing to less tracks, aka keeping it at 5.1, FastFlix does not inject a channel layout and FFmpeg for some reason doesn't provide that information to the libopus library.
You were on the right track to try to put that in yourself, however the FFmpeg arguments are location dependent, and where FastFlix injects the additional ones for the video will not affect the audio track (notice the af aformat=channel_layouts=5.1
comes before -map 0:1
)
For example can replicate with that source by trying:
ffmpeg -i .\dts_orchestra_long_core_1080p-thedigitaltheater.mkv -map 0:1 -c:a libopus -b:a 384k -af aformat=channel_layouts=5.1 out.mkv
Whereas without the channel layout it will fail:
ffmpeg -i .\dts_orchestra_long_core_1080p-thedigitaltheater.mkv -map 0:1 -c:a libopus -b:a 384k out.mkv
...
[libopus @ 00000269d9efc580] Invalid channel layout 5.1(side) for specified mapping family -1.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
Reopening this issue, will have to provide channel information to at least libopus even when not downmixing , which FFmpeg should REALLY handle by itself :(
Hello, i also notice that issue. And changing the audio channels also reset to default the bitrate which is very annoying, so if you change first the bitrate to anything that's not the default (i think it's 384K) and then you change the channels it will switch back to the default bitrate. Very annoying when you check the output file and realize that audio is converted with an undesired bitrate
well i met that too, wondering why doesn't it get fixed after such a long duration since issue created