Jump to content
Tuts 4 You
LCF-AT

FFmpeg - Audio bitrate not same

Recommended Posts

LCF-AT

Hi guys,

I found a new problem using FFmpeg to encode some video / audio streams.My goal was it to encode some diffrent parts of one video out using same audio bitrate but as result I have the parts out with diffrent bitrates what means I can not merge this parts together but for this I need exact same audio bitrate (only for audio needed).Thats a problem so far.I tried already all diffrent ffmpeg commands without success.I am using audio codec aac (nativ).On internet I found some infos about using libfdk_aac instead of acc what I tried too (Internet I found a static compiled build version what has this codec included which is not present in normal builds).I tried this one now and it still dosent match.

Example commands:

-i - -c:a libfdk_aac -b:a 128k -f mp4 -y "%(tempaudiofile)"

I just loaded a video in VirtualDub2 and using external encoders option where I can set commandline arguments.I just selected some video frames to encode from the beginning of the video and as result I got first a matching audio bitrate = good.Now I did selected some frames from the end of the video and did encode it and in this second file I got a audio bitrate which is higher.

44100Hz  128 kb/s tot (2 chnls) <-- of first video part
44100Hz  129 kb/s tot (2 chnls) <-- of second video part

So you see its only 1 bit more.

So my question is whether anyone knows some more specific commands I could use to get my desired constant audio bitrate out for acc codec?

Normaly I use VirtualDub tool to cut videos using Quick Time Plugin 2.6 loading mp4 videos.The good thing using this plugin is that I can cut videos and keeping the original audio stream.That pretty good.The disadvantage is that the plugin has some bad issues for the video stream what means frames are not same where there should be same.This is bad if you wanna cut exactly.Video handling bad / audio handling good.So to make a exact video cutting I need to load the video using FFmpeg input driver or Caching input driver (VirtualDub2) or DirectShow input driver so with these I get all video frames correctly to see without black frames or any other issues the QT plugin has.Problem with this drivers are the audio stream what needs to be encode and for that I wanna use FFmpeg as I told above but there I have that bitrate issues which dosent match.Maybe anyone could help to fix that issues. :)

Thank you

Share this post


Link to post
Share on other sites
LCF-AT

Hi again,

I was now trying to use external encoder using just the copy method of ffmpeg in the audio encoder but this dosent work in VirtualDub. :( Thats pretty bad.

So I would like to keep the audio stream original without to re-encode it (using ffmpeg in VD).All seems to work good if I split any file using ffmpeg from commandline direct like this..

ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4

This new both files I can also merge together in VD.

Example: Lets say I do have 3 videos and wanna cut out some parts and merge them together.If I encode the audio stream like I told in my first post then I get diffrent bitrates out what means I cant merge them.How to handle that issue without to make a retour saving all audio streams as wav file.

greetz

Share this post


Link to post
Share on other sites
LCF-AT

Hi again,

so I was playing around again testing diffrent video tools and found out that they all almost working very diffrent to merge / join videos and getting diffrent results out (mostly bad of course).

Good news first: I tried ffmpeg again to merge files like in my first post who having diffrent aac bitrates.So it works to merge them putting all files into extern txt file and using -f concat command.So with this I get successfully a complete correct file. :) The bad thing is I have no GUI yet for this (maybe I build any later).I also tried to tool called Avidemux what also works successfully to join such files.

Next I tried tools like MP4 Box GUI / VD2 and others what do merge these files too but they are not correctly merged = total bad result (not merged 2. file to first or second file sound isnt present in output file).

greetz

Share this post


Link to post
Share on other sites
LCF-AT

Hi guys,

I have another question.Just wanna ask whether anyone knows how to re-encode diffrent video & audio streams into a new format?Lets say I have 3 video with audio and all 3 are diffrent.They using diffrent video & audio formats and now I wanna create one commandline to encode all in the one and same video / audio format.So I can do this one by one for example but I would like to know whether its also possible to do this at once (one commandline)?I was playing around and did check some commandline I found like this..

-c:v libx264 -r 25 -vf scale=854:480 -c:a aac -strict experimental -b:a 128k -ac 2 -ar 44100 -threads 2 -crf 20 -f mp4

...but audio isnt there in the second video (I tried it with 2 video in this case).Do you have any clues for that how to make more than one diffrent audio / video streams same in one commandline without to handle all videos one by one?

greetz

Share this post


Link to post
Share on other sites
身勝手のごくい

Hi,

If i understand correctly u have 3 different type of videos with audio, u want to merge them to single video by following each timeline with its own audio.

If thats the case in virtualdub u can use 'append avi segment' before u save them all might have some limitations i got no experience with it.

Im using virtualdub to create low size videos with decent quality from uncompressed files, mostly standard aac x265 and mkvmerge as multiplexer.

I would just queue every video in a job and then merge them (u might have to set same static size previously in the conversion to avoid stretching).

here are the exact cmdargs im running:

-q 0.67 -ignorelength -if - -of "%(tempaudiofile)"

--crf 24 --preset medium --input-res %(width)x%(height) --fps %(fps) -o "%(tempvideofile)" -

-o "%(outputname)" --default-duration 0:%(fpsnum)/%(fpsden)fps "%(tempvideofile)" "%(tempaudiofile)"

Hope it helps, regards.

  • Like 1

Share this post


