ffmpeg : audio + image to video : reduce time and space it takes - ffmpeg

I am using FFMPEG to convert an image and an audio to a video.
I am able to achieve the final video using the following command (Attaching the output of the command too) :
time ffmpeg -loop 1 -i inputImage.jpg -i inputAudio.mp3 -c:v libx264 -
c:a copy -shortest output1.mp4
ffmpeg version 4.1.3-0york1~16.04 Copyright (c) 2000-2019 the FFmpeg
developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
configuration: --prefix=/usr --extra-version='0york1~16.04' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-nonfree --enable-libfdk-aac --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, image2, from 'inputImage.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 32003 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 4160x2340 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
[mp3 # 0x55cd4bed0f80] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from 'inputAudio.mp3':
Duration: 00:00:23.77, start: 0.000000, bitrate: 127 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, mono, fltp, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 # 0x55cd4bee9c80] using SAR=1/1
[libx264 # 0x55cd4bee9c80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x55cd4bee9c80] profile High, level 6.0
[libx264 # 0x55cd4bee9c80] 264 - core 155 r2917 0a84d98 - 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=6 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=25 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 'output1.mp4':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuvj420p(pc), 4160x2340 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc58.35.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 128 kb/s
frame= 647 fps= 21 q=28.0 Lsize= 1302kB time=00:00:23.76 bitrate= 449.0kbits/s speed=0.778x
video:908kB audio:371kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.797463%
[libx264 # 0x55cd4bee9c80] frame I:3 Avg QP:12.36 size:235361
[libx264 # 0x55cd4bee9c80] frame P:163 Avg QP:17.66 size: 469
[libx264 # 0x55cd4bee9c80] frame B:481 Avg QP:20.95 size: 336
[libx264 # 0x55cd4bee9c80] consecutive B-frames: 0.8% 0.3% 0.0% 98.9%
[libx264 # 0x55cd4bee9c80] mb I I16..4: 60.6% 37.5% 1.9%
[libx264 # 0x55cd4bee9c80] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.3% 0.0% 0.0% 0.0% 0.0% skip:99.7%
[libx264 # 0x55cd4bee9c80] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.2% 0.0% 0.0% direct: 0.0% skip:99.8% L0:46.7% L1:53.3% BI: 0.0%
[libx264 # 0x55cd4bee9c80] 8x8 transform intra:36.9% inter:94.7%
[libx264 # 0x55cd4bee9c80] coded y,uvDC,uvAC intra: 29.0% 60.8% 5.5% inter: 0.0% 0.1% 0.0%
[libx264 # 0x55cd4bee9c80] i16 v,h,dc,p: 19% 67% 14% 0%
[libx264 # 0x55cd4bee9c80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 8% 42% 41% 1% 0% 0% 0% 0% 8%
[libx264 # 0x55cd4bee9c80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 60% 5% 0% 0% 0% 0% 0% 0%
[libx264 # 0x55cd4bee9c80] i8c dc,h,v,p: 24% 56% 16% 5%
[libx264 # 0x55cd4bee9c80] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 # 0x55cd4bee9c80] ref P L0: 96.2% 0.0% 1.8% 2.0%
[libx264 # 0x55cd4bee9c80] ref B L0: 87.7% 8.6% 3.7%
[libx264 # 0x55cd4bee9c80] ref B L1: 98.5% 1.5%
[libx264 # 0x55cd4bee9c80] kb/s:291.81
real 0m30.671s
user 1m50.724s
sys 0m0.348s
Here are the respected sizes of inputs and output:
inputImage.jpg : 160kb
inputAudio.mp3 : 380.3kb
output1.mp4 : 1.3MB
The size of output video is pretty large as compared to the input audio. This is my first issue.
Secondly, as you can see, this process takes ~30sec, which is too much I think.
How do I solve this two problems?
reducing the output video file size
reducing the time this process takes.
I've gone through numerous online links, including a lot of questions on this forum for the past several hours but still not able to solve this.
Tried playing with framerate but disturbs the duration of the output video.
Can someone please help here. Let me know if any other information is needed.
1 thing that helped me reduce the size of final video from 3MB to 1.2MB was to compress the image that I am using.

Both your issues are due to the same cause. FFmpeg has generated the video by repeating the image 647 times. Your output file has 647 video frames at 21 FPS. This info is displayed in your console output.
frame= 647 fps= 21 q=28.0 Lsize= 1302kB time=00:00:23.76 bitrate= 449.0kbits/s speed=0.778x
You can optimise this by one or more of the following ways
Decrease output video resolution (-s lower-resolution)
Decrease output video bitrate (-vb lower-video-bitrate)
Decrease output FPS (-r lower-frame-rate)

Related

Why duration of the mp4 file created with ffmpeg from png files is smaller than expected?

I'm trying to concatenate a bunch of png files into one mp4 file using ffmpeg. I use following command:
ffmpeg -f concat -i concat.txt -f mp4 out.mp4
The "description file" (concat.txt) looks like this:
file screen_001.png
duration 0.14538311958312988
file screen_002.png
duration 0.11382007598876953
file screen_003.png
duration 2.543360710144043
...
file screen_036.png
duration 0.15303301811218262
file screen_037.png
duration 0.160630464553833
file screen_038.png
duration 3.2751874923706055
Given command works, I'm able to create desired mp4 file. The problem is, the duration of the output file is smaller than sum of the duration lines from concat.txt. I expect mp4 file ~22.48s long but I get 19.20s long file.
What am I doing wrong? Maybe I'm not using some flag I should? Is it even possible to do what I want? I'm kind a newbie with ffmpeg and video manipulation at all so any help would be appreciated.
Output of the ffmpeg, maybe will be useful:
root#65181939e08e:/files/tmp# ffmpeg -f concat -i concat.txt -f mp4 out.mp4
ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, concat, from 'concat.txt':
Duration: 00:00:22.48, start: 0.000000, bitrate: 0 kb/s
Stream #0:0: Video: png, rgba(pc), 1366x768, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 # 0x5651f1a6e8c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x5651f1a6e8c0] profile High 4:4:4 Predictive, level 3.2, 4:4:4 8-bit
[libx264 # 0x5651f1a6e8c0] 264 - core 155 r2917 0a84d98 - 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=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 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=25 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 'out.mp4':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv444p, 1366x768, q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc58.35.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 483 fps=199 q=-1.0 Lsize= 258kB time=00:00:19.20 bitrate= 110.2kbits/s dup=445 drop=0 speed=7.89x
video:252kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.564829%
[libx264 # 0x5651f1a6e8c0] frame I:5 Avg QP: 7.86 size: 28761
[libx264 # 0x5651f1a6e8c0] frame P:121 Avg QP:14.58 size: 729
[libx264 # 0x5651f1a6e8c0] frame B:357 Avg QP:13.34 size: 70
[libx264 # 0x5651f1a6e8c0] consecutive B-frames: 1.2% 0.0% 1.9% 96.9%
[libx264 # 0x5651f1a6e8c0] mb I I16..4: 88.2% 0.0% 11.8%
[libx264 # 0x5651f1a6e8c0] mb P I16..4: 1.3% 0.0% 0.3% P16..4: 0.2% 0.0% 0.0% 0.0% 0.0% skip:98.1%
[libx264 # 0x5651f1a6e8c0] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.9% 0.0% 0.0% direct: 0.0% skip:99.1% L0:59.4% L1:40.6% BI: 0.0%
[libx264 # 0x5651f1a6e8c0] coded y,u,v intra: 7.9% 0.7% 1.3% inter: 0.0% 0.0% 0.0%
[libx264 # 0x5651f1a6e8c0] i16 v,h,dc,p: 81% 18% 1% 0%
[libx264 # 0x5651f1a6e8c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 28% 22% 2% 3% 3% 3% 3% 3%
[libx264 # 0x5651f1a6e8c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 # 0x5651f1a6e8c0] ref P L0: 72.5% 11.9% 12.4% 3.1%
[libx264 # 0x5651f1a6e8c0] ref B L0: 50.4% 48.1% 1.4%
[libx264 # 0x5651f1a6e8c0] ref B L1: 98.9% 1.1%
[libx264 # 0x5651f1a6e8c0] kb/s:106.45
Thanks for your help!
Create a video from each png like this:
ffmpeg -f image2 -loop 1 -i 01.png -r 30 -t 00:00:05.000 -pix_fmt yuv420p 01.mp4
Where:
"-r 30" is frame rate
"-t 00:00:05.000" is the time of this PNG in the video, in this case 5 seconds, looking this the floating point is 3 :(
Anyway, make this for each video and to concat it, create a txt:
concat.txt
file '01.mp4'
file '02.mp4'
And use ffmpeg to concat all files
ffmpeg -f concat -safe 0 -i concat.txt -c copy output.mp4
Good luck!
Edit in the docs are in microseconds too, maybe float point is 6 and not 3:
http://www.ffmpeg.org/ffmpeg-utils.html#time-duration-syntax

Bad output from ffmpeg running on raw video from Wear OS device

I am following these instructions regarding capturing and converting video from a Wear OS device, and I am running into problems. I get a video and I can tell it is my screen but it seems to be warped. This should be a green check with some white text.
There is a lot of noise when I run this:
ffmpeg -f rawvideo -vcodec rawvideo -s 400x400 -pix_fmt rgb24 -r 10 -i video.raw -an -c:v libx264 -pix_fmt yuv420p video.mp4
Here
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.3 (clang-1103.0.32.62)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
[rawvideo # 0x7fbcec008200] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from 'video.raw':
Duration: 00:00:07.00, start: 0.000000, bitrate: 38566 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 400x400, 38400 kb/s, 10 tbr, 10 tbn, 10 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 # 0x7fbce980d400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x7fbce980d400] profile High, level 2.1, 4:2:0, 8-bit
[libx264 # 0x7fbce980d400] 264 - core 159 r2999 296494a - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - 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=10 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 'video.mp4':
Metadata:
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 400x400, q=-1--1, 10 fps, 10240 tbn, 10 tbc
Metadata:
encoder : Lavc58.91.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[rawvideo # 0x7fbcec008200] Packet corrupt (stream = 0, dts = 70).
video.raw: corrupt input packet in stream 0
[rawvideo # 0x7fbce980c800] Invalid buffer size, packet size 145920 < expected frame_size 480000
Error while decoding stream #0:0: Invalid argument
frame= 70 fps=0.0 q=-1.0 Lsize= 90kB time=00:00:06.70 bitrate= 110.3kbits/s speed=46.5x
video:89kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.788509%
[libx264 # 0x7fbce980d400] frame I:4 Avg QP:15.11 size: 8077
[libx264 # 0x7fbce980d400] frame P:26 Avg QP:12.39 size: 2159
[libx264 # 0x7fbce980d400] frame B:40 Avg QP: 9.83 size: 40
[libx264 # 0x7fbce980d400] consecutive B-frames: 21.4% 5.7% 4.3% 68.6%
[libx264 # 0x7fbce980d400] mb I I16..4: 53.0% 3.3% 43.6%
[libx264 # 0x7fbce980d400] mb P I16..4: 9.2% 2.0% 11.1% P16..4: 2.4% 1.3% 0.3% 0.0% 0.0% skip:73.7%
[libx264 # 0x7fbce980d400] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 1.5% 0.0% 0.0% direct: 0.1% skip:98.4% L0:24.1% L1:75.9% BI: 0.0%
[libx264 # 0x7fbce980d400] 8x8 transform intra:6.5% inter:9.8%
[libx264 # 0x7fbce980d400] coded y,uvDC,uvAC intra: 26.1% 44.1% 43.9% inter: 0.3% 0.8% 0.7%
[libx264 # 0x7fbce980d400] i16 v,h,dc,p: 89% 5% 5% 0%
[libx264 # 0x7fbce980d400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 10% 22% 67% 0% 0% 0% 0% 0% 1%
[libx264 # 0x7fbce980d400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 69% 10% 0% 1% 0% 5% 0% 1%
[libx264 # 0x7fbce980d400] i8c dc,h,v,p: 59% 41% 0% 0%
[libx264 # 0x7fbce980d400] Weighted P-Frames: Y:30.8% UV:30.8%
[libx264 # 0x7fbce980d400] ref P L0: 83.0% 3.1% 13.0% 0.5% 0.5%
[libx264 # 0x7fbce980d400] kb/s:102.92
Any ideas?

ffmpeg convert cdg/mp3 to mp4 but cdg track is always sped up by a second

I've tried this:
"C:\Program Files\ffmpeg-4.2.1-win64-static\bin\ffmpeg" -i %1 -i %2 -b:v 1M -y -speed 2 "%~dpn1.mp4"
"C:\Program Files\ffmpeg-4.2.1-win64-static\bin\ffmpeg" -i %1 -i %2 -pix_fmt yuv420p -vcodec libx264 -async 1 -speed 2 "%~dpn1.mp4"
Always same result. The file and quality are great, but obv since its karaoke... the lyrics need to match the timing and the converted files lyrics track is always about a full second or so ahead from when I play the original in a Karaoke program. Any ideas on what settings I could play with to help with this?
Both the original and the converted have the same play length at the end though. so the mp3 track seems to be ok.
EDIT: Added cmd output
"C:\Program Files\ffmpeg-4.2.1-win64-static\bin\ffmpeg" -i "A:\25 Karaoke\English\Linkin Park - In The End [SF Karaoke].cdg" -i "A:\25 Karaoke\English\Linkin Park - In The End [SF Karaoke].mp3" -b:v 1M -y -speed 2 "LP_inTheEnd.mp4"
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.1.1 (GCC) 20190807
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --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 --enable-libopenmpt
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, cdg, from 'A:\25 Karaoke\English\Linkin Park - In The End [SF Karaoke].cdg':
Duration: 00:03:56.21, start: 0.480000, bitrate: 57 kb/s
Stream #0:0: Video: cdgraphics, pal8, 300x216, 300 fps, 300 tbr, 300 tbn, 300 tbc
[mp3 # 000001bb3c14bb40] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from 'A:\25 Karaoke\English\Linkin Park - In The End [SF Karaoke].mp3':
Metadata:
title : In The End [SF Karaoke]
artist : Linkin Park
comment : http://www.otslabs.com/
Duration: 00:03:56.26, start: 0.000000, bitrate: 128 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
Codec AVOption speed () specified for output file #0 (LP_inTheEnd.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
Stream #0:0 -> #0:0 (cdgraphics (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (mp3 (mp3float) -> aac (native))
Press [q] to stop, [?] for help
[libx264 # 000001bb3c13bc00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 000001bb3c13bc00] profile High 4:4:4 Predictive, level 3.1, 4:4:4, 8-bit
[libx264 # 000001bb3c13bc00] 264 - core 158 r2984 3759fcb - 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_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=1000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'LP_inTheEnd.mp4':
Metadata:
encoder : Lavf58.29.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv444p(progressive), 300x216, q=-1--1, 1000 kb/s, 300 fps, 19200 tbn, 300 tbc
Metadata:
encoder : Lavc58.54.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc58.54.100 aac
More than 1000 frames duplicated
More than 10000 frames duplicated 2048kB time=00:00:42.16 bitrate= 397.9kbits/s dup=9625 drop=0 speed=11.5x
frame=59170 fps=3226 q=-1.0 Lsize= 11887kB time=00:03:56.26 bitrate= 412.2kbits/s dup=43525 drop=0 speed=12.9x
video:7749kB audio:3340kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.203599%
[libx264 # 000001bb3c13bc00] frame I:242 Avg QP: 0.26 size: 17214
[libx264 # 000001bb3c13bc00] frame P:16651 Avg QP: 0.14 size: 164
[libx264 # 000001bb3c13bc00] frame B:42277 Avg QP: 0.25 size: 25
[libx264 # 000001bb3c13bc00] consecutive B-frames: 2.7% 4.9% 3.8% 88.6%
[libx264 # 000001bb3c13bc00] mb I I16..4: 73.7% 1.6% 24.7%
[libx264 # 000001bb3c13bc00] mb P I16..4: 0.1% 0.0% 0.1% P16..4: 0.4% 0.0% 0.0% 0.0% 0.0% skip:99.4%
[libx264 # 000001bb3c13bc00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.3% 0.0% 0.0% direct: 0.0% skip:99.7% L0:44.2% L1:55.6% BI: 0.2%
[libx264 # 000001bb3c13bc00] final ratefactor: -19.48
[libx264 # 000001bb3c13bc00] 8x8 transform intra:1.5% inter:14.0%
[libx264 # 000001bb3c13bc00] coded y,u,v intra: 14.1% 14.8% 14.9% inter: 0.0% 0.0% 0.0%
[libx264 # 000001bb3c13bc00] i16 v,h,dc,p: 90% 0% 9% 0%
[libx264 # 000001bb3c13bc00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 14% 63% 0% 0% 0% 0% 0% 1%
[libx264 # 000001bb3c13bc00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 55% 15% 16% 1% 2% 3% 3% 2% 2%
[libx264 # 000001bb3c13bc00] Weighted P-Frames: Y:0.2% UV:0.2%
[libx264 # 000001bb3c13bc00] ref P L0: 97.9% 0.9% 1.0% 0.2%
[libx264 # 000001bb3c13bc00] ref B L0: 99.6% 0.4% 0.0%
[libx264 # 000001bb3c13bc00] ref B L1: 99.9% 0.1%
[libx264 # 000001bb3c13bc00] kb/s:321.80
[aac # 000001bb3c172e40] Qavg: 6813.878
try:
ffmpeg -itsoffset 1 -i "Linkin Park - In The End [SF Karaoke].cdg" -itsoffset 0 -i "Linkin Park - In The End [SF Karaoke].mp3" -b:v 1M -y -speed 2 "LP_inTheEnd.mp4"
that's your original command (though without the windows-specific bits) adjusted with a timestamp offset of 1 on the video and zero on the audio, so that the video should delay one second but the audio should not.

FFMPEG 'Fontconfig error: Cannot load default config file' error Windows

I am trying to make a short video in FFMPEG, where a word stays on screen for the duration of the video (0.5s). My FFMPEG code looks like this:
ffmpeg -f lavfi -i color=c=white:s=320x240:d=0.5 -vf "drawtext=fontfile= ‘c\:\Windows\fonts\calibri.ttf':fontsize=18: fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text='word'" output.mp4
However, I keep getting the following error (see below for full output):
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 # 000001c2918cef00] Using "C:/Windows/fonts/mingliub.ttc"
I figured it had something to do with the path to the font file. I also tried copying the font file to my FFMPEG map and map the font path to the FFMPEG directory:
ffmpeg -f lavfi -i color=c=white:s=320x240:d=0.5 -vf
"drawtext=fontfile=‘C:\FFMPEG\bin\calibri.ttf':fontsize=18:
fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text='word'" output.mp4'
This doesn't work either. I do get an output video.mp4 video, but the font is wrong. Here is the full output I get. It is the same for both code examples above:
c:\FFMPEG\bin>ffmpeg -f lavfi -i color=c=white:s=320x240:d=0.5 -vf "drawtext=fontfile= ‘c\\:\\\Windows\\\fonts\\\calibri.ttf':fontsize=18: fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text='word'" output.mp4
ffmpeg version N-93234-g2e67f751b5 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20190212
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --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 --enable-libopenmpt
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.102 / 58. 47.102
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, lavfi, from 'color=c=white:s=320x240:d=0.5':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 # 00000291ad7def00] Using "C:/Windows/fonts/mingliub.ttc"
[libx264 # 00000291af0ef180] using SAR=1/1
[libx264 # 00000291af0ef180] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 00000291af0ef180] profile High, level 1.3, 4:2:0, 8-bit
[libx264 # 00000291af0ef180] 264 - core 157 r2935 545de2f - 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=6 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=25 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 'output.mp4':
Metadata:
encoder : Lavf58.26.101
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc58.47.102 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[Parsed_color_0 # 00000291af0aa840] EOF timestamp not reliable
frame= 13 fps=0.0 q=-1.0 Lsize= 2kB time=00:00:00.40 bitrate= 43.9kbits/s speed=4.27x
video:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 84.991570%
[libx264 # 00000291af0ef180] frame I:1 Avg QP: 9.22 size: 306
[libx264 # 00000291af0ef180] frame P:3 Avg QP:11.33 size: 20
[libx264 # 00000291af0ef180] frame B:9 Avg QP:12.67 size: 14
[libx264 # 00000291af0ef180] consecutive B-frames: 7.7% 0.0% 0.0% 92.3%
[libx264 # 00000291af0ef180] mb I I16..4: 98.7% 0.0% 1.3%
[libx264 # 00000291af0ef180] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:100.0%
[libx264 # 00000291af0ef180] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.0% 0.0% 0.0% direct: 0.0% skip:100.0%
[libx264 # 00000291af0ef180] 8x8 transform intra:0.0%
[libx264 # 00000291af0ef180] coded y,uvDC,uvAC intra: 1.0% 0.0% 0.0% inter: 0.0% 0.0% 0.0%
[libx264 # 00000291af0ef180] i16 v,h,dc,p: 92% 1% 7% 0%
[libx264 # 00000291af0ef180] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 3% 42% 2% 5% 5% 2% 2% 2%
[libx264 # 00000291af0ef180] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 # 00000291af0ef180] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 # 00000291af0ef180] kb/s:7.65
2019 Windows builds seem to have changed syntax or something again; here's what works for me today:
-vf "drawtext=fontfile=C\\:/Windows/fonts/consola.ttf:fontsize=72:fontcolor='white':timecode='00\:00\:00\:00':rate=25:text='TCR\:':boxcolor=0x000000AA:box=1:x=860-text_w/2:y=960"
In my case, I'm running FFmpeg from PWD not C: so I have to specify font path C:\ with escaped colon and forward-slash for path.
SOLVED! Apparently the problem was that the path to the font cannot contain a semicolon (i.e., "C:/". The code that worked is:
ffmpeg -f lavfi -i color=c=white:s=320x240:d=0.5 -vf “drawtext=fontfile= /Windows/fonts/calibri.ttf:fontsize=18: fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=word” output.mp4
If you are trying to get the font using script/program, you should additionally escape backslashes.This path worked for me:
const FONT_FILE = 'C\\\\:/Windows/Fonts/arial.ttf';

ffmpeg video slideshow only takes first image

I wanted to create an .mp4 video with a framerate of 1 fps out of 10 images. I followed https://trac.ffmpeg.org/wiki/Slideshow and got to (my images are in the folder I am running the command from and are name img000.png, img001.png, etc.)
path_to_ffmpeg\ffmpeg.exe -framerate 1 -i img%03d.png output.mp4
However only the first image is taken to the video and it only shows one image!
After trying multiple permutations of -framerate and -r options and positions of the options, I did not recieve any better results.
Does anyone know what might have gone wrong even in this simple case? Thanks.
Full log:
C:\Users\foo\Documents\path>C:\bar\ffmpeg-4.0.2-win64-static\bin\ffmpeg.ex
e -framerate 1 -i img%03d.png output.mp4
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.1 (GCC) 20180722
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --e
nable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libblur
ay --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-
libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enab
le-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-li
bvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --en
able-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-
libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enabl
e-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enabl
e-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enab
le-dxva2 --enable-avisynth
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, image2, from 'img%03d.png':
Duration: 00:00:10.00, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgba(pc), 959x550 [SAR 2834:2834 DAR 959:550], 1 fp
s, 1 tbr, 1 tbn, 1 tbc
File 'output.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 # 0000000000611040] using SAR=1/1
[libx264 # 0000000000611040] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX FMA3 BMI2 AVX2
[libx264 # 0000000000611040] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-b
it
[libx264 # 0000000000611040] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC cod
ec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 r
ef=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed
_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pski
p=1 chroma_qp_offset=4 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 deci
mate=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 'output.mp4':
Metadata:
encoder : Lavf58.12.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv444p, 959x550 [SA
R 1:1 DAR 959:550], q=-1--1, 1 fps, 16384 tbn, 1 tbc
Metadata:
encoder : Lavc58.18.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 10 fps=0.0 q=-1.0 Lsize= 20kB time=00:00:07.00 bitrate= 23.1kbits
/s speed=68.6x
video:19kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing ov
erhead: 5.046419%
[libx264 # 0000000000611040] frame I:1 Avg QP: 4.41 size: 14084
[libx264 # 0000000000611040] frame P:3 Avg QP:12.31 size: 632
[libx264 # 0000000000611040] frame B:6 Avg QP:19.11 size: 436
[libx264 # 0000000000611040] consecutive B-frames: 20.0% 0.0% 0.0% 80.0%
[libx264 # 0000000000611040] mb I I16..4: 89.7% 0.0% 10.3%
[libx264 # 0000000000611040] mb P I16..4: 0.2% 0.0% 0.1% P16..4: 0.5% 0.1
% 0.1% 0.0% 0.0% skip:98.9%
[libx264 # 0000000000611040] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.6% 0.1
% 0.1% direct: 0.0% skip:99.1% L0:22.0% L1:73.7% BI: 4.3%
[libx264 # 0000000000611040] coded y,u,v intra: 6.1% 2.5% 2.6% inter: 0.2% 0.1%
0.1%
[libx264 # 0000000000611040] i16 v,h,dc,p: 72% 25% 3% 0%
[libx264 # 0000000000611040] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 31% 20% 2% 2%
2% 3% 5% 2%
[libx264 # 0000000000611040] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 # 0000000000611040] ref P L0: 65.8% 1.5% 26.5% 6.1%
[libx264 # 0000000000611040] ref B L0: 77.0% 12.7% 10.3%
[libx264 # 0000000000611040] ref B L1: 88.6% 11.4%
[libx264 # 0000000000611040] kb/s:14.87
Older versions of VLC couldn't play videos with framerates 5 or lower. Add -r 6 to correct for that. Also, you may want to add -pix_fmt yuv420p for wide playback compatibility.

Resources