I converted an avi file to a mp4 file with the following command, but the converted mp4 file produced no audio when played with QuickTime (no such problem with other players). I was able to convert mkv to mp4 with the same command without the audio problem.
ffmpeg -i show.avi -vcodec libx264 -vprofile high -crf 28 -acodec copy show.mp4
However I was able to fix the problem by the following two commands (first extract the audio into a mp3 file from the mp4 file, then combine the mp4 file with the mp3 file).
ffmpeg -i show.mp4 -vn -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 show.mp3
ffmpeg -i show.mp4 -i show.mp3 show2.mp4
show2.mp4 showed no audio problems with QuickTime. Anyone has any ideas as to what was wrong with the first command?
Below is my ffmpeg info.
% ffmpeg -i show.avi -vcodec libx264 -vprofile high -crf 28 -acodec copy show.mp4
ffmpeg version N-60236-gffb000fff8-static https://johnvansickle.com/ffmpeg/ \
Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug \
--disable-ffplay --disable-indev=sndio --disable-outdev=sndio \
--cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls \
--enable-gmp --enable-libgme --enable-gray --enable-libaom \
--enable-libfribidi --enable-libass --enable-libvmaf \
--enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb \
--enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband \
--enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis \
--enable-libopus --enable-libtheora --enable-libvidstab \
--enable-libvo-amrwbenc --enable-libvpx --enable-libwebp \
--enable-libx264 --enable-libx265 --enable-libxml2 \
--enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 57. 18.100 / 57. 18.100
libavcodec 59. 20.100 / 59. 20.100
libavformat 59. 17.100 / 59. 17.100
libavdevice 59. 5.100 / 59. 5.100
libavfilter 8. 25.100 / 8. 25.100
libswscale 6. 5.100 / 6. 5.100
libswresample 4. 4.100 / 4. 4.100
libpostproc 56. 4.100 / 56. 4.100
Input #0, avi, from 'show.avi':
Metadata:
software : Nandub v1.0rc2
Duration: 01:38:52.93, start: 0.000000, bitrate: 984 kb/s
Stream #0:0: Video: msmpeg4v3 (DIV3 / 0x33564944), yuv420p, \
576x240, 842 kb/s, 23.98 fps, 23.98 tbr, 23.98 tbn
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (msmpeg4v3 (msmpeg4) -> h264 (libx264))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 @ 0x76824c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x76824c0] profile High, level 2.1, 4:2:0, 8-bit
[libx264 @ 0x76824c0] 264 - core 164 r3081 19856cc - H.264/MPEG-4 \
AVC codec - Copyleft 2003-2021 - 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_range=16 \
chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 \
fast_pskip=1 chroma_qp_offset=-2 threads=7 lookahead_threads=1 \
sliced_threads=0 nr=0 decimate=1 interlaced=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=23 \
scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 \
crf=28.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 \
aq=1:1.00
Output #0, mp4, to 'show.mp4':
Metadata:
software : Nandub v1.0rc2
encoder : Lavf59.17.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive),\
576x240, q=2-31, 23.98 fps, 11988 tbn
Metadata:
encoder : Lavc59.20.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:00.48 bitrate= \
0.8kbits/sframe= 120 fps=0.0 q=-1.0 Lsize= 148kB \
time=00:00:05.01 bitrate= 242.5kbits/s speed=21.2x
video:71kB audio:73kB subtitle:0kB other streams:0kB global headers:0kB \
muxing overhead: 3.456417%
[libx264 @ 0x76824c0] frame I:1 Avg QP: 9.52 size: 77
[libx264 @ 0x76824c0] frame P:65 Avg QP:26.99 size: 1030
[libx264 @ 0x76824c0] frame B:54 Avg QP:22.71 size: 92
[libx264 @ 0x76824c0] consecutive B-frames: 32.5% 16.7% 17.5% 33.3%
[libx264 @ 0x76824c0] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x76824c0] mb P I16..4: 0.2% 1.3% 0.1% P16..4: 13.7% 5.2% \
4.2% 0.0% 0.0% skip:75.4%
[libx264 @ 0x76824c0] mb B I16..4: 0.4% 0.2% 0.0% B16..8: 7.8% 0.4% \
0.0% direct: 0.1% skip:91.1% L0:41.8% L1:50.0% BI: 8.2%
[libx264 @ 0x76824c0] 8x8 transform intra:39.3% inter:58.4%
[libx264 @ 0x76824c0] coded y,uvDC,uvAC intra: 8.9% 6.7% 2.4% inter: 5.5% \
4.8% 1.1%
[libx264 @ 0x76824c0] i16 v,h,dc,p: 80% 9% 11% 0%
[libx264 @ 0x76824c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 10% 69% 2% 2% 2% \
1% 2% 1%
[libx264 @ 0x76824c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 13% 38% 5% 6% 6% \
5% 4% 3%
[libx264 @ 0x76824c0] i8c dc,h,v,p: 68% 14% 17% 0%
[libx264 @ 0x76824c0] Weighted P-Frames: Y:27.7% UV:15.4%
[libx264 @ 0x76824c0] ref P L0: 75.3% 11.5% 8.5% 3.4% 1.3%
[libx264 @ 0x76824c0] ref B L0: 83.8% 11.1% 5.1%
[libx264 @ 0x76824c0] ref B L1: 98.9% 1.1%
[libx264 @ 0x76824c0] kb/s:115.09
From your log I can see that your input audio is MP3.
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 128 kb/s
Most systems expect MPEG container (MP4) to hold AAC audio as standard.
The fastest fix is not to use -acodec copy
if the input video has non AAC audio.
Solution:
ffmpeg -i show.avi -vcodec libx264 -vprofile high -crf 28 show.mp4
PS:
Regarding ffmpeg -i show.mp4 -i show.mp3 show2.mp4
. It is not necessary to create a temp MP3 file. Here you are telling FFmpeg to ignore the MP3 inside show.mp4
and use the MP3 of show.mp3
which is actually the same thing.
You can achieve same result without middle step of making an MP3 file.
ffmpeg -i show.mp4 -c:v copy show2.mp4
Where the output show2.mp4
will now have AAC audio (it is default choice by FFmpeg for MP4 unless you specify a different codec).