Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
11th September 2015, 05:34 | #1 | Link |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
How to Encode Audio with x264.exe
I'm making improvements to the media encoder I'm working on. Currently, the only option I'm giving is to copy the original audio after processing the video. In some cases, however, it would be good to re-encode the audio, such as when we want to trim the video, or when we have uncompressed low-quality audio from a camera.
To copy the audio, I encode with x264.exe and then muxe back the original audio with FFMPEG. If I instead want to encode the audio as AAC, what's the best way of doing it? AFAIK, x264 official builds don't include the audio encoder and can only output a raw H264 file that then needs to be muxed into a container. Only options I can think of are 1. Having a custom build that supports audio encoding 2. Rendering the video and audio separately and then muxing together; for this pass, I would have to discard video functions and only keep functions that affect the audio, speed or duration. What do experts have to say on the topic? I did custom-build FFMPEG to include audio encoder, but AFAIK x264's encoder is superior to FFMPEG. Also, in some cases it could be useful to encode the video in a lossless format, what's *the* way of doing so? Thanks!
__________________
FrameRateConverter | AvisynthShader | AvsFilterNet | Natural Grounding Player with Yin Media Encoder, 432hz Player, Powerliminals Player and Audio Video Muxer Last edited by MysteryX; 11th September 2015 at 06:51. |
11th September 2015, 06:24 | #2 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
If you can mux with ffmpeg,
Code:
>ffmpeg.exe -y -i "video.264" -i "audio.wav" -fps 30 -c:v copy -c:a copy -f mp4 "output.mp4" (may not work, depending on ffmpeg version and included libraries; check your console output for clues) Code:
>ffmpeg.exe -y -i "video.264" -i "audio.wav" -fps 30 -c:v copy -c:a aac -q:a 0.35 -f mp4 "output.mp4" Code:
>neroAacEnc.exe -q 0.35 -ignorelength -if "audio.wav" -of "audio.aac" >ffmpeg.exe -y -i "video.264" -i "audio.aac" -fps 30 -c:v copy -c:a copy -f mp4 "output.mp4" |
11th September 2015, 06:24 | #3 | Link |
Pig on the wing
Join Date: Mar 2002
Location: Finland
Posts: 5,733
|
First compile libx264 using the latest x264 git and then compile ffmpeg with libx264, and you'll have the best of both worlds
https://trac.ffmpeg.org/wiki/How%20t...(x264,%20H.264)
__________________
And if the band you're in starts playing different tunes I'll see you on the dark side of the Moon... |
11th September 2015, 06:48 | #5 | Link | |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
Quote:
If I'm using FFMPEG, do I need to use x264 separately, or can I simply use it from within FFMPEG? I read somewhere that to encode x264 videos with FFMPEG with decent quality, you had to tweak settings quite a bit while x264.exe was working great right out of the box. While searching on the topic, I also found someone mentioning that encoding both separately and then muxing could cause synchronization issues; not sure if that's an issue. While also searching about lossless encoding, I also saw a comment that UT Video was fast to process but produced a large file, and that there were better options for lossless to produce smaller files. Sorry, fixed it!
__________________
FrameRateConverter | AvisynthShader | AvsFilterNet | Natural Grounding Player with Yin Media Encoder, 432hz Player, Powerliminals Player and Audio Video Muxer Last edited by MysteryX; 11th September 2015 at 06:51. |
|
11th September 2015, 06:51 | #6 | Link |
Pig on the wing
Join Date: Mar 2002
Location: Finland
Posts: 5,733
|
The forum software snipped the last ')' out of the URL so you'll apparently need to add that You can use x264 inside ffmpeg if you follow the instructions. The quality will be the same because the code is the same.
__________________
And if the band you're in starts playing different tunes I'll see you on the dark side of the Moon... |
11th September 2015, 07:05 | #7 | Link |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
I just read that it is illegal to publicly distribute a software that includes FFMPEG with libfdk_aac, so I shouldn't use that option. (correct?)
Nero AAC Codec looks interesting. Will I run into any potential issues if I encode the audio and video separately and then muxe? Even if I trim the video and change the speed? If I get this correctly, I would have to 1. Encode to x264 via FFMPEG and output the audio as PCM 2. Convert audio from PCM to AAC with Nero AAC Codec 3. Muxe the video with the AAC audio That would work? Then if I want lossless audio, I stick to step 1. |
11th September 2015, 08:42 | #8 | Link |
Registered User
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
|
ffmpeg also supports the libvo_aacenc codec which I use constantly. Some people on the ffmpeg mailing list regard it as inferior to libfdk_aac, so I guess a comparison in your case might be in order.
|
12th September 2015, 03:03 | #10 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
I think you are right. My memory circuits are faulty.
http://wiki.hydrogenaud.io/index.php?title=AAC_encoders |
12th September 2015, 15:56 | #11 | Link | |
Registered User
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
|
Quote:
|
|
16th September 2015, 16:48 | #12 | Link |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
Thanks for all the useful information!
About Fraunhofer AAC Encoders, could I run into legal issues if I distribute a custom-built version of FFMPEG that includes it, as part of the setup package of an open-source software? As for Fraunhofer AAC vs Nero... it seems they're both good. If I get this properly, Nero was best when it came out, but now Fraunhofer is better? |
17th September 2015, 13:55 | #13 | Link |
Registered User
Join Date: Mar 2014
Posts: 308
|
If you care about GPL compatibility (so you can have an ffmpeg build with --enable-gpl), the best option (rule 12 be damned) is to use libavcodec's AAC encoder. I hear it's much better now than it was years back, but it's not like you have much of a choice anyway because libvo_aacenc is literally the only other free AAC encoder and it allegedly sucks.
According to that same page, if you absolutely must have an audio format compatible with MP4 and a GPL-compatible encoder for it, using LAME to encode to MP3 is an even better option. (Yeah, yeah, MP3 is an old format and AAC is supposed to be better, but people haven't invested the same amount of time into improving the free AAC encoders.) Also, why is this in the AviSynth usage forum?
__________________
Say no to AviSynth 2.5.8 and DirectShowSource! Last edited by colours; 17th September 2015 at 13:59. |
18th September 2015, 21:28 | #14 | Link |
Registered User
Join Date: Jul 2008
Posts: 532
|
|
19th September 2015, 08:52 | #15 | Link |
SuperVirus
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,351
|
Regarding NeroAACenc...
keep in mind that it has a BIG encoder delay, so it probably is not the most suitable choice for movies's or videos's audio tracks... Last edited by filler56789; 19th September 2015 at 08:54. Reason: clarity |
19th September 2015, 09:50 | #16 | Link | |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,915
|
Quote:
The recommended encoder for low bitrates is Qaac (Quicktime) than have also the --no-delay parameter, but for bitrates over 64 kbps/channel you can use NeroAacEnc without audible differences. You can use NeroAacEnc with -q 0.4 (or greater) safely.
__________________
BeHappy, AviSynth audio transcoder. |
|
19th September 2015, 17:59 | #17 | Link | |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
|
Totally agree with tebasuna...
If you prefer to use FFMpeg for AAC encoding, have a look here: https://trac.ffmpeg.org/wiki/Encode/AAC From their FAQ: Quote:
You can get such FFMpeg binaries and also the libfdk_aac DLL at Sherpya's MPlayer site: http://oss.netfarm.it/mplayer/ Cheers manolito Last edited by manolito; 19th September 2015 at 18:57. |
|
|
|