我设法将单个图像添加到在特定时间开始并在特定时间结束的视频中,但我找不到对多个图像执行此操作的方法。我用的是流利的ffmpeg。
这是我的代码:
ffmpeg('../videos/testklein.mp4')
.input('../src/test.png')
.input('../src/0.png')
.input('../src/1.png')
.addOptions([
"-strict -2"
])
.complexFilter([
{
filter: 'overlay',
options: {
x: 200,
y: 200,
enable: 'between(t,1,3)',
}}, {
filter: 'overlay',
options: {
x: 200,
y: 200,
enable: 'between(t,3,5)',
}},
{
filter: 'overlay',
options: {
x: 200,
y: 200,
enable: 'between(t,5,7)',
}
},
])
Run Code Online (Sandbox Code Playgroud)
我想我需要明确说明哪个过滤器应该采用哪个文件,但我不确定其语法。
int64_t timeBase;
timeBase = (int64_t(pavStrm-> time_base.num) * AV_TIME_BASE) / int64_t(pavStrm->time_base.den);
int64_t seekTarget = int64_t(iFrameNumber) * timeBase;
av_seek_frame(fmt_ctx, -1, seekTarget, AVSEEK_FLAG_FRAME);
Run Code Online (Sandbox Code Playgroud)
在这里,我想在iFrameNumebr之后阅读下一个5帧
for(int iCnt = 0; iCnt <= 4; iCnt++)
{
iRet = av_read_frame(fmt_ctx, &pkt);
do
{
ret = decode_packet(&got_frame, 0);
if (ret < 0)
break;
pkt.data += ret;
pkt.size -= ret;
}while (pkt.size > 0);
av_free_packet(&pkt);
}
static int decode_packet(int *got_frame, int cached)
{
int ret = 0;
int decoded = pkt.size;
*got_frame = 0;
if (pkt.stream_index == video_stream_idx)
{ …Run Code Online (Sandbox Code Playgroud) 我在我的 NodeJS 应用程序中使用 Fluent FFMpeg,我试图在输入不存在的情况下添加一些错误处理。目前它只是崩溃了这条消息:
events.js:72
throw er; // Unhandled 'error' event
^
Error: ffmpeg exited with code 1: http://localhost:9001: Connection refused
Run Code Online (Sandbox Code Playgroud)
当输入源不存在时,我想等待一段时间(比如 1 秒)然后再试一次。这是目前我的代码:
var command = FFmpeg("http://localhost:9001")
// set options here
;
var stream = command.pipe();
stream.on('data', function(chunk) {
// do something with the data
});
Run Code Online (Sandbox Code Playgroud)
当输入(还)不存在时,如何正确处理错误?
我的输入是 .mp4 视频文件。
尝试#1
ffmpeg -i pipe:0 -y -map a media/73.mp3
Run Code Online (Sandbox Code Playgroud)
错误:
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.42)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 …Run Code Online (Sandbox Code Playgroud) 下面是我将 h264 转换为 gif 的代码
var ffmpeg = require("fluent-ffmpeg");
var inFilename = "/home/pi/Videos/video.mp4";
var outFilename = "/home/pi/Videos/video.gif";
var fs = require('fs');
ffmpeg(inFilename)
.outputOptions("-c:v", "copy")
.output(outFilename)
.run();
Run Code Online (Sandbox Code Playgroud)
这段代码在从 h264 到 mp4 时工作得非常好,只是想知道为什么它不能从 h264 到 gif 工作,或者我是否可以让它工作。
我正在尝试使用 ffmpeg 和 node.js 将视频转码为多种分辨率。
我可以从命令行运行此命令将视频转码为 720p:
ffmpeg -vsync 0 -hwaccel cuvid -hwaccel_device 0 -c:v h264_cuvid -i input.mp4 -vf scale_npp=-1:720 -c:a copy -c:v h264_nvenc -b:v 5M output2.mp4
我还可以使用 CPU 进行转码,使用以下代码和用于 Node.js 的 Fluent-ffmpeg 库
function transcodeToRes(path, shortSide, bitrate, videoID, portrait) {
return new Promise((res, rej) => {
let resolution = portrait ? "?x" + shortSide : shortSide + "x?";
let localSavePath = savePath + videoID + "/" + shortSide + ".mp4";
ffmpeg()
.input(path)
.native()
.audioCodec('aac')
.audioBitrate(128)
.audioChannels(2)
.videoCodec('libx264')
.videoBitrate(bitrate)
.size(resolution) …Run Code Online (Sandbox Code Playgroud) 在我的程序中,我使用 Fluent-ffmpeg 将视频转换为可流式传输的 HLS 格式 (m3u8)。但这非常消耗CPU,我想知道它是否可以在浏览器的客户端运行。通过这种方式,我将从服务器上卸载一些工作。如果是这样,如何安装它以在 html<script>标签中可用?我也尝试直接在他们的github上询问,但到目前为止没有回应......
我正在尝试将以下复杂过滤器转换为 Fluent FFMPEG 命令,但我无法弄清楚映射是如何工作的。
ffmpeg -i audio.mp3 -filter_complex "[0:a]showfreqs=s=200x100:colors=white|white,format=yuv420p[vid]" -map "[vid]" -map 0:a video.mp4
到目前为止,这是我所拥有的,但我收到有关“vid”流的错误。
ffmpeg()
.input("audio.mp3")
.audioCodec("aac")
.audioBitrate("320")
.complexFilter(
{
filter: "showfreqs",
options: { s: "200x100" },
inputs: "0:a",
},
{
filter: "format",
options: { pix_fmts: "yuv420p" },
outputs: ["vid"],
}
)
.outputOptions(['-map "[vid]"', "-map 0:a"])
.save(spectrumTmp)
Run Code Online (Sandbox Code Playgroud)
错误: ffmpeg exited with code 1: Stream map '"[vid]"' matches no streams.
To ignore this, add a trailing '?' to the map.
如果我添加一个尾随 '?' 在outputOptions我得到一个没有视频流的文件。