Audio ends too soon using A-B markers in MKV

Started by Daniel3069, January 27, 2019, 06:43:18 AM

Previous topic - Next topic

Daniel3069

Hi I'm using Avidemux to mix together video and audio from different sources into one. The videos are different lengths thus out of sync.

When I fix the two out of sync areas and save I get problems depending on the output format, despite it looking fine in Avidemux.

OUT OF SYNC *A
BLACK SCREEN *B
BLACK SCREEN UNTIL SEEK *C
AUDIO CUTS OFF AT END *D

MKV= *D
MP4= *A *B
AVI= *A *C *D

The videos produced with [start and end markers] are the cause of audio ending before their time in MKV.
If the audio could just keep playing till the end I could keep a MKV format, and until this video I was using MP4 without issues, so that's odd.

Testing with MPC using Formats .wav=mp3 .avc=MKV

Daniel3069

#1
In total of 5 videos done it seems to be only this one video despite all the information on this video looking the same as all the others ???
(I'm converting a anime season from Japanese to English)

all 3 of these videos are the same and should contain synced audio and video as in program.

MP4 plays till seek, no sound
MKV plays CAN seek, no sound
AAC is the same file but I converted the audio to AAC, black screen at start, but sound and video can't seek..

The MKV had no black screen issue before, maybe because the video was longer maybe? I dunno.

https://filebin.net/g2879b8ixd1357an

eumagga0x2a

Which version of Avidemux are you referring to? Please use the latest (190126) nightly matching your operating system (if macOS, use a Mojave build even if you run an older macOS version) to repeat all steps starting with the original source video.

All samples exhibit an abnormally high first frame delay which may account for premature end of audio, so likely the first GOP is broken. All samples play fine for me in mpv apart from the silent ending, but QuickTime really shows black screen until the point which Avidemux considers to be the start of the video.

Daniel3069

Indeed, I'll retest with a more updated version.
After I read your message I re-tested using other players instead of MPC, yes it looks like some players are more accepting than others LOL

VLC won't open the .mp4 at all, while KM player got the same file to play (without)
the sound delayed or any bugs at all, but the audios not synced -doh.

Daniel3069

Using Avidemux 190126

From A-1:04 to B-1:43

copy.mp4: Sound, video at end only, seek audio only.
copy.MKV: video, Sound, at end only, seek video only.
aac .mp4: Sound, video at end only, seek audio only.

Seems these issues are related to video length being shorter, which kinda makes these shorter tests kinda pointless ???

In the full length videos the only issue in MKV format is the sound's still ending before its time and full MP4 still has black screen at the start, BUT in KM player both full videos have no issues (dunno about sync)

I'm gonna give up on this one video as Mp4 is serving me well on the other files lol. I'll keep it as MKV with the audio cut-off for now. I really don't see why this file's so "Special"

I'm adding the video info from one working video and the one not, maybe It could be of some use to someone lol. There are small differences.
Test 2 videos and vid info uploaded: https://filebin.net/g2879b8ixd1357an

eumagga0x2a

When Avidemux adds an external audio track, it assumes that it starts at time = 0, but, as already pointed out, your sample exhibits an incredibly high first frame delay (22.628 seconds for "copy.mkv"). This means, you must set audio delay to 22628 ms, which solves the problem of audio track ending prematurally.

The source video would be necessary to assess the nature of this high delay, it might be just a single bad GOP (if I save in copy mode starting with the second GOP, the first frame delay in the resulting video is inocuous 0.125 s).

By the way, 8 ref frames seems to me to be a pretty high value which might pose a problem for some devices. If you have access to the source media, I would stick with values at or below 6 for SD content.

Daniel3069

#6
Hi thanks for your reply, in Avidemux the video and audio were synced perfectly and only after when it was copied did the de-sync occur.
I've tested different start positions with all the same results so this should have skipped over the bad GOP if there was one, I assume anyway.
With the R-frames I prefer a minimalistic approach changing little as possible, but I'll deff keep that in mind for future projects so thanks.

I've uploaded a copy of the original files they seem pretty fine though, like no issues playing in any player etc, also the steps I take.

The size in total is 110MB about 2m-3m
At this point I'm basically doing it for just for curiosity's sake as no other files are having issues lol

https://ufile.io/r55gt

I forgot to mention you might crash adding the new audio using the latest version (dunno) base 2.7.1 doesn't crash.. though I did test with the latest ver with same results..

eumagga0x2a

I'll look at the sample ASAP. Could you please provide the external audio file which triggers crash in the 190126 nightly? This is very important as detection of external audio properties has been reworked post-2.7.1.

Daniel3069

Hi yes the audio file .wav is in the 7zip I uploaded and crashes when adding to the video also in the 7zip.

I don't know what exactly makes Avidemux crash, It may be a combination of factors.

eumagga0x2a


eumagga0x2a

Can't reproduce the crash, though the 154.wav file is actually mp3 with some garbage at the head of the file (probably starting as wav thus initially confusing the detection in Avidemux).

The origin of trouble is the Matroska demuxer in Avidemux which doesn't believe the default time increment in the source MKV (which may be wrong as well) and decides to force the closest default value:

[ComputeDeltaAndCheckBFrames] 21:08:25-521  PTS is not monotonous, there are bframe
[ComputeDeltaAndCheckBFrames] 21:08:25-522  >>> MinDelta=9000 MaxDelta=334000
[getStdFrameRate] 21:08:25-522  Best match is 0
[ComputeDeltaAndCheckBFrames] 21:08:25-522  Num=1000 Den=24350 zero=0 first=0
[ComputeDeltaAndCheckBFrames] 21:08:25-524  Checking deviation for native 1000 24350
Frame 160, multiple = 162
Frame 1250, multiple = 1269
Frame 2340, multiple = 2376
Frame 8879, multiple = 9017
Frame 9969, multiple = 10124
[computeDeviation] 21:08:25-525  Den=24350 Num=1000  sum of error=7001, multiple=523
[computeDeviation] 21:08:25-525  MinDelta=9000 maxDelta=42000 skipped=523
[ComputeDeltaAndCheckBFrames] 21:08:25-525  Checking deviation for minDelta 9000 1000000
[computeDeviation] 21:08:25-526  Den=1000000 Num=9000  sum of error=48606, multiple=0
[computeDeviation] 21:08:25-526  MinDelta=9000 maxDelta=42000 skipped=125354
[ComputeDeltaAndCheckBFrames] 21:08:25-526  Deviation        = 7001
[ComputeDeltaAndCheckBFrames] 21:08:25-526  DeviationMinDelta = 48606
[ComputeDeltaAndCheckBFrames] 21:08:25-526  Deviation skip    = 125354
[ComputeDeltaAndCheckBFrames] 21:08:25-526  MinDelta=9000, defaultFrameDuation=41067
[ComputeDeltaAndCheckBFrames] 21:08:25-526  Checking deviation for stdFrameRate=1001:24000
Frame 31409, multiple = 31408
Frame 31412, multiple = 31410
Frame 31417, multiple = 31414
Frame 31422, multiple = 31418
Frame 31427, multiple = 31422
[computeDeviation] 21:08:25-526  Den=24000 Num=1001  sum of error=982, multiple=541
[computeDeviation] 21:08:25-526  MinDelta=9000 maxDelta=42000 skipped=0
[ComputeDeltaAndCheckBFrames] 21:08:25-526  Deviation for stdFrameRate(0) =982
[ComputeDeltaAndCheckBFrames] 21:08:25-526  Std frame rate is better
[ComputeDeltaAndCheckBFrames] 21:08:25-526  Old default duration    41067 us
[ComputeDeltaAndCheckBFrames] 21:08:25-526  New framerate values : 1001:24000
[ComputeDeltaAndCheckBFrames] 21:08:25-526  New default duration    41708 us
[ComputeDeltaAndCheckBFrames] 21:08:25-526  First frame pts     0 us
[open] 21:08:25-527  Have to delay by 22628376 us so that PTS>DTS
[open] 21:08:25-527  The delay is implausibly high. The calculated frame rate is probably too low.

eumagga0x2a

#11
For an immediate success please use command-line ffmpeg:

ffmpeg -i 154.mkv -i 154.wav -map 0:0 -map 0:1 -map 1:0 -map 0:2 -map 0:3 -c copy 154-with-en-track-added.mkv

(edited to preserve subtitles)

dosdan

Quote from: eumagga0x2a on January 28, 2019, 09:41:06 PM
For an immediate success please use command-line ffmpeg:

ffmpeg -i 154.mkv -i 154.wav -map 0:0 -map 0:1 -map 1:0 -map 0:2 -map 0:3 -c copy 154-with-en-track-added.mkv

(edited to preserve subtitles)

eumagga0x2a, while this is an ADM forum, as a teaching aid for the useful FFMPEG, I think it would be best you showed the reported stream indices in the input files and explain how this command line assigns them in the output file. 

Dan.

Daniel3069

#13
Oh that's odd It crashes 100% of the time for me in the 190126 version, not in the old version. The second I add ANY sound track. WITH the source video. I also tried a full reinstall removing all old versions, but same.

Yes the .wav file is .mp3 (said in my first comment lol), although I have converted it to .mp3 and .aac while having the same issues, so it can't be related. Also I've used the same .wav-mp3 files for all the other videos I've done thus far without issue. Don't ask lol.

The default video has no issues in every player I've tried, even Avidemux plays it correctly.
it can read it correctly to play but not to rewrite I dunno. ???

Unfortunately I have zero command line experience, but if the file is 100% at fault I can take comfort that I won't run into this issue again lol, though I believe if it can be readable, it should be writable, meaning Avidemux is at fault, unless I'm wrong in this belief: also possible.

edit:----
actually after a bit of testing
"Avidemux_2.7.1 VC++ 64bits 190126.exe"

Seems to crash every time with every video I try when adding another soundtrack. I definitely need the older version lol.

eumagga0x2a

#14
Quote from: Daniel3069 on January 28, 2019, 10:43:05 PM
Oh that's odd It crashes 100% of the time for me in the 190126 version, not in the old version. The second I add ANY sound track. WITH the source video.

Please reproduce the crash, then compress and attach admlog.txt from %localappdata%\avidemux\ to your reply.

I test on Linux, the operating system where Avidemux is at home. This usually does not matter for this kind of things.

Quoteit can read it correctly to play but not to rewrite I dunno. ???

It can't read it correctly.

Quoteactually after a bit of testing
"Avidemux_2.7.1 VC++ 64bits 190126.exe"

Seems to crash every time with every video I try when adding another soundtrack. I definitely need the older version lol.

Please try the win64 version (MinGW build) instead of the VC++ one.