0

I have an .mp4 video encoded in H264 and AAC. I extracted the audio so that I could make some changes in Audacity and use ffmpeg to combine the video and new audio. But it turned out that while the video was 12:40.92 long, the extracted audio was only 12:30.59 long. The shortening happened when I converted the audio from AAC to WAV -- didn't matter whether ffmpeg converted, or I just extracted an .m4a file using ffmpeg then imported it into Audacity.

When I created the new video file, I was able to solve the problem by lengthening the audio (-filter:a "atempo=0.986424"). But I don't understand what was "wrong" with the extracted audio. Audacity and ffmpeg both shortened, so it doesn't appear to be anyone's "fault".

Anyone have any thoughts? Is there a property in the .m4a file controlling this? If so, how can I view that property?

Details:

ffprobe reports the video's duration as 12:40:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
Duration: 00:12:40.92, start: 0.000000, bitrate: 1432 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1245 kb/s, 29.56 fps, 59.94 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
    handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 177 kb/s (default)
    Metadata:
    handler_name    : SoundHandler

If I extract the audio (ffmpeg -i video.mp4 -vn -c:a copy audio.m4a), the .m4a filesize is 17,095,597 B and the duration is 12:40:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'audio.m4a':
Metadata:
    major_brand     : M4A 
    minor_version   : 512
    compatible_brands: isomiso2
    encoder         : Lavf58.20.100
Duration: 00:12:40.92, start: 0.000000, bitrate: 179 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 177 kb/s (default)
    Metadata:
    handler_name    : SoundHandler

Now we convert the .m4a to WAV (ffmpeg -i audio.m4a audio.wav):

Output #0, wav, to 'audio.wav':
Metadata:
    major_brand     : M4A 
    minor_version   : 512
    compatible_brands: isomiso2
    ISFT            : Lavf58.20.100
    Stream #0:0(und): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s (default)
    Metadata:
    handler_name    : SoundHandler
    encoder         : Lavc58.35.100 pcm_s16le
size=  129300kB time=00:12:40.91 bitrate=1392.0kbits/s speed= 964x    
video:0kB audio:129300kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000059%

But ffprobe now shows the duration has been shortened to 12:30:

Input #0, wav, from 'audio.wav':
Metadata:
    encoder         : Lavf58.20.100
Duration: 00:12:30.59, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
  • The audio stream likely doesn't represent a continuous timeline. In MP4/M4A, those gaps were preserved using timestamps but WAV doesn't have timestamps. Add -af aresample=async=1 for WAV extraction.. – Gyan Jan 26 at 4:55
  • @Gyan Thank you very much. You're correct -- I printed some frames w/ ffprobe and found small audio gaps. async fixed it, although I did have to bump it up to 1000. If you re-post, I can mark as an answer. – tenshing Jan 28 at 20:11
0

do you want to extract the aac audio?, this is imposible.

the audio time is 00:12:30.59 (00 hours, 12 minits and 30 seconds and 59 miliseconds) the video time is 00:12:40.92, start: 0.000000 (00 hours, 12 minits and 40 seconds and 92 miliseconds)

you have to copy the audio into a new file like only_audio.mp4 and the same for video into a only_video.mp4 try some like this

ffmpeg -i video.mp4 -map 0:0 -map 0:1 -c copy -an only_video.mp4 

will created a file called only_video.mp4 with a duration of 00:12:40.92

ffmpeg -i video.mp4 -map 0:0 -map 0:1 -vn -c copy -strict -2 only_audio.mp4

will created a file called only_audio.mp4 with a duration of 00:12:30.59

ok... edit your only_audio.mp4 file... and check if the file edited is "aac" and his time, (in theory have to be) 00:12:40.92

TE CONCLUTION; THE AUDIO FILE IS 00:00:10.33 SECONDS MORE SMALLED than only_video.mp4...

yo have to use -itsoffset

ffmpeg -i "only_video.mp4" -itsoffset 00:00:10.33 -i "only_audio.mp4" -map 0:v -map 1:a -c copy -strict -2 "problem_end.mp4"

ok amiwo, afloja y largate unos dolares que i want the ultimate mac, if this was ok, send a email xear.div@gmail.com thanks regards!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.