Link to post
Share on other sites
LCF-AT

Hello .....you,sorry I can't read your name. :)

Thanks for your answer so far.Yes I am also using VD/2 sometimes.

So about FFmpeg commandlines.In this case I just wanna do it alone with FFmpeg (without VD) and with only one whole cmd line if possible but anyhow I dont get it work yet also not if I am using the concat mode (extern file with paths of the videos I wanna handle).Its works if I handle all videos alone but not all at once you know.In this case I could setup the list of videos I wanna make same and start the process and go away and if I come back then all shouldbe finished.All this without to create any extra script or other tools between using ffmpeg.I am still not sure whether its possible but I am trying check another ffmpeg parameters or infos I found on internet.Will see.

greetz

Share this post


Link to post
Share on other sites
身勝手のごくい

Hi, again!

I did some digging, concatating videos without have to re-encode can be done easily as found here https://trac.ffmpeg.org/wiki/Concatenate.

You can make it with a single command line.

I've made first a list of my video files using this:

(for %i in (*.mkv, *.avi, *.mp4) do @echo file '%i') > mylist.txt

then i run this:

ffmpeg -f concat -i mylist.txt -c copy output.mkv


(videos merged without losing any quality in single file, and the order was filename ascending)

In a previous version of ffmpeg i run this fully working example:

"C:\ffmpeg\ffmpeg.exe"  -y -t 70.19 -i C:\ffmpeg\v1.mkv -t 71.77 -i C:\ffmpeg\v2.mkv -t 12.10 -i C:\ffmpeg\v3.mkv -t 12.35 -i C:\ffmpeg\v4.mkv -t 16.92 -i C:\ffmpeg\v5.mkv -t 37.10 -i C:\ffmpeg\v6.mkv -t 70.19 -i C:\ffmpeg\v1.mkv -t 71.77 -i C:\ffmpeg\v2.mkv -t 12.10 -i C:\ffmpeg\v3.mkv -t 12.35 -i C:\ffmpeg\v4.mkv -t 16.92 -i C:\ffmpeg\v5.mkv -t 37.10 -i C:\ffmpeg\v6.mkv -filter_complex "[0:v] trim=end=70.19 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_0]; [1:v] trim=end=71.77 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_1]; [2:v] trim=end=12.10 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_2]; [3:v] trim=end=12.35 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_3]; [4:v] trim=end=16.92 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_4]; [5:v] trim=end=37.10 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_5]; [v_0_0][v_0_1][v_0_2][v_0_3][v_0_4][v_0_5] concat=n=6:v=1:a=0[v_0]; [6:a] atrim=end=70.19 [a_0_0]; [7:a] atrim=end=71.77 [a_0_1]; [8:a] atrim=end=12.10 [a_0_2]; [9:a] atrim=end=12.35 [a_0_3]; [10:a] atrim=end=16.92 [a_0_4]; [11:a] atrim=end=37.10 [a_0_5]; [a_0_0][a_0_1][a_0_2][a_0_3][a_0_4][a_0_5] concat=n=6:v=0:a=1[a_0]" -map [v_0] -map [a_0] -pix_fmt yuv420p -b:v 1844 -vcodec libx265 -crf 28 -preset ultrafast -aspect 16:10 -ab 192K -ac 2 -ar 44100 -acodec libfaac C:\ffmpeg\ouput.mp4

Its reencoding the videos and merging them to the specified output:
video:
1680x1050
1844 br
ultrafast preset
16:10 aspect ratio
yuv420 pixel format

audio:
44100 sample rate
192K bitrate

In case u want this old ffmpeg version i will leave it here with a picture of how the output looks like.

Cheers (:

ffmpeg.zip

ffmpegOutput.png

  • Like 1

Share this post


Link to post
Share on other sites
LCF-AT

Hi again,

I tried concat command using extra file with diffrent video paths inside.First problem I have....about the filenames...

file 'C:\123\test'video1.mp4'
file 'C:\123\test'video2.mp4'

...if the filename used a ' sign in the name itself then it does fail whats not happens if I just use -i paramters.Strange somehow.

Now lets talk again about encoding of diffrent video files (formats / resolutions / with and without audio streams etc).The filter_complex paramters is also very complex to understand so maybe its possible for you to write some less complex commands examples next time which I could test without trimming etc.

Example: I made a small pic of 2 video from my app I did added...

Vidinfo.png.b8a2ef7a8d37c42b4524b89244224df0.png

...now I wanna encode both to one same video & audio & container format and join them.All at once with one commandline.

First problem I see in this case that they have diffrent resolutions.

- How to make both video to same resolution like (-s hd720)

- How to set a same aspect ratio 16:9 without to make the video stretch into 16:9 (I mean it should keep original) = need to add a letterbox OR make a zoom OR Crop it.Something like that you know.

- How to handle the diffrent framerates?Can they keep same?I mean the sound stream needs to keep matching of course.

- How to do handle diffrent video & audio bitrates?I would like to tell ffmpeg to choose A.) the best bitrate of video & audio streams it can find in the files (if possible) so that all files will created with the best rate which is present in any file from the list of video I wanna handle all at once.

Something like this you know,so maybe you can make any examples I can check out.Later I would like to use them to make some diffrent profiles.

PS: I am just a basic FFmpeg user at the moment and I dont know all possible commands yet.

Thank you

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×