Opened 4 years ago
Closed 2 years ago
#8489 closed defect (fixed)
MP4 file has too short audio
Reported by: | Michael Koch | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | undetermined |
Version: | git-master | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
How to reproduce:
Step 1: Make a 6 seconds test video with 1kHz tone. The file is ok when played.
ffmpeg -f lavfi -i testsrc2=size=vga -f lavfi -i sine=1000 -t 6 -y video.mp4
Step 2: Make a 10 seconds audio file with silence and a short 3kHz tone at t=3s. The file is ok when played.
ffmpeg -f lavfi -i "sine=3000:duration=0.1" -af adelay=3000,apad -t 10 -y audio.wav
Step 3: Combine both files into one video, and the audio sources shall be mixed:
ffmpeg -i video.mp4 -i audio.wav -filter_complex "[0:a][1:a]amix=weights='1.0 1.0'" -shortest -y out.mp4
The output video has the correct length 6s, but unexpectedly the audio length is only 4s. The last 2s are silence.
Known workarounds to solve the problem: add -c:v mpeg4, or use out.nut as output filename
Below is the console output for step 3:
F:\Test_Audio>c:\ffmpeg\ffmpeg -i video.mp4 -i audio.wav -filter_complex "[0:a][
1:a]amix=weights='1.0 1.0'" -shortest -y out.mp4
ffmpeg version git-2020-01-15-0dc0837 Copyright (c) 2000-2020 the FFmpeg develop
ers
built with gcc 9.2.1 (GCC) 20200111
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi
g --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libb
luray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --e
nable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable
-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 -
-enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enab
le-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --en
able-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcode
c --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 -
-enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 38.100 / 56. 38.100
libavcodec 58. 65.103 / 58. 65.103
libavformat 58. 35.102 / 58. 35.102
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 71.100 / 7. 71.100
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.35.102
Duration: 00:00:06.02, start: 0.000000, bitrate: 938 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480 [
SAR 1:1 DAR 4:3], 864 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp,
68 kb/s (default)
Metadata:
handler_name : SoundHandler
Guessed Channel Layout for Input Stream #1.0 : mono
Input #1, wav, from 'audio.wav':
Metadata:
encoder : Lavf58.35.102
Duration: 00:00:10.00, bitrate: 705 kb/s
Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16,
705 kb/s
Stream mapping:
Stream #0:1 (aac) -> amix:input0 (graph 0)
Stream #1:0 (pcm_s16le) -> amix:input1 (graph 0)
amix (graph 0) -> Stream #0:0 (aac)
Stream #0:0 -> #0:1 (h264 (native) -> h264 (libx264))
Press [q] to stop, ? for help
[libx264 @ 00000000029d7540] using SAR=1/1
[libx264 @ 00000000029d7540] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX FMA3 BMI2 AVX2
[libx264 @ 00000000029d7540] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 00000000029d7540] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft
2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1
:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_rang
e=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_
offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interla
ced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias
=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40
intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpma
x=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.35.102
Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 k
b/s (default)
Metadata:
encoder : Lavc58.65.103 aac
Stream #0:1(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x48
0 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.65.103 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 111 fps=0.0 q=28.0 size= 256kB time=00:00:02.36 bitrate= 885.6kbits/
frame= 150 fps=141 q=-1.0 Lsize= 635kB time=00:00:06.01 bitrate= 864.7kbits
/s speed=5.66x
video:612kB audio:17kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 0.982628%
[aac @ 00000000029dbb40] Qavg: 62202.113
[libx264 @ 00000000029d7540] frame I:1 Avg QP:18.28 size: 9171
[libx264 @ 00000000029d7540] frame P:47 Avg QP:25.28 size: 5109
[libx264 @ 00000000029d7540] frame B:102 Avg QP:29.85 size: 3690
[libx264 @ 00000000029d7540] consecutive B-frames: 2.0% 13.3% 26.0% 58.7%
[libx264 @ 00000000029d7540] mb I I16..4: 45.2% 42.3% 12.5%
[libx264 @ 00000000029d7540] mb P I16..4: 1.5% 5.5% 0.8% P16..4: 11.1% 5.0
% 2.8% 0.0% 0.0% skip:73.3%
[libx264 @ 00000000029d7540] mb B I16..4: 0.2% 0.1% 0.5% B16..8: 14.1% 3.7
% 0.9% direct: 1.7% skip:78.6% L0:49.5% L1:44.3% BI: 6.2%
[libx264 @ 00000000029d7540] 8x8 transform intra:56.4% inter:25.6%
[libx264 @ 00000000029d7540] coded y,uvDC,uvAC intra: 19.1% 27.7% 26.1% inter: 4
.0% 9.1% 7.5%
[libx264 @ 00000000029d7540] i16 v,h,dc,p: 71% 19% 8% 1%
[libx264 @ 00000000029d7540] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 12% 75% 0% 0%
0% 0% 0% 0%
[libx264 @ 00000000029d7540] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 22% 33% 7% 3%
4% 4% 6% 4%
[libx264 @ 00000000029d7540] i8c dc,h,v,p: 71% 11% 17% 2%
[libx264 @ 00000000029d7540] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000000029d7540] ref P L0: 56.9% 7.7% 22.6% 12.9%
[libx264 @ 00000000029d7540] ref B L0: 74.2% 21.4% 4.4%
[libx264 @ 00000000029d7540] ref B L1: 94.6% 5.4%
[libx264 @ 00000000029d7540] kb/s:834.26
Attachments (2)
Change History (10)
by , 4 years ago
by , 4 years ago
comment:2 by , 4 years ago
Another known workaround is to pad the first audio input with a single sample at the end:
ffmpeg -i video.mp4 -i video.mp4 -lavfi "[0:a]apad=pad_len=1[p];[p][1:a]amix=weights='1.0 0.1'" -y out.mp4
comment:3 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
The problem seems to be solved now.
comment:4 by , 4 years ago
Component: | ffmpeg → undetermined |
---|---|
Resolution: | fixed → invalid |
out.mp4 are identical here for 0dc08379 and 05039c13
comment:5 by , 4 years ago
I did check with a Windows 64-bit version from Zeranoe about 10 days ago, and the problem was reproducible (as it was with all other versions since I reported the problem). Now with the version from 2020-04-12 it's fixed. I did check with the simpler example that I posted in comment 1.
comment:6 by , 4 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Sorry for the confusion. I did check the wrong output file. The problem is still reproducible with all versions.
comment:7 by , 3 years ago
This example has the wrong audio output:
ffmpeg -f lavfi -i testsrc2=size=vga -f lavfi -i sine=1000 -t 6 -y video.mp4
ffmpeg -i video.mp4 -i video.mp4 -lavfi "amix=weights='1.0 0.1'" -y out.mp4
But if I use a *.mov as input file, then it works:
ffmpeg -f lavfi -i testsrc2=size=vga -f lavfi -i sine=1000 -t 6 -y video.mov
ffmpeg -i video.mov -i video.mov -lavfi "amix=weights='1.0 0.1'" -y out.mp4
Michael
comment:8 by , 2 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
I don't know when and how, but the issue is fixed now.
Here is a simpler example for reproducing the problem, only two steps are required:
ffmpeg -f lavfi -i testsrc2=size=vga -f lavfi -i sine=1000 -t 6 -y video.mp4
ffmpeg -i video.mp4 -i video.mp4 -filter_complex "[0:a][1:a]amix=weights='1.0 0.1'" -y out.mp4
You can hear that the audio from the first input ends too early at 4s. But both input files are the same and have 6s audio.
I've added video.mp4 and out.mp4 for this example.
Known workaround: add -c:v mpeg4