当我ffmpeg在Ubuntu上运行时,它显示:
$ ffmpeg
ffmpeg version v0.8, Copyright (c) 2000-2011 the Libav developers
built on Feb 28 2012 13:27:36 with gcc 4.6.1
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).
Run Code Online (Sandbox Code Playgroud)
或者它显示(取决于Ubuntu版本):
$ ffmpeg
ffmpeg version 0.8.5-6:0.8.5-0ubuntu0.12.10.1, Copyright (c) 2000-2012 the Libav developers
built on Jan 24 2013 14:49:20 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility …Run Code Online (Sandbox Code Playgroud) 我试图使用libavcodec/libavformat编码视频.音频效果很好,但当我尝试编码视频时,我收到以下错误:
[libx264 @ 0x10182a000]broken ffmpeg default settings detected
[libx264 @ 0x10182a000]use an encoding preset (vpre)
Run Code Online (Sandbox Code Playgroud)
使用命令行ffmpeg很容易修复,但我想在C中执行此操作.我的选项是
AVStream *pVideoOutStream = av_new_stream(pOutFormatCtx, 0);
AVCodecContext *pVideoOutCodecCtx = pVideoOutStream->codec;
pVideoOutCodecCtx->codec_id = CODEC_ID_H264;
pVideoOutCodecCtx->codec_type = CODEC_TYPE_VIDEO;
pVideoOutCodecCtx->bit_rate = pVideoInCodecCtx->bit_rate;
pVideoOutCodecCtx->width = pVideoInCodecCtx->width;
pVideoOutCodecCtx->height = pVideoInCodecCtx->height;
pVideoOutCodecCtx->pix_fmt = pVideoInCodecCtx->pix_fmt;
pVideoOutCodecCtx->sample_rate = pVideoInCodecCtx->sample_rate;
pVideoOutCodecCtx->gop_size = 30;
Run Code Online (Sandbox Code Playgroud)
但是avcodec_open()失败了.
我需要设置哪些其他值才能使x264满意?
我想在C中制作一个快速程序,它将打开一个视频,将每个帧保存为ppm,并转储运动矢量.我能找到的所有教程都是近十年前的,并且调用了已弃用或不存在的函数.
是否有任何良好的在线资源,网站,视频或教科书涵盖了做这类事情的现代方法?
我有一个使用libav的程序.在调试模式下编译时,它运行良好(Windows,VisualStudio 2010).但是,当程序在发布模式下编译时,它会在av_register_all中崩溃.我得到的例外是特权指令.
任何人都知道在Release模式下是否需要进行任何特殊操作才能使libav工作?
最好的问候冉
从AV_SAMPLE_FMT_S16P转换到AV_SAMPLE_FMT_S16时会发生什么?AVFrame结构如何包含平面和非平面数据?
如何在FFmpeg C API编码之前计算帧的正确PTS值?
对于编码我正在使用函数avcodec_encode_video2,然后通过编写它av_interleaved_write_frame.
我发现了一些公式,但其中没有一个不起作用.
在doxygen示例中,他们正在使用
frame->pts = 0;
for (;;) {
// encode & write frame
// ...
frame->pts += av_rescale_q(1, video_st->codec->time_base, video_st->time_base);
}
Run Code Online (Sandbox Code Playgroud)
这篇博客说公式必须是这样的:
(1/FPS)*采样率*帧数
有人只使用帧号来设置pts:
frame->pts = videoCodecCtx->frame_number;
Run Code Online (Sandbox Code Playgroud)
或者替代方式:
int64_t now = av_gettime();
frame->pts = av_rescale_q(now, (AVRational){1, 1000000}, videoCodecCtx->time_base);
Run Code Online (Sandbox Code Playgroud)
最后一个:
// 40 * 90 means 40 ms and 90 because of the 90kHz by the standard for PTS-values.
frame->pts = encodedFrames * 40 * 90;
Run Code Online (Sandbox Code Playgroud)
哪一个是正确的?我认为这个问题的答案不仅对我有帮助.
我用avfc_decode_audio3用ffmpeg将aac解码为pcm.然而,它解码为AV_SAMPLE_FMT_FLTP样本格式(PCM 32位浮点平面),我需要AV_SAMPLE_FMT_S16(PCM 16位签名 - S16LE).
我知道ffmpeg可以使用-sample_fmt轻松完成此操作.我想对代码做同样的事情,但我仍然无法弄明白.
audio_resample不起作用:它失败并显示错误消息:....转换失败.
因此,我想使用libav 在特定时间从视频中抓取一个帧作为缩略图使用.
我正在使用的是以下代码.它编译和工作正常(关于检索图片),但我很难找到它来检索正确的图片.
我根本无法理解libav明显使用每个视频的多个时基背后的明确逻辑.具体说明哪些函数期望/返回哪种类型的时基.
不幸的是,文档基本上没有任何帮助.那么救援?
#define ABORT(x) do {fprintf(stderr, x); exit(1);} while(0)
av_register_all();
AVFormatContext *format_context = ...;
AVCodec *codec = ...;
AVStream *stream = ...;
AVCodecContext *codec_context = ...;
int stream_index = ...;
// open codec_context, etc.
AVRational stream_time_base = stream->time_base;
AVRational codec_time_base = codec_context->time_base;
printf("stream_time_base: %d / %d = %.5f\n", stream_time_base.num, stream_time_base.den, av_q2d(stream_time_base));
printf("codec_time_base: %d / %d = %.5f\n\n", codec_time_base.num, codec_time_base.den, av_q2d(codec_time_base));
AVFrame *frame = avcodec_alloc_frame();
printf("duration: %lld @ %d/sec (%.2f sec)\n", …Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,它从输入文件(任何编解码器,任何容器)解码单个视频流,进行一堆图像处理,并将结果编码为输出文件(单个视频流,Quicktime RLE,MOV).我正在使用ffmpeg的libav 3.1.5(目前是Windows版本,但应用程序将是跨平台的).
输入帧和输出帧之间存在1:1的对应关系,我希望输出中的帧时序与输入相同.我真的很难完成这件事.所以我的一般问题是:我如何可靠地(在所有输入情况下)将输出帧时序设置为与输入相同?
我花了很长时间来讨论API并且达到了我现在的目的.我整理了一个最小的测试程序来处理:
#include <cstdio>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}
using namespace std;
struct DecoderStuff {
AVFormatContext *formatx;
int nstream;
AVCodec *codec;
AVStream *stream;
AVCodecContext *codecx;
AVFrame *rawframe;
AVFrame *rgbframe;
SwsContext *swsx;
};
struct EncoderStuff {
AVFormatContext *formatx;
AVCodec *codec;
AVStream *stream;
AVCodecContext *codecx;
};
template <typename T>
static void dump_timebase (const char *what, const T *o) {
if (o)
printf("%s timebase: %d/%d\n", what, o->time_base.num, o->time_base.den); …Run Code Online (Sandbox Code Playgroud) 默认情况下,libavformat将错误消息写入stderr,如:
Estimating duration from bitrate, this may be inaccurate
我怎么能把它关掉?或者更好的是,把它管道到我自己的整洁记录功能?
编辑:将stderr重定向到其他地方是不可接受的,因为我需要它用于其他日志记录目的,我只是希望libavformat不写入它.
libav ×10
ffmpeg ×8
c ×3
libavcodec ×3
audio ×2
android-ndk ×1
c++ ×1
libavformat ×1
libx264 ×1
pcm ×1
pts ×1
sample ×1
transcoding ×1
ubuntu ×1
video ×1
x264 ×1