Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Sync Old AAC audio track w/new H264 video with different sample rates? (Read 793 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Sync Old AAC audio track w/new H264 video with different sample rates?

Hello everyone. It's been a while since I posted here. I have two video/audio files:

Code: [Select]
-------- OLD MP4 FILE WITH LOCAL LANGUAGE -------- 
Complete name                            : OLD.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/avc1)
File size                                : 48.3 MiB
Duration                                 : 22 min 16 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 303 kb/s
Encoded date                             : UTC 2009-12-07 19:43:41
Tagged date                              : UTC 2009-12-07 19:43:41

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L5.1
Format settings                          : CABAC / 8 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 8 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 22 min 16 s
Bit rate                                 : 268 kb/s
Maximum bit rate                         : 985 kb/s
Width                                    : 512 pixels
Height                                   : 384 pixels
Display aspect ratio                     : 4:3
Frame rate mode                          : Constant
Frame rate                               : 29.970 (30000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.045
Stream size                              : 42.7 MiB (88%)
Writing library                          : x264 core 56 svn-680
Encoding settings                        : cabac=1 / ref=5 / deblock=1:1:1 / analyse=0x3:0x133 / me=umh / subme=6 / brdo=1 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=0 / threads=3 / nr=0 / decimate=1 / mbaff=0 / bframes=5 / b_pyramid=1 / b_adapt=1 / b_bias=0 / direct=1 / wpredb=1 / bime=1 / keyint=250 / keyint_min=25 / scenecut=40(pre) / rc=2pass / bitrate=268 / ratetol=1.0 / rceq='blurCplx^(1-qComp)' / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30
Encoded date                             : UTC 2009-12-07 19:43:41
Tagged date                              : UTC 2009-12-07 19:43:47
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC SBR PS
Format/Info                              : Advanced Audio Codec Low Complexity with Spectral Band Replication and Parametric Stereo
Commercial name                          : HE-AACv2
Format settings                          : Implicit / NBC
Codec ID                                 : mp4a-40-5
Duration                                 : 22 min 16 s
Bit rate mode                            : Variable
Bit rate                                 : 32.0 kb/s
Maximum bit rate                         : 35.7 kb/s
Channel(s)                               : 2 channels
Channel layout                           : C
Sampling rate                            : 44.1 kHz
Frame rate                               : 21.533 FPS (2048 SPF)
Compression mode                         : Lossy
Stream size                              : 5.10 MiB (11%)
Encoded date                             : UTC 2009-12-07 19:43:47
Tagged date                              : UTC 2009-12-07 19:43:47

-------- NEW MKV FILE WITH BETTER VIDEO --------
General
Complete name                            : NEW.mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 394 MiB
Duration                                 : 25 min 2 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 2 200 kb/s
Encoded date                             : UTC 2019-10-18 03:10:59
Writing application                      : mkvmerge v10.0.0 ('To Drown In You') 32bit
Writing library                          : libebml v1.3.4 + libmatroska v1.4.5

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings                          : CABAC / 5 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 5 frames
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 25 min 2 s
Bit rate                                 : 1 749 kb/s
Width                                    : 1 440 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 4:3
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.047
Stream size                              : 313 MiB (80%)
Writing library                          : x264 core 152 r2851 ba24899
Encoding settings                        : cabac=1 / ref=5 / deblock=1:1:1 / analyse=0x3:0x133 / me=umh / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=4 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=0 / open_gop=0 / weightp=2 / keyint=240 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Default                                  : Yes
Forced                                   : No

Audio
ID                                       : 2
Format                                   : FLAC
Format/Info                              : Free Lossless Audio Codec
Codec ID                                 : A_FLAC
Duration                                 : 25 min 2 s
Bit rate mode                            : Variable
Bit rate                                 : 448 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 11.719 FPS (4096 SPF)
Bit depth                                : 16 bits
Compression mode                         : Lossless
Stream size                              : 80.3 MiB (20%)
Title                                    : Main
Writing library                          : libFLAC 1.3.2 (UTC 2017-01-01)
Language                                 : Japanese
Default                                  : Yes
Forced                                   : No

I want to remux the OLD audio track from the MP4 into the MKV file.

Now, the old audio is delayed by 60 seconds, so I use 60.000 as the delay in MKVmerge and it works fine in the beginning, but then the audio gets de-synchronized with the video over time.

I understand it is because of the difference in sample rate, so I was wondering how can I fix the old audio so that I can include it in the NEW MKV file.

If it can be done with FFMPEG or some command-line tool, much better. I don't mind re-encoding the AAC.

Any pointers, tips, or ideas? Thanks!

EDIT: I keep looking around and it seems the problem is that the MP4 is 29.970fps and the MKV is 23.976fps, so I am currently searching for ways to make the AAC 23.976fps, although I am not sure that is the real problem.

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #1
The frame rate is irrelevant. The problem is that the videos have different lengths. Either someone cut some frames out of the shorter one, or they were converted differently from the original source material.

If you can figure out the ratio between the two lengths, you can try to change the new video's frame rate to match the old audio without re-encoding anything. This may not work very well if the different length is due to different cuts.

Since you mentioned adding a delay of 60 seconds, I assume there's some extra material in the new video that isn't part of the old video? Make sure you measure only the length of video that's the same in both files, or you won't get an accurate ratio.

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #2
Quote
Now, the old audio is delayed by 60 seconds, so I use 60.000 as the delay in MKVmerge and it works fine in the beginning, but then the audio gets de-synchronized with the video over time.

Calculate the offset between the video/audio at a couple different points.  If it increases linearly, you can do a simple rate adjustment in any audio editor to zero the difference in their playback rates.  If its due to the audio/video being edited differently, you might be able to make the same cuts to the audio to align them.

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #3
Use the 'Time Stretch' option in BeHappy. You preserve the pitch as well. It works well, I've used it many times.

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #4
Thanks, so apparently (and I am at work so I could only check in the morning briefly for 10 minutes during breakfast), the new version includes an additional frame here and there. So apparently, that is the problem. I need to do a more thorough check.

In any case, assuming that the videos had the same length and exact same frames, shouldn't I still re-sync the audio because of the FPS difference on the videos?

This is all totally new for me, so I am just wondering if before taking the time to edit the audio in Audacity or similar, don't I need to first re-sync to the new FPS or something like that?

Also, what tool is good to sync audio/video manually? I am not sure I have the time or the skills to do it, but in case I want to give it a try?

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #5
The FPS is the video, the number of frames per second, it doesn't matter to the audio as long as it is the same length. Your audio track can be 1 minute long, the video is 1 minute long they match, it doesn't matter is that 1 minute is 24fps or 30fps, one just contains more frames in the video.

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #6
The FPS is the video, the number of frames per second, it doesn't matter to the audio as long as it is the same length. Your audio track can be 1 minute long, the video is 1 minute long they match, it doesn't matter is that 1 minute is 24fps or 30fps, one just contains more frames in the video.
That is exactly what I understand, but apparently not? If you search in google there are lots of people having this question/problem.

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #7
I think there is a risk of over complicating this. I have altered video framerates, increasing and decreasing, and used BeHappy to 'stretch' the audio (in both directions!?!?) and had no synchronisation issues at all. As aforesaid, so long as the audio track is altered to match the new video length, all will be well. ;) Edit: Always assuming that the new video is simply a framerate adjustment of the original.

Re: Sync Old AAC audio track w/new H264 video with different sample rates?

Reply #8
In any case, assuming that the videos had the same length and exact same frames, shouldn't I still re-sync the audio because of the FPS difference on the videos?
No. If the videos are the same length, then the audio will (probably) match. You can use the mkvmerge "--default-duration" option to change the video FPS to change the video length (by speeding it up or slowing it down) without re-encoding anything, so I suggest you try that first.

The FPS is the video, the number of frames per second, it doesn't matter to the audio as long as it is the same length. Your audio track can be 1 minute long, the video is 1 minute long they match, it doesn't matter is that 1 minute is 24fps or 30fps, one just contains more frames in the video.
That is exactly what I understand, but apparently not? If you search in google there are lots of people having this question/problem.
There are a lot of ways to edit a video that change the length, the FPS, or both, or neither. You're probably finding a lot of people having a different issue than what you're having.

 
SimplePortal 1.0.0 RC1 © 2008-2021