[SOLVED] How to extract too long an audio

Started by Pipalo, April 10, 2021, 01:58:26 AM

Previous topic - Next topic

Pipalo

Hi,

I have an mkw with an audio that needs to be modified to match the video lentgh.
The audio is longer, but should match the video.
I used the change ips filter option, and with an offset, it corrects the problem.

When I mux this out though, I end up with the end of the audio missing,
as Avidemux only considers the audio track within the limits of the video part, which is shorter.

The audio is there, I know it, as my player can read the end of it, but Avidemux does not seem to want to know about it.

I tried extracting the audio,
I tried adding more video then extract the audio,
but the end of the audio is lost always.

Does anyone have an idea?

thx, and have a nice day.

eumagga0x2a

Quote from: Pipalo on April 10, 2021, 01:58:26 AMI have an mkw with an audio that needs to be modified to match the video lentgh.
The audio is longer, but should match the video.

Does this mean that sync with video doesn't matter?

Quote from: Pipalo on April 10, 2021, 01:58:26 AMI used the change ips filter option, and with an offset, it corrects the problem.

I fear, I don't follow you here. Did you mean "change fps"? If so, did you mean the audio filter or the video filter?

Quote from: Pipalo on April 10, 2021, 01:58:26 AMWhen I mux this out though, I end up with the end of the audio missing,
as Avidemux only considers the audio track within the limits of the video part, which is shorter.

Right, Avidemux will always truncate the internal audio track at the duration of the video track. This doesn't apply to the external track, however. You don't provide any information what type of audio it is (codec, number of channels, sampling rate), unfortunately, but with an AAC audio track, you could try to use ffmpeg on command line:

ffmpeg -i source.mkv -vn -c:a copy should-be-full-length.aac
What happens next with the generated "should-be-full-length.aac" file, depends on what you actually want to achieve. Do you want to slow down the video? If so, what is the frame rate of the source video? Or would it be enough just to repeat a single frame? Or is it the audio which needs to be accelerated?

Pipalo

Hi, thanks a lot for your answer.

- Sync matters.
- So I changed audio fps, and it corrects the sync problem.
- When I mux this out, Avidemux truncates the end of the audio,
alas it truncates it "before applying the sync correction",
So sync is ok, but the end is missing.
I hope I can make myself clear:)

-Actually there are 2 audio tracks in the mkv, one aac that I get rid of,
and one mp3  (48000 Hz, stereo, 125 kb/s), the one I want to sync and keep.

If I understand correctly, I should try some other app to extract the full lentgh audio. Then remux with Avidemux.
I tried with Audacity, and managed to, after some work... The only option eventually is re-encoding before export.
Of course I'd prefer a "copy" kind of extraction.

eumagga0x2a

Quote from: Pipalo on April 11, 2021, 02:50:02 AM- Sync matters.
- So I changed audio fps, and it corrects the sync problem.

I bet you should not touch audio but instead fix presumably wrong fps of the video.

Quote from: Pipalo on April 11, 2021, 02:50:02 AM- When I mux this out, Avidemux truncates the end of the audio,
alas it truncates it "before applying the sync correction",
So sync is ok, but the end is missing.
I hope I can make myself clear:)

Absolutely, you just need to follow the advice from my last reply, but for the mp3 track (use .mp3 as filename extension instead of .aac).

Quote from: Pipalo on April 11, 2021, 02:50:02 AMIf I understand correctly, I should try some other app to extract the full lentgh audio.

Yes, but not "some other app" – you would use FFmpeg, the tool for audio and video handling, the core of many application including Avidemux and VLC.

Quote from: Pipalo on April 11, 2021, 02:50:02 AMI tried with Audacity, and managed to, after some work... The only option eventually is re-encoding before export.
Of course I'd prefer a "copy" kind of extraction.

Sure, this is why I suggested ffmpeg...

Pipalo

Ah, so it would work with mp3 as well,
I didn't got that...
Ok, I'll try:)

thx again

eumagga0x2a

If the mp3 track is not the first audio track, you will probably need a proper -map option, matching the stream index, please see e.g. https://write.corbpie.com/understanding-ffmpeg-map-with-examples/ for examples.

Pipalo

Yes, that's what i just found out:)

ffmpeg -i file_name.mkv -map 0:2 -vn -c:a copy full_lentgh_audio.mp3
I used this command line.
-map 0:2 instruction determines the selected stream.
It worked, something strange happened though.

Before extraction, the mp3 was 125kps,
after, it became 115kps.
Any idea what happened ?

butterw

Your command seems correct, I would assume the header just gets rewritten when you extract, but do pay attention to the ffmpeg console output.
The mp3 file should be generated instantaneously with no re-encoding and filesize/duration should be as expected.


Pipalo

True, there was no re-encoding, it was too fast.
This case is solved, thanks guys for your help.

I was just wondering what happened there.
After recheck I found that only MPC HC produces this misinterpretation.
For MediaInfo the mp3 is the same before and after.
Maybe something in the metadata... It seems for MPC HC, bitrate and nominal bitrate were swapped.


Anyway... thanks again.

Pipalo

Well, there's something, which is not as resolved as I thought:)
I have several videos I must treat like the first one we spoke about.

