Need help optimizing my media to direct play (Handbrake / FFmpeg)

Hi all,

This is my first time posting on the forums, and I do apologise if the question has been asked several times, however I did not find an answer related to my problem.

Short question:
I want to convert the audio only (DTS 5.1 / Ac3 5.1 to AAC 5.1) of a video to a codec that is supported to most if not all my devices (incl. Roku, Samsung TV, android/IOS phones, Apple TV, Xbox one and PS4, Chrome web browser). How can I do that without re-encoding the whole video?

Explanation:

Most of my media (including itunes music / home video records / gameplay recordings / movies & tv shows) were all encoded with handbrake (for movies & tv shows then used mkvtoolnix for the mkv container to add srt subtitles) and itunes conversion (to convert to .mp3 songs)

After that long process I found out that most of them required transcoding on all my clients (excluding Samsung tv which apparently can play anything on direct play, including HEVC codecs).

After further investigating and some search, I found out the optimal way of direct playing all my media to most of the common devices was that I should change some of the media input.

i.e. Profile High@ level 4.0 with h.264 codec and audio with AAC lc (also web optimized for chrome browser perhaps?)

Now my problem is with the audio, as most of my media is already H.264 through handbrake at rcf 23 slider.

while Handbrake can not re-encode audio only, I found out I can do it with ffmpeg, and here’s where I got stuck.

I am very limited with the use of ffmpeg, and limited as in I only know what the website here “https://trac.ffmpeg.org/wiki/Encode/AAC” teaches me only :D.

by using the command line in cmd console and changing directory to the folder of the media, i can write:

ffmpeg -i nameOFmediaINPUT.mp4 -c:v copy -c:a aac 448k OUTPUT.mp4 (if i use aac without adding the bitrate, it would default to 340k as its too low from my source file, and heard that 480k is optimum for AAC, while highest is 640k)

I realised with ffmpeg on cmd its not using all my cpu cores (a total cpu usage of 6% only) and takes a really long time (with my cpu core i7 5960x @stock speeds) its taking around ~15mins for a 1.5hr length media, almost same as handbrake with video and audio encodes.

Can Anyone lend me a hand here on what’s the proper way to change my media’s audio only to AAC stereo or AAC 5.1 depending on the media itself? Feels like i’m doing it wrong here, and also would like to get them web optimized of some files.

and if theres a better program suited for my needs. Would like to retain the quality of the video, and dont want to tamper much with the audio’s quality but only try to get it as close as to its original as possible.

Thank you all in advance.

If you’re converting only the audio, you don’t need to use all the processor’s cores.

The basic command for ffmpeg is:

ffmpeg -i input_file.ext -c:v codec_name -c:a codec_name -b:a bitrate -ac number_of_channels output_file.ext

Bitrates can be specified as full numeric value or using abbreviations like 512K
The codec you’ll be interested in is the copy codec and is just as it implies. It copies as-is. You could specify any other supported/installed codec here as well

This will also do container changes for you as well if you wish. (any container -> any container)

If your output file is MP4 , you can also specify -movflags faststart to have the MOOV atom placed at the front of the file. This is a two pass operation which ffmpeg handles. The resultant output file is one which will start playing in a player as soon as the video starts downloading instead of waiting for the entire file to download.

As an example, to convert some arbitrary input file to AAC 2 channel with 256Kbs/channel (stereo), which is overkill on audio fidelity, and place in an MP4 container which is optimized for web page streaming, the command would be:

ffmpeg -i input_filename -c:v copy -c:a aac -ac 2 -b:a 512K -movflags faststart output.mp4

Thanks ChuckPa!

As I understand, for AAC Stereo i’m converting them to 192k, and as for AAC 5.1 i’m doing 448K, using Handbrake as a guide there.

As most of my files were in MKV containers (used to hold Multiple SRTs) what I did was:

FFmpeg -i Media_Input.mkv -movflags faststart -vcodec copy -acodec AAC -b:a 000k Media_Output.mp4

what it did for me was if the input file had either DTS or AC3 in 6 channels (5.1) it would keep the number of channels, and same goes for stereo.

with 000k I used 192k for stereo, and 448k for 5.1 AAC

would that work? been testing it, I used to have DTS audio for home theatre.

been using your method and its working for me! Thanks!

Now I’m figuring out how to do a batch of them.
i.e. For a full season Tv show.

at the moment, i’m doing it one by one manually while opening several CMD.exe and writing down the command lines for each hehe!

PS: As you mentioned for number of channels in your command line, do I have to specify the number of channels if i’m going to convert for example 5.1 DTS to 5.1 AAC? I’m trying to retain the channel numbers while changing all audios to AAC for universal support.

PS2: are 192k for stereo and 448k 5.1 for audios good? or am I going over on 5.1?

Thank you again!

@Ashus said:
Thanks ChuckPa!

As I understand, for AAC Stereo i’m converting them to 192k, and as for AAC 5.1 i’m doing 448K, using Handbrake as a guide there.

As most of my files were in MKV containers (used to hold Multiple SRTs) what I did was:

FFmpeg -i Media_Input.mkv -movflags faststart -vcodec copy -acodec AAC -b:a 000k Media_Output.mp4

what it did for me was if the input file had either DTS or AC3 in 6 channels (5.1) it would keep the number of channels, and same goes for stereo.

with 000k I used 192k for stereo, and 448k for 5.1 AAC

would that work? been testing it, I used to have DTS audio for home theatre.

been using your method and its working for me! Thanks!

Now I’m figuring out how to do a batch of them.
i.e. For a full season Tv show.

at the moment, i’m doing it one by one manually while opening several CMD.exe and writing down the command lines for each hehe!

PS: As you mentioned for number of channels in your command line, do I have to specify the number of channels if i’m going to convert for example 5.1 DTS to 5.1 AAC? I’m trying to retain the channel numbers while changing all audios to AAC for universal support.

PS2: are 192k for stereo and 448k 5.1 for audios good? or am I going over on 5.1?

Thank you again!

I have never tested ffmpeg using 000K or 000k (be very careful of upper and lower case with FFMPEG)

If you want to retain 5.1 in the output (which is 5 + 1 side) -ac 6 will do it

Thanks Chuck!

yea with k - bit and K = byte, a simple mistake would screw me :P.

got the basic idea thanks to you! Gonna practice it a bit but so far I got all plex clients working with Direct Play including subtitles (Image only, seems Automatic usually burns in subs). On the other hand, Xbox one does not like direct play with subs, keeps burning them in, I understand that its the limitations of xbox one not using srt for image only.

Nonetheless, very satisfied that I took the load off my main pc CPU!

Yes, most screw up the k versus K at least a few times before the X_X kicks in and all becomes right with the world :smiley: