For a time lapse video project I want to create a header (with some title text).
The header is just one still image which I give as jpg. I have seen other answers that produce still image video from a single jpg and match length with sound from a sound file. I have no sound file and want no audio channel in the output video. I would like to just give the single still jpg to ffmpeg and number of frames or seconds to show. So far I have just made many copies of the single still jpg (links) and used image2 input processor.
ffmpeg -framerate 16 -f image2 -i './Header/Sun_20150214_head_%02d.png' -vf "crop=1240:940:40:10" -c:v libx264 -pix_fmt yuv420p -crf 16 -y ./Video/sunspot_20150214_header.mp4
Is there a simpler version that works without the links and gives me better control over seconds of video length?
Thanks,
Gert
UPDATE
I found this at the ffmpeg wiki (pending test short of answering my question)
ffmpeg -loop 1 -i img.png -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4
I will try that but will add frame rate for the output.
I.e.
ffmpeg -loop 1 -i img.png -c:v libx264 -t 5 -r 16 -pix_fmt yuv420p out.mp4
Should give me 5sec of output video at 16fps. (hopefully)
Best,
Gert
UPDATE2
I tried the above line and it worked fine. The video played well.
I wanted to have a title text overlayed onto the video and a fade effect at the beginning. Adding this as a -vf option gave a warning message. (Still the video is usable)
Just want to be sure about the significance of the message.
Command:
ffmpeg -loop 1 -i './npy2reg/Sun_20150214_01.png' -c:v libx264 -vf drawtext="fontsize=100:fontcolor=yellow:fontfile=/usr/share/fonts/truetype/freefont/FreeSans.ttf:textfile=./scripts/header_text.txt:x=(w-text_w)/2:y=(h-text_h-line_h)/2","crop=1240:940:40:10" -t 3 -pix_fmt yuv420p -crf 16 -r 12 -y ./Video/sunspot_20150214_header.mp4
Console output:
gottsch@ubuntu:~/sunspot_20150214$ ffmpeg -loop 1 -i './npy2reg/Sun_20150214_01.png' -c:v libx264 -vf drawtext="fontsize=100:fontcolor=yellow:fontfile=/usr/share/fonts/truetype/freefont/FreeSans.ttf:textfile=./scripts/header_text.txt:x=(w-text_w)/2:y=(h-text_h-line_h)/2","crop=1240:940:40:10" -t 3 -pix_fmt yuv420p -crf 16 -r 12 -y ./Video/sunspot_20150214_header.mp4
ffmpeg version 1.2.6-7:1.2.6-1~trusty1 Copyright (c) 2000-2014 the FFmpeg developers
built on Apr 26 2014 18:52:58 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --arch=amd64 --disable-stripping --enable-avresample --enable-pthreads --enable-runtime-cpudetect --extra-version='7:1.2.6-1~trusty1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-libcdio --enable-x11grab --enable-libx264 --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 53. 5.103 / 53. 5.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, image2, from './npy2reg/Sun_20150214_01.png':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgb24, 1280x960, 25 fps, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x1bb7020] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3
[libx264 @ 0x1bb7020] profile High, level 3.2
[libx264 @ 0x1bb7020] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=12 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=16.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to './Video/sunspot_20150214_header.mp4':
Metadata:
encoder : Lavf54.63.104
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1240x940, q=-1--1, 12288 tbn, 12 tbc
Stream mapping:
Stream #0:0 -> #0:0 (png -> libx264)
Press [q] to stop, [?] for help
[swscaler @ 0x1badb40] Warning: data is not aligned! This can lead to a speedloss
frame= 36 fps= 20 q=-1.0 Lsize= 399kB time=00:00:02.83 bitrate=1155.0kbits/s dup=0 drop=34
video:398kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.301361%
[libx264 @ 0x1bb7020] frame I:1 Avg QP: 6.33 size:399123
[libx264 @ 0x1bb7020] frame P:9 Avg QP: 8.73 size: 696
[libx264 @ 0x1bb7020] frame B:26 Avg QP:13.38 size: 65
[libx264 @ 0x1bb7020] consecutive B-frames: 2.8% 0.0% 8.3% 88.9%
[libx264 @ 0x1bb7020] mb I I16..4: 15.9% 29.7% 54.4%
[libx264 @ 0x1bb7020] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 2.8% 0.0% 0.0% 0.0% 0.0% skip:97.2%
[libx264 @ 0x1bb7020] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.7% 0.0% 0.0% direct: 0.0% skip:99.3% L0: 0.9% L1:99.1% BI: 0.0%
[libx264 @ 0x1bb7020] 8x8 transform intra:29.7% inter:48.0%
[libx264 @ 0x1bb7020] coded y,uvDC,uvAC intra: 99.4% 9.5% 9.3% inter: 0.3% 0.0% 0.0%
[libx264 @ 0x1bb7020] i16 v,h,dc,p: 6% 4% 70% 20%
[libx264 @ 0x1bb7020] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 10% 19% 4% 14% 13% 11% 6% 9%
[libx264 @ 0x1bb7020] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 11% 17% 7% 13% 11% 10% 8% 9%
[libx264 @ 0x1bb7020] i8c dc,h,v,p: 92% 3% 4% 1%
[libx264 @ 0x1bb7020] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x1bb7020] ref P L0: 98.6% 0.0% 1.1% 0.3%
[libx264 @ 0x1bb7020] kb/s:1085.57
gottsch@ubuntu:~/sunspot_20150214$
Thanks,
Gert
Best Answer
You can specify the frame rate for the input and/or the output.
Same frame rate for input and output
Because the output will inherit the input frame rate you only need to declare the input frame rate if you want both the input and output to have the same frame rate.
The default frame rate for the image file demuxer is 25, which is the value that will be used if you omit
-framerate
.Different frame rate for input and output
This example will use a frame rate of 10 for the input, and 25 for the output. Frames will be duplicated to go from 10 → 25. If the values are swapped, then frames will be dropped to go from 25 → 10. The console output will inform you if frames are duplicated or dropped.
The image file demuxer uses the
-framerate
private option to set frame rate. The output uses the-r
option to set frame rate.If you want frame interpolation try slowmoVideo.