Log in

View Full Version : [SOLVED] A/V synch problems when trying to correct video from Android phone


Dacicus
19th June 2012, 23:05
Hello. I have an MP4 file that was recorded on a Nexus S 4G phone by a family member. The file plays back well on the device, but it is upside-down when copied to a PC via USB. I would like to rotate it so it displays properly on the PC.

Some online searching showed that MP4Box can extract the elementary streams from an MP4 file, so I used its -raw option to do so. This produced an .h264 and an .aac file. I ran the former through DGAVCIndex to produce a .dga file and then composed the following AviSynth file:
LoadPlugin("DGAVCDecode.dll")
LoadPlugin("BassAudio.dll")
AVCSource("VID_20120527_172827_track1.dga")
FlipVertical()
FlipHorizontal()
a = last
b = bassAudioSource("VID_20120527_172827_track2.aac")
AudioDub(a, b)

This fixed the upside-down video, but the audio and video were out of synch when previewed in VirtualDub, with the audio starting much too early. AviSynth's AssumeFPS function looked useful, and I calculated an FPS of 30.00865 (=7000/233.266) based on the following output of mp4box -info for the original MP4 file:
* Movie Info *
Timescale 1000 - Duration 00:03:53.792
Fragmented File no - 2 track(s)
File Brand isom - version 0
Created: GMT Fri Jul 03 07:00:38 2082

File has no MPEG4 IOD/OD

Track # 1 Info - TrackID 1 - TimeScale 90000 - Duration 00:03:53.266
Media Info: Language "Undetermined" - Type "vide:avc1" - 7000 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 720 x 480 - Profile Baseline @ Level 3.1
NAL Unit length bits: 32
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 16000 - Duration 00:03:53.792
Media Info: Language "Undetermined" - Type "soun:mp4a" - 3653 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 1 Channel(s) - SampleRate 16000
Synchronized on stream 1

Adding AssumeFPS(30.00865) after FlipHorizontal() improves the synch, but now the audio is slightly too late, as is it with AssumeFPS(30).

I'd like any input about what I am doing wrong in this process. Thanks!

Guest
20th June 2012, 01:35
Don't use AssumeFPS() for a constant delay offset. Use DelayAudio().

If the desync increase as the file plays we have another issue. Does the desync remain constant?

What frame rate does DGAVCIndex report?

Dacicus
20th June 2012, 04:52
The desynch does increase as the file plays. DGAVCIndex says that the .h264 file has a frame rate of 25.000 fps.

Guest
20th June 2012, 05:06
>The desynch does increase as the file plays.

OK, but with what AssumeFPS() value?

You have to find the original frame rate and then AssumeFPS() that, followed by fixing the offset with DelayAudio().

The frame rate of the MP4 is 30 fps (confirmed with web search). DGAVCIndex reports 25 because there is no VUI to specify the frame rate and so it defaults to 25 fps.

So, set AssumeFPS(30) and use DelayAudio() to fix the offset.

AVCSource("VID_20120527_172827_track1.dga")
AssumeFPS(30)
FlipVertical()
vid=FlipHorizontal()
aud=bassAudioSource("VID_20120527_172827_track2.aac").DelayAudio(???) # replace ??? with correct offset
AudioDub(vid,aud)

Dacicus
23rd June 2012, 18:30
>The desynch does increase as the file plays.

OK, but with what AssumeFPS() value?That was without any AssumeFPS() value specified.

So, set AssumeFPS(30) and use DelayAudio() to fix the offset.
That worked! Thank you very much!