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
-af aresample=async=1
for WAV extraction..