在幻灯片视频上使用 ffmpeg concat

在幻灯片视频上使用 ffmpeg concat

我正在使用 ffmpeg 从静态图像构建延时动画。重复第一幅图像以创建标题。下一步是将标题和延时动画连接起来以制作最终视频。标题和延时动画都制作得很好。创建连接的最终视频没有得到预期的结果。

kubuntu 14 上的 ffmpeg 版本 1.2.6-7。

标题

ffmpeg -framerate 16 -f image2 -i './Header/Sun_20150214_head_%02d.png' -vf "crop=1240:940:40:10" -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" -c:v libx264 -pix_fmt yuv420p -crf 16 -y ./Video/sunspot_20150214_header.mp4

ffmpeg -i ./Video/sunspot_20150214_header.mp4 -vf fade=in:0:30 -crf 24 -y ./Video/sunspot_20150214_header_fade.mp4

头球本身表现不错,并且淡出效果很好。

现在来看看时间流逝:

ffmpeg -r 12 -threads 0 -f image2 -pattern_type glob -i './npy2reg/Sun_20150214_*.png'  -c:v libx264 -crf 16 -vf "crop=1240:940:40:10" -y ./Video/sunspot_20150214_crf16_12fps.mp4

就其本身而言,延时播放效果很好。

尝试使用带有指向两个输入文件的指针的 concat.txt 文件进行连接。concat.txt 文件:

file '/home/gottsch/sunspot_20150214/Video/sunspot_20150214_header_fade.mp4'
file '/home/gottsch/sunspot_20150214/Video/sunspot_20150214_crf16_12fps.mp4'

ffmpeg的cmd:

ffmpeg -f concat -i ./scripts/concat.txt -c copy -y  ./Video/sunspot_20150214_crf16_12fps_final.mp4

这给出了我的输出文件sunspot_20150214_crf16_12fps_final.mp4。问题:输出文件仅显示标题。

我读到过,ffmpeg concat 引擎要求输入视频具有相同的格式,我相信这是 ffmpeg 创建它们时给出的格式。

非常感谢您的帮助。

谢谢,格特

更新:

我被要求提供以下 cmd 的控制台输出:

gottsch@ubuntu:~/sunspot_20150214$ ffmpeg -i './Header/Sun_20150214_head_%02d.png' -pattern_type glob -i './npy2reg/Sun_20150214_*.png'
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 './Header/Sun_20150214_head_%02d.png':
  Duration: 00:00:02.36, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgb24, 1280x960, 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, image2, from './npy2reg/Sun_20150214_*.png':
  Duration: 00:00:01.76, start: 0.000000, bitrate: N/A
Stream #1:0: Video: png, rgb24, 1280x960, 25 fps, 25 tbr, 25 tbn, 25 tbc
At least one output file must be specified
gottsch@ubuntu:~/sunspot_20150214$ 

之后,在一个 cmd 中处理这两个部分似乎没问题。我的图像处理脚本以枚举格式创建文件,因此第二部分可以不用 % 符号来编写。

ffmpeg -i './Header/Sun_20150214_head_%02d.png' -i './npy2reg/Sun_20150214_%02d.png'

关于缺少输出文件的 cmd 行错误没有问题。我担心的是我计划合并的一系列过滤器。(淡入淡出、文本、裁剪)。有没有关于过滤器正确排序和优先级控制的教程?

我还关注创建的 mpeg 的最广泛的兼容性,以便大多数设备/操作系统/浏览器组合可以处理它。

在我之前的尝试中,我收到的反馈是它在 MAC OS 浏览器中失败,并出现缺少插件的错误。

谢谢,格特

更新2

以下每行仅生成标题的视频。不显示延时拍摄的任何帧。

ffmpeg -i './Header/Sun_20150214_head_%02d.png' -i './npy2reg/Sun_20150214_%02d.png' -codec:v libx264 -pix_fmt yuv420p -crf 16 -y ./Video/sunspot_20150214_crf16_12fps_test.mp4

ffmpeg -i './Header/Sun_20150214_head_%02d.png' -pattern_type glob -i './npy2reg/Sun_20150214_*.png' -codec:v libx264 -pix_fmt yuv420p -crf 16 -y ./Video/sunspot_20150214_crf16_12fps_test.mp4

最好的,格特

答案1

据我所见,您的视频有不同的帧速率,16fps 和 12fps。对于连接视频并使用 concat解复用器,视频连接的唯一可能不同的地方可能是比特率,其他一切,分辨率,fps,编解码器,颜色格式......必须相等。

查看FFmpeg wiki 连接部分

可能的解决方案

  • 均衡视频的所有可能参数(fps、大小……)
  • 在 GUI 视频编辑器中制作视频,例如kdenlive
  • FFMpeg 在淡入淡出和文本等编辑任务方面相当有限。如果你真的想以编程方式创建/编写视频,我个人建议使用像avisynth,它通过其内部过滤器ImageSourceFadeInSubtitle......)。但是,它仅适用于 Windows。它有一个 Linux 端口,称为AVX合成器,尽管我从未尝试过。使用框架服务器可以在您选择的媒体播放器中预览最终结果,非常容易地更改参数并一次性编码最终结果。
  • 使用 ffmpegs concat筛选https://trac.ffmpeg.org/wiki/Concatenate#differentcodec. 我对此的评价好坏参半。

示例 avisynth 脚本

我制作了简单的 avisynth 脚本sunspot.avs,可以作为您的起点。我在 Windows 中尝试过,但理论上,它也应该适用于 avxsynth...

# Set the desired parameters for the output video
out_fps = 25
out_width = 800
out_height = 600

# Make a title clip
blank = BlankClip(length=out_fps * 3, width=out_width, height=out_height, fps=out_fps, color=$000000).KillAudio()
blank_subtitle = blank.Subtitle("Your Title", align=5, size=60, text_color=$ffff00)

# Load image sequence, assume 16 input fps 16, convert to output video's 25fps
# NOTE: since the input frame rates differs from the output frame rate, there will be interpolation going on... 
sunspot = ImageReader("Sun_20150214_%02d.png", 1, 62, 16).ChangeFPS(out_fps).ConvertToRGB32()
# Crop & Resize, pay attention not to distort the images to the ratios
sunspot_cropped = sunspot.Crop(8,2,-9,-4).LanczosResize(out_width, out_height)

# Concatenate the clips (which now have the same fps + format + color space)
blank_subtitle.FadeIn(out_fps * 1) ++ sunspot_cropped

您可以预览结果ffplay sunspot.avs,如果满意,则将其转换为 mp4 文件,例如:

ffmpeg -i sunspot.avs -c:v libx264 -crf 19 -preset:v slower -pix_fmt yuv420p -c:a libfdk_aac sunspot.mp4

相关内容