3

I have an .MP4 file with one video track (H.264, 25 FPS) and one audio track (MP2). The total length is ~2:52 (two hours, 52 minutes). I've noticed that A/V is synchronous before ~2:34 but async afterwards, i.e. audio is late ~0.3 s.

My plan was to

  1. Extract the audio track to .MP2
  2. Cut the 0.3 s (using mp3directCut, which works fine)
  3. Mux the video track and the cut audio track.

Done. However, the result wasn't satisfying because A/V was out of sync right from the start of the video. I took a closer look at the original file and dumped the timestamps. The smallest PTS of the video track is 0.16 s, and the PTSs are all increasing by 0.04 and without any gap. The smallest PTS of the audio track is 0.212 s, and most PTSs increase by 24 ms (normal for MP2), but few diffs are smaller or greater than 24 ms (which is ok, but obviously a problem when extracting the track, see question below)

My questions are: Do I lose timestamps when extracting to MP2? Then my initial plan is foredoomed. Which other way is there to cut a small part of an audio track inside an MP4 file? Without reencoding audio, of course. I'm familiar with FFmpeg and AviDemux.

2 Answers2

2

Do I lose timestamps when extracting to MP2?

Yes. .mp2/.mp3 has no timestamps.

Which other way is there to cut a small part of an audio track inside an MP4 file?

Any container with timestamps that supports MP2 i.e. MPEG-TS, MP4/MOV, MKV. There may be others.


Try the concat demuxer,

ffmpeg -i in.mp4 -f concat -i audio.txt -map 0:v -map 1:a -c copy out.mp4

where audio.txt is

file in.mp4
outpoint 2:34:00
file in.mp4
inpoint 2:34:00.30
Gyan
  • 38,955
0

The solution was:

  1. Extract the first part of the audio track to part1.mp4
  2. Extract the second part of the audio track to part2.mp4
  3. Concat part1.mp4 and part2.mp4 to complete.mp4
  4. Mux video from the original file and audio from complete.mp4

See comments above from @Mulvya for the specific FFmpeg commands. Thanks again to him/her for the support.