FFMPEG将文本帧添加到视频的开头 [英] FFMPEG add text frames to the start of video

查看:995
本文介绍了FFMPEG将文本帧添加到视频的开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些mp4或webm格式的视频,我想用ffmpeg在每个视频的开头添加4秒,以在中心显示一些没有声音的文本.

I have some videos either in mp4 or webm format, and I'd like to use ffmpeg to add 4 seconds to the start of each video to display some text in the center with no sound.

其他一些要求:

  • 尝试避免对视频进行重新编码
  • 需要保持质量(分辨率,比特率等)
  • (可选),以使文本淡入/淡出

我是ffmpeg的新手,任何帮助将不胜感激.

I am new to ffmpeg and any help will be appreciated.

预先感谢

以下mp4的示例ffprobe信息:

Example ffprobe information for mp4 below:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.33.100
  Duration: 00:00:03.84, start: 0.042667, bitrate: 1117 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1021 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
  handler_name    : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 140 kb/s (default)
Metadata:
  handler_name    : SoundHandler

示例webm

Input #0, matroska,webm, from 'input.webm':
  Metadata:
  encoder         : Lavf55.33.100
 Duration: 00:00:03.80, start: 0.000000, bitrate: 1060 kb/s
   Stream #0:0(eng): Video: vp8, yuv420p, 1280x720, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
   Stream #0:1(eng): Audio: vorbis, 48000 Hz, stereo, fltp (default)

joined.mp4中的屏幕截图

第3步控制台的屏幕截图

推荐答案

您必须生成一个4秒钟的视频,该视频具有与现有视频(包括时基)的参数匹配的虚拟音频,然后将concat多路分配器与streamcopy一起使用.

You'll have to generate a 4 second video with dummy audio matching the parameters of the existing video, including timebase, and then use the concat demuxer with streamcopy.

对于Q中显示的示例文件:

For the sample files shown in Q:

步骤1 生成文字视频

ffmpeg -f lavfi -r 30 -i color=black:1280x720 -f lavfi -i anullsrc -vf "drawtext="fontfile=/path/to/font.ttf:fontcolor=FFFFFF:fontsize=50:text='Your text':x=(main_w-text_w)/2:y=(main_h-text_h)/2",fade=t=in:st=0:d=1,fade=t=out:st=3:d=1" -c:v libx264 -b:v 1000k -pix_fmt yuv420p -video_track_timescale 15360 -c:a aac -ar 48000 -ac 2 -sample_fmt fltp -t 4 intro.mp4

对于WebM,将-c:v libx264替换为-c:v libvpx,将-c:a aac替换为-c:a libvorbis,将intro.mp4替换为intro.webm.您可能会删除-video_track_timescale 15360,因为WebM倾向于使用单个时标,这已经见过.

For WebM, replace -c:v libx264 with -c:v libvpx, -c:a aac with -c:a libvorbis and intro.mp4 with intro.webm. You may remove the -video_track_timescale 15360 since WebMs tend to use a single timescale, that I've seen.

步骤2 ,准备concat文件,例如list.txt

Step 2 Prepare concat file, say, list.txt

file 'intro.mp4'
file 'input.mp4'

第3步 Concat

ffmpeg -f concat -i list.txt -c copy -fflags +genpts joined.mp4


这里重要的变量是视频大小1280x720,帧速率-r 30-pix_fmt yuv420p,采样率-ar 48000,格式-sample_fmt fltp,频道布局-ac 2,当然还有编解码器.


The variables important here are video size 1280x720, frame rate -r 30, -pix_fmt yuv420p, sample rate -ar 48000, format -sample_fmt fltp, channel layout -ac 2 and of course, codecs.

这篇关于FFMPEG将文本帧添加到视频的开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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