I've been using FFmpeg to combine an audio file (.wav) and an image (.jpg) into a video (.mp4), the command I looked up seemed to work when testing it, so I tweaked it a bit (mostly just adding the scale argument) to fit that I needed and wrote a python script to run through the whole folder and create the videos.
They seemed fine until I noticed one was a lot longer than intended, and when I loaded all the videos & songs into VLC, every video was exactly one minute longer than the audio source was.
This is the command I've been using:
ffmpeg -loop 1 -framerate 1 -i "{image}" -i "{audio}" -c:a aac -b:a 128k -s 1080x1080 -shortest "{name}"
The curly brackets are just for python's .format()
function, I've tested it with specific files just in the command prompt and I get the same output. Here's said output for a test I did:
ffmpeg version N-91869-g5632044939 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180813
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-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 --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 19.101 / 56. 19.101
libavcodec 58. 29.100 / 58. 29.100
libavformat 58. 18.100 / 58. 18.100
libavdevice 58. 4.103 / 58. 4.103
libavfilter 7. 29.100 / 7. 29.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Input #0, image2, from 'cover.jpg':
Duration: 00:00:01.00, start: 0.000000, bitrate: 1031 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 810x810 [SAR 72:72 DAR 1:1], 1 fps, 1 tbr, 1 tbn, 1 tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, wav, from '15 Intermission ~ Applaud The Dog!.wav':
Metadata:
encoder : FL Studio 20
Duration: 00:00:16.18, bitrate: 1411 kb/s
Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[swscaler @ 0000014cab299600] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0000014cab314300] using SAR=1/1
[libx264 @ 0000014cab314300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000014cab314300] profile High, level 3.2, 4:2:0, 8-bit
[libx264 @ 0000014cab314300] 264 - core 157 r2932 303c484 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=12 lookahead_threads=2 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=1 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'vid/15 Intermission ~ Applaud The Dog!.mp4':
Metadata:
encoder : Lavf58.18.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuvj420p(pc, progressive), 1080x1080 [SAR 1:1 DAR 1:1], q=-1--1, 1 fps, 16384 tbn, 1 tbc
Metadata:
encoder : Lavc58.29.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc58.29.100 aac
frame= 76 fps= 57 q=-1.0 Lsize= 798kB time=00:01:13.00 bitrate= 89.5kbits/s speed=54.8x
video:536kB audio:256kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.658655%
[libx264 @ 0000014cab314300] frame I:1 Avg QP: 8.10 size:534314
[libx264 @ 0000014cab314300] frame P:19 Avg QP: 7.98 size: 565
[libx264 @ 0000014cab314300] frame B:56 Avg QP:13.34 size: 58
[libx264 @ 0000014cab314300] consecutive B-frames: 1.3% 0.0% 3.9% 94.7%
[libx264 @ 0000014cab314300] mb I I16..4: 5.4% 25.8% 68.8%
[libx264 @ 0000014cab314300] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 2.3% 0.0% 0.0% 0.0% 0.0% skip:97.7%
[libx264 @ 0000014cab314300] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.4% 0.0% 0.0% direct: 0.0% skip:99.6% L0: 7.5% L1:92.5% BI: 0.0%
[libx264 @ 0000014cab314300] 8x8 transform intra:25.8% inter:68.4%
[libx264 @ 0000014cab314300] coded y,uvDC,uvAC intra: 98.1% 85.1% 84.5% inter: 0.2% 0.1% 0.0%
[libx264 @ 0000014cab314300] i16 v,h,dc,p: 13% 13% 55% 18%
[libx264 @ 0000014cab314300] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 14% 12% 12% 10% 9% 10% 8% 12%
[libx264 @ 0000014cab314300] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 15% 8% 8% 10% 10% 9% 8% 10%
[libx264 @ 0000014cab314300] i8c dc,h,v,p: 35% 28% 27% 11%
[libx264 @ 0000014cab314300] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0000014cab314300] ref P L0: 98.6% 0.0% 1.2% 0.2%
[libx264 @ 0000014cab314300] ref B L0: 5.4% 94.6%
[libx264 @ 0000014cab314300] kb/s:57.72
[aac @ 0000014cab28c740] Qavg: 145.257
I can't for the life of me figure out why this is happening, would anyone know and have a solution? Again, this happens with every audio file I try and with different images as well.