The other ones have reather the same config:
a video,
two audio streams,
one aac I want to get rid of,
and the other one is the mp3 I want to keep.
This mp3 very likely needs "frame rate" modification, and a time offset.

I tried a few things, but I can't make it work.
The frame rate option does nothing.

Any reason this could happen?


eumagga0x2a

Quote from: Pipalo on April 15, 2021, 06:59:47 AMThis mp3 very likely needs "frame rate" modification

I doubt it. The fps (and the duration) of the video track can be wrong.

Quote from: Pipalo on April 15, 2021, 06:59:47 AMI tried a few things, but I can't make it work.

Please start with providing info about the source mkv file, e.g. using the text output of MediaInfo application and the portion of Avidemux console output (%localappdata%\avidemux\admlog.txt on Windows) from loading such a source file.

Pipalo

Here is MediaInfo output:

Video
ID                          : 1
Format                      : AVC
Format/Info                 : Advanced Video Codec
Format profile              : High@L5.1
Format settings             : CABAC / 3 Ref Frames
Format settings, CABAC      : Yes
Format settings, Reference  : 3 frames
Codec ID                    : V_MPEG4/ISO/AVC
Duration                    : 1 h 54 min
Bit rate                    : 3 500 kb/s
Width                       : 1 920 pixels
Height                      : 1 080 pixels
Display aspect ratio        : 16:9
Frame rate mode             : Constant
Frame rate                  : 23.976 (24000/1001) FPS
Color space                 : YUV
Chroma subsampling          : 4:2:0
Bit depth                   : 8 bits
Scan type                   : Progressive
Bits/(Pixel*Frame)          : 0.070
Stream size                 : 2.80 GiB (91%)
Writing library             : x264 core 157 r2969 d4099dd
Encoding settings           : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=0 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=8 / lookahead_threads=8 / sliced_threads=1 / slices=8 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=2 / keyint=250 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc=abr / mbtree=0 / bitrate=3500 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=2:1.00
Default                     : Yes
Forced                      : No

Audio #1
ID                          : 2
Format                      : AAC LC SBR
Format/Info                 : Advanced Audio Codec Low Complexity with Spectral Band Replication
Commercial name             : HE-AAC
Format settings             : NBC
Codec ID                    : A_AAC-5
Duration                    : 1 h 54 min
Bit rate                    : 256 kb/s
Channel(s)                  : 6 channels
Channel layout              : C L R Ls Rs LFE
Sampling rate               : 48.0 kHz
Frame rate                  : 23.438 FPS (2048 SPF)
Compression mode            : Lossy
Stream size                 : 209 MiB (7%)
Title                       : 国语
Default                     : Yes
Forced                      : No

Audio #2
ID                          : 3
Format                      : MPEG Audio
Format version              : Version 1
Format profile              : Layer 3
Format settings             : Joint stereo / MS Stereo
Codec ID                    : A_MPEG/L3
Codec ID/Hint               : MP3
Duration                    : 1 h 54 min
Bit rate mode               : Variable
Bit rate                    : 107 kb/s
Nominal bit rate            : 128 kb/s
Channel(s)                  : 2 channels
Sampling rate               : 48.0 kHz
Frame rate                  : 41.667 FPS (1152 SPF)
Compression mode            : Lossy
Stream size                 : 87.6 MiB (3%)
Title                       : 日语
Writing library             : LAME3.97
Encoding settings           : -m j -V 4 -q 2 -lowpass 17 --abr 128
Language                    : Japanese
Default                     : No
Forced                      : No

Video and audio sync is not correct, a short offset is needed as well.
Once again, I will get rid of audio 1, and will keep audio 2.
This time though audio 2 is not longer, but 3 seconds shorter.
The framerate that MediaInfo indicates is really something else: 41.667 FPS
What is that ?

Pipalo

I just checked the first file I managed to correct already.
MediaInfo says framerate was 41.667 as well.
Though it's strange to me, Avidemux did it just fine:)

About the new file I can't correct,
which part of the Avidemux log could be useful ?

eumagga0x2a

Quote from: Pipalo on April 16, 2021, 03:53:29 AMHere is MediaInfo output:

Video

Duration                    : 1 h 54 min

Frame rate mode            : Constant
Frame rate                  : 23.976 (24000/1001) FPS

Video and audio sync is not correct, a short offset is needed as well.
Once again, I will get rid of audio 1, and will keep audio 2.
This time though audio 2 is not longer, but 3 seconds shorter.

How much of an offset do you need to add to ensure the start of the Japanese track is in sync with video? If ~3 seconds, then the true fps of the video might be not 24000/1001 but 24000/1000 (24 fps exactly).

Variable bitrate for MP3 may be problematic for duration estimation.

Quote from: Pipalo on April 16, 2021, 03:53:29 AMThe framerate that MediaInfo indicates is really something else: 41.667 FPS
What is that ?

Sampling rate divided through number of samples per audio frame (48000 / 1152 = 41.667), nothing to worry about.

eumagga0x2a

Quote from: Pipalo on April 16, 2021, 04:36:52 AMwhich part of the Avidemux log could be useful ?

Everything between

[MKV] *** Header dump ***
and

[MKV]Matroska successfully read