- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要一个仅使用 libavformat 来混合视频的简单工作示例。有很好的示例 ( doc/examples/muxing.c ) 显示了使用 libavcodec 进行编码、使用 libavformat 进行多路复用以及使用 libavio 保存数据。但是,据我所知,没有一个例子单独使用 libavformat,在缓冲区中输入编码数据并在缓冲区中获取混合数据。
困难有两方面:一,用avformat_new_stream(AVFormatContext *s, const AVCodec *c)
添加流需要引用编解码器;第二,muxing 的输出被传递给 AVFormatContext->pb
,这是一个 AVIOContext*
。因此,似乎没有(明显的)方法可以从其他 libav 库中提取 libavformat。
另见:这个问题提到了一种不使用 libavio 的方法:Get TS packets into buffer from libavformat
最佳答案
您可以避免依赖 libavcodec 库,但您需要头文件(例如,avcodec.h)。
方案如下:
AVOutputFormat * oFmt= ::av_guess_format("mp4", NULL, NULL);
AVFormatContext *oFmtCtx = NULL;
::avformat_alloc_output_context2(&oFmtCtx, oFmt, NULL, NULL);
AVStream * oStrm = ::avformat_new_stream(oFmtCtx, NULL);
AVCodecContext * strmCodec = oFmtCtx->streams[0]->codec;
// Fill the required properties for codec context.
// *from the documentation:
// *The user sets codec information, the muxer writes it to the output.
// *Mandatory fields as specified in AVCodecContext
// *documentation must be set even if this AVCodecContext is
// *not actually used for encoding.
my_tune_codec(strmCodec);
if (oFmtCtx->oformat->flags & AVFMT_NOFILE)
{
::avio_open2(&oFmtCtx->pb, fileName, AVIO_FLAG_WRITE, NULL, NULL);
}
::avformat_write_header(oFmtCtx, NULL);
// .....
// writing loop
// .....
::av_write_trailer(oFmtCtx);
::avio_close(oFmtCtx->pb);
::avformat_free_context(oFmtCtx);
要获得输出,您始终必须使用 AVIOContext
的概念。您可以避免使用内置协议(protocol)。为此,您需要创建自己的 AVIOContext
(::avio_alloc_context
)。
UPD要创建您自己的 AVIOContext
,您必须这样做
#include <stdio.h>
extern "C" {
#include <libavformat/avio.h>
#include <libavformat/avformat.h>
}
static const int kBufferSize = 32768;
class my_iocontext_private
{
public:
my_iocontext_private(FILE * f) : buffer_size_(kBufferSize),
buffer_(static_cast<unsigned char*>(::av_malloc(buffer_size_))), f_(f) {
ctx_ = ::avio_alloc_context(buffer_, buffer_size_, AVIO_FLAG_WRITE, this,
&my_iocontext_private::read, &my_iocontext_private::write, &my_iocontext_private::seek);
}
~my_iocontext_private() { av_free(buffer_); }
static int read(void *opaque, unsigned char *buf, int buf_size) {
my_iocontext_private* h = static_cast<my_iocontext_private*>(opaque);
return fread(buf, 1, buf_size, h->f_);
}
static int write(void *opaque, unsigned char *buf, int buf_size) {
my_iocontext_private* h = static_cast<my_iocontext_private*>(opaque);
return fwrite(buf, 1, buf_size, h->f_);
}
static int64_t seek(void *opaque, int64_t offset, int whence) {
my_iocontext_private* h = static_cast<my_iocontext_private*>(opaque);
// use lseeki64 instead of fseek
return fseek(h->f_, static_cast<long>(offset), whence);
}
::AVIOContext *get_avio() { return ctx_; }
private:
int buffer_size_;
unsigned char * buffer_;
FILE * f_;
::AVIOContext * ctx_;
};
int main(int argc, char* argv[])
{
FILE * f = fopen("myfile.dmp", "wb");
my_iocontext_private priv_ctx(f);
AVFormatContext * ctx = ::avformat_alloc_context();
ctx->pb = priv_ctx.get_avio();
/// using ctx
fclose(f);
return 0;
}
关于video - 不使用其他libav库如何使用libavformat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13634539/
来自Linux背景。我只是想知道在 OSX 上安装 avprobe 的最佳方法是什么? 我尝试安装 libav:http://libav.org/download.html但这似乎使用了avconf。
如何在FFmpeg C API中编码之前为帧计算正确的PTS值? 为了进行编码,我使用了avcodec_encode_video2函数,然后通过av_interleaved_write_frame编写
使用 libav 保存视频中的帧。 问题是,如果你多次调用 decode 函数,然后调用 2nd,然后就没有正确处理。 第一次这样的结论(一切正常): [swscaler @ 0x8b48510]No
我正在尝试制作一个简单的 av 播放器,在某些情况下,我可以正确获取如下值: checking /media/timecapsule/Music/02 Baawre.mp3 [mp3 @ 0x7f06
我在OS X Mavericks上没有安装libav的运气。我已经尝试了一切。 我正在遵循此指南:http://earthwithsun.com/questions/568464/install-la
尝试使用 ffmpeg 打开网络摄像头(ffplay -f video4linux2/dev/video0 有效 pFormatCtx = NULL; av_register_all(
我使用下面的命令来转换文件 ./avconv -i inputFile -vcodec libx264 -trellis 2 -crf 23 -tune psnr -vf Crop='trunc(iw
我试图通过使用代码将 MP2 文件转换为原始 PCM 来获得与 ffmpeg/avconv 相同的输出。我使用了 the tutorial included in the FFmpeg/Libav d
我正在关注 ffmpeg 文档中的音频编码示例:https://www.ffmpeg.org/doxygen/0.6/api-example_8c-source.html 但我想解码 .wav 文件,
我正在尝试使用 libav(ffmpeg) 创建带有 MJPEG 视频负载的 RTP 流示例代码非常简单,适用于 MPEG1我看到 MJPEG 中的编码有效,但是当我需要发送 mjpeg 时帧 RTP
有没有办法使用 libav/avconv 来复制 FFMPEG 中瓦片过滤器的效果? 我正在尝试为每十秒的视频输入创建一个从左到右的图像 strip 。 我的计划是首先生成图像,然后创建图像条。最好我
我正在尝试使用 libav 在我的应用程序中删除视频的某些部分,例如在长度为 00:08:00 的视频中,我尝试删除帧 100-250 和 400-500(仅作为示例)。 我写了这段代码来复制 AVP
我有一个能够同时生成 5 个 mpeg 传输流的程序。每个流都有自己的上下文,并在独立的线程中完成。当只有一个流处于事件状态时,一切都很好。一旦我激活另一个流,我的帧速率就会大大下降。两个流仍然可以正
我有一系列编码数据包、H.264 视频和 AAC 音频。当它们出现时,我正在使用 av_write_frame 将它们写入视频文件。 连续给定以下情况 10秒视频,然后 10 秒的视频和音频,然后 1
我看到了这个答案,Libav (ffmpeg) copying decoded video timestamps to encoder 但我仍然不明白为什么我们需要流时基和编解码器时基。目前我正在尝试
我正在尝试学习使用 libav。我遵循了 dranger.com 上的第一个教程,但有一次我有点困惑。 // Write pixel data for(y=0; ydata[0]+y*pFrame->
我有一个从我的手机以纵向模式拍摄的视频。以下是有关视频的转储信息: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.MOV': Metadata: maj
我有一个带有卡住(热)像素的视频,我想修复它,比如说用相邻像素的平均值替换像素。我在 Ubuntu 上,所以我想使用 libav/ffmpeg,但我真的不知道该怎么做。谁能提供一个简单的解决方案? 最
这个问题在这里已经有了答案: FFMPEG (libx264) "height not divisible by 2" (7 个回答) 5年前关闭。 我需要批量处理一堆视频以将它们的高度缩放到 240
我目前正在使用 libav 将视频的音频流提取到原始 PCM 文件中。 此代码适用于 mp3,但当我尝试使用 mp4 视频时,Audacity 上导入的原始格式显示奇怪的 0 到 -1 之间的规则下降
我是一名优秀的程序员,十分优秀!