如何在影片的第一帧之前放置静像? [英] How can I place a still image before the first frame of a video?

查看:329
本文介绍了如何在影片的第一帧之前放置静像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用FFMpeg编码视频时,我想在第一个视频帧之前放置一个jpg图像,因为当我将视频嵌入到具有videohtml5标签的网页上时,它会将第一张图片显示为闪光图像。或者,我想将图像编码为1帧视频,并将其连接到我的编码视频。我不想使用videohtml5元素的poster属性。

解决方案

可以使用concat过滤这样做。确切的命令取决于您想要启动屏幕的时间长短。我确定你不希望有一个1帧的闪屏,大约是1/25到1/30秒,这取决于视频;)



答案



首先,您需要获取视频的帧速率。尝试 ffmpeg -i INPUT 并找到 tbr 值。例如

  $ ffmpeg -i a.mkv 
ffmpeg版本N-62860-g9173602版权所有(c)2000-2014 FFmpeg开发人员
建立于2014年4月30日21:42:15与gcc 4.8(Ubuntu 4.8.2-19ubuntu1)
[...]
输入#0,matroska,webm,从'a.mkv':
元数据:
ENCODER:Lavf55.37.101
持续时间:00:00:10.08,开始:0.080000,比特率:23 kb / s
流#0 :0:视频:h264(高4:4:4预测),yuv444p,320x240 [SAR 1:1 DAR 4:3],25 fps,25 tbr,1k tbn,50 tbc(默认)
至少必须指定一个输出文件

在上面的例子中,它显示 25 tbr 。记住这个号码。



其次,您需要将影像与影片连接起来。尝试此命令:

  ffmpeg -loop 1 -framerate FPS -t SECONDS -i IMAGE \ 
-t SECONDS -f lavfi -i aevalsrc = 0 \
-i INPUTVIDEO \
-filter_complex'[0:0] [1:0] [2:0] [2:1] concat = n = 2:v = 1:a = 1'\
[选项] OUTPUT

您的视频没有音频,请尝试:

  ffmpeg -loop 1 -framerate FPS -t SECONDS -i IMAGE \ 
-i INPUTVIDEO \
-filter_complex'[0:0] [1:0] concat = n = 2:v = 1:a = 0'\
[OPTIONS] OUTPUT

FPS = tbr 从步骤1获得的值



SECONDS =想要图像的持续时间



IMAGE =图片名称



INPUTVIDEO =原始视频名称



[选项] =可选编码参数(如 -vcodec libx 264 -b:一个160k



OUTPUT =输出视频文件名称



如何工作?



我使用的命令行:



-loop 1 -framerate FPS -t SECONDS -i IMAGE :这基本上意味着:打开图像,并循环使用 SECONDS 秒的视频,每秒以 FPS 帧为单位。您需要它与输入视频具有相同FPS的原因是因为我们稍后使用的 concat 过滤器有其限制。



-t SECONDS -f lavfi -i aevalsrc = 0 :这意味着:为SECONDS生成静音(0表示静音)。您需要沉默才能填满飞溅图像的时间。如果原始视频没有音频,则不需要。



-i INPUTVIDEO :打开视频



-filter_complex'[0:0] [1:0] [2:0] [2:1] concat = n = 2:v = 1:a = 1':这是最好的部分。您打开文件0流0(图像视频),文件1流0(静音音频),文件2流0和1(实际输入音频和视频)和 concat 一起使用它们。 n v a 的选项意味着是2段,1个输出视频和1个输出音频。



[选项] OUTPUT :这只是意味着将视频编码为输出文件名。如果您使用HTML5流式传输,则可能需要使用 -c:v libx264 -crf 23 -c:libfdk_aac(或-c:libfaac)-b:128k 用于H.264视频和AAC音频。



更多信息




When I encode videos by FFMpeg I would like to put a jpg image before the very first video frame, because when I embed the video on a webpage with "video" html5 tag, it shows the very first picture as a splash image. Alternatively I want to encode an image to an 1 frame video and concatenate it to my encoded video. I don't want to use the "poster" property of the "video" html5 element.

解决方案

You can use the concat filter to do that. The exact command depends on how long you want your splash screen to be. I am pretty sure you don't want an 1-frame splash screen, which is about 1/25 to 1/30 seconds, depending on the video ;)

The Answer

First, you need to get the frame rate of the video. Try ffmpeg -i INPUT and find the tbr value. E.g.

$ ffmpeg -i a.mkv
ffmpeg version N-62860-g9173602 Copyright (c) 2000-2014 the FFmpeg developers
  built on Apr 30 2014 21:42:15 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
[...]
Input #0, matroska,webm, from 'a.mkv':
  Metadata:
    ENCODER         : Lavf55.37.101
  Duration: 00:00:10.08, start: 0.080000, bitrate: 23 kb/s
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
At least one output file must be specified

In the above example, it shows 25 tbr. Remember this number.

Second, you need to concatenate the image with the video. Try this command:

ffmpeg -loop 1 -framerate FPS -t SECONDS -i IMAGE \
       -t SECONDS -f lavfi -i aevalsrc=0 \
       -i INPUTVIDEO \
       -filter_complex '[0:0] [1:0] [2:0] [2:1] concat=n=2:v=1:a=1' \
       [OPTIONS] OUTPUT

If your video doesn't have audio, try this:

ffmpeg -loop 1 -framerate FPS -t SECONDS -i IMAGE \
       -i INPUTVIDEO \
       -filter_complex '[0:0] [1:0] concat=n=2:v=1:a=0' \
       [OPTIONS] OUTPUT

FPS = tbr value got from step 1

SECONDS = duration you want the image to be shown.

IMAGE = the image name

INPUTVIDEO = the original video name

[OPTIONS] = optional encoding parameters (such as -vcodec libx264 or -b:a 160k)

OUTPUT = the output video file name

How Does This Work?

Let's split the command line I used:

-loop 1 -framerate FPS -t SECONDS -i IMAGE: this basically means: open the image, and loop over it to make it a video with SECONDS seconds with FPS frames per second. The reason you need it to have the same FPS as the input video is because the concat filter we will use later has a restriction on it.

-t SECONDS -f lavfi -i aevalsrc=0: this means: generate silence for SECONDS (0 means silence). You need silence to fill up the time for the splash image. This isn't needed if the original video doesn't have audio.

-i INPUTVIDEO: open the video itself.

-filter_complex '[0:0] [1:0] [2:0] [2:1] concat=n=2:v=1:a=1': this is the best part. You open file 0 stream 0 (the image-video), file 1 stream 0 (the silence audio), file 2 streams 0 and 1 (the real input audio and video), and concatenate them together. The options n, v, and a mean that there are 2 segments, 1 output video, and 1 output audio.

[OPTIONS] OUTPUT: this just means to encode the video to the output file name. If you are using HTML5 streaming, you'd probably want to use -c:v libx264 -crf 23 -c:a libfdk_aac (or -c:a libfaac) -b:a 128k for H.264 video and AAC audio.

Further information

这篇关于如何在影片的第一帧之前放置静像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