lisamelton / other_video_transcoding

Other tools to transcode videos.
MIT License
543 stars 24 forks source link

Support for ffmpeg fdk-aac vbr encoding #127

Closed whppr closed 2 years ago

whppr commented 2 years ago

First; thanks so much for this script and all the progression made in the last year (I read all the change logs and also the issues and wiki to get a grip on all the design choices). I finally upgraded to a PC with a proper RTX 3060 graphics adapter, so video encoding using this script is a real pleasure again. I've been testing a lot in the last weeks and I've settled for 6000k (which is indeed marginally better than the default setting) and using fdk-aac for all tracks with VBR encoding.

To use VBR encoding I had to adapt the script myself (thanks for making this so easy to do), but it would be great if this would be a future parameter. I did settle for VBR 5 (no lowpass filter) encoding, because it ensures maximum quality for comparable or lower bitrates than (E)AC3 and provides great compatibility across all my devices.

lisamelton commented 2 years ago

@whppr Thanks and congrats on that awesome CPU!

OK, I will consider VBR support for FDK. Stay tuned.

lisamelton commented 2 years ago

The problem I'm having with exploring this is just testing FDK. It's basically impossible to use FDK without building a custom verson of ffmpeg due to licensing issues. So, this will go on a back burner until I figure that out.

CaptSonic commented 2 years ago

@whppr Can you share your script? I am also interested to use fdk_aac for my workflow.

CaptSonic commented 2 years ago

@donmelton Can you give me a hint how to use fdkaac in your script with my self compiled ffmpeg version?

libfdk_aac -cutoff 20000 -afterburner 1 -vbr 5

lisamelton commented 2 years ago

@CaptSonic The only way to use FDK with other-transcode at the moment is to modify the command line it emits to ffmpeg. You can get that command line using the --dry-run option. You can then copy, edit and paste that command back into your terminal.

samhutchins commented 2 years ago

@donmelton Is that right? I thought other-transcode had a find_encoders method, and it would use either aac_at or libfdk_aac if it could find it.

EDIT: I'm pretty sure it'll use fdk if ffmpeg has it, but the only way to add those extra options (-cutoff, -afterburner, and -vbr is to modify the ffmpeg command as Don described

lisamelton commented 2 years ago

@samhutchins Ack! I somehow missed your comment. Apologies!

And you are correct, I dynamically choose libfdk_aac if it's available. My bad.

whppr commented 2 years ago

@CaptSonic Sorry for my late reply. I was not active on my PC on which I had the modified script stored.

I've changed this line (line 2104 in v0.9): *(bitrate.nil? ? [] : ["-b:a:#{index}", "#{bitrate}k"]), Into: *(encoder == 'libfdk_aac' ? ["-vbr", '5'] : []),

Then I convert with the --aac-only parameter. As you can see I use -vbr 5, because this is the only setting without low pass filter and is fully transparent.

CaptSonic commented 2 years ago

Thank you. I'll try it. But first I had to tell my PC to use my own ffmpeg version as standard

lisamelton commented 2 years ago

@whppr OK, I've got a --fdk-vbr option implemented. It seems to work but I need to do more testing. It's likely I'll check this in tomorrow if it still works then. Stay tuned.

lisamelton commented 2 years ago

@whppr @CaptSonic @samhutchins OK, I have checked in the feature implementation. Here's how I'll describe it in the README:

  • Add a --fdk-vbr option to other-transcode to set the numeric variable bitrate (VBR) mode for the Fraunhofer libfdk_aac audio encoder, disabling constant bitrate (CBR) ratecontrol. VBR mode 1 selects the lowest quality and 5 the highest. Please note that the libfdk_aac encoder is not normally included with ffmpeg due to licensing restrictions and the --fdk-vbr option has no effect if that encoder is not available.

Please download it and try it out. Thanks!

CaptSonic commented 2 years ago

Thank you! I will try it. Could you add the -afterburner 1 feature as well, since Frauenhofer also recommends it?

https://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#Afterburner

lisamelton commented 2 years ago

@CaptSonic So, should Afterburner be enabled by default? And how much does it affect performance?

whppr commented 2 years ago

No need to enable afterburner. It is enabled by default.

lisamelton commented 2 years ago

@whppr Thanks! I just found that out looking at the code, too. :)

CaptSonic commented 2 years ago

Encode is running. Looks good.

lisamelton commented 2 years ago

OK, I'll close this now since the code is in and seems to be working. I'll likely make an official release with it in a week or two. Thanks, all!