标签: libavformat

如何获取视频文件的I/P/B帧数?

我想提取视频文件的信息以获得其I/P/B帧的计数.如何在ffmpeg中做到这一点?或者我应该使用libavformat和libavcodec进行编程吗?非常感谢!

video opencv ffmpeg libavcodec libavformat

4
推荐指数
1
解决办法
2855
查看次数

ffmpeg/libavcodec内存管理

libavcodec文档对于何时释放已分配的数据以及如何释放它并不十分具体.阅读完文档和示例后,我将下面的示例程序放在一起.在源代码中有一些特定的问题,但我的一般问题是,我是否在下面的代码中正确释放所有内存?我意识到下面的程序在发生错误后没有进行任何清理 - 重点是最终清理.

testfile()函数是有问题的.

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
}

#include <cstdio>

using namespace std;


void AVFAIL (int code, const char *what) {
    char msg[500];
    av_strerror(code, msg, sizeof(msg));
    fprintf(stderr, "failed: %s\nerror: %s\n", what, msg);
    exit(2);
}

#define AVCHECK(f) do { int e = (f); if (e < 0) AVFAIL(e, #f); } while (0)
#define AVCHECKPTR(p,f) do { p = (f); if (!p) AVFAIL(AVERROR_UNKNOWN, #f); } while (0)


void testfile (const char *filename) {

    AVFormatContext *format;
    unsigned …
Run Code Online (Sandbox Code Playgroud)

memory-leaks ffmpeg libavcodec libav libavformat

4
推荐指数
1
解决办法
5713
查看次数

可靠地获得ffmpeg中的PTS值?

我正在尝试编写一个方法,在查询时提供下一帧和显示时间戳.代码目前看起来像这样:

while( getNextFrame(image, pts) )
{
    // show current image
    drawImage(currentImage);
    sleep(pts);
    currentImage = image;
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我一直在关注Dranger教程,但是为了可靠地获取帧的PTS值而停滞不前(http://www.dranger.com/ffmpeg/tutorial05.html).返回的PTS值始终为0.

此外,get_buffer()已被弃用,所以我现在使用该get_buffer2()方法设置全局pts值.但是,该release_buffer方法也已被弃用,我似乎无法找到它的替代品.这让我相信教程中列出的方法可能不再是完成此任务的最佳方法.

简而言之,使用最新的ffmpeg,可靠地获取帧pts值的最佳方法是什么?

video ffmpeg pts libavcodec libavformat

4
推荐指数
1
解决办法
3707
查看次数

如何确定编解码器/容器组合是否与 FFmpeg 兼容?

我正在考虑重新混合一些保存音频和视频的容器,以便提取最好的第一个音频流,并将其存储在一个新容器中,例如存在音频流。

\n\n

FFmpeg 的输出上下文是这样创建的:

\n\n
AVFormatContext* output_context = NULL;\navformat_alloc_output_context2( &output_context, NULL, "mp4", NULL );\n
Run Code Online (Sandbox Code Playgroud)\n\n

我有一个可接受的输出的候选列表,例如 MP4、M4A 等 \xe2\x80\xa6 基本上是 Apple 的音频文件服务可读的输出:

\n\n
kAudioFileAIFFType              = \'AIFF\',\nkAudioFileAIFCType              = \'AIFC\',\nkAudioFileWAVEType              = \'WAVE\',\nkAudioFileSoundDesigner2Type    = \'Sd2f\',\nkAudioFileNextType              = \'NeXT\',\nkAudioFileMP3Type               = \'MPG3\',   // mpeg layer 3\nkAudioFileMP2Type               = \'MPG2\',   // mpeg layer 2\nkAudioFileMP1Type               = \'MPG1\',   // mpeg layer 1\nkAudioFileAC3Type               = \'ac-3\',\nkAudioFileAAC_ADTSType          = \'adts\',\nkAudioFileMPEG4Type             = \'mp4f\',\nkAudioFileM4AType               = \'m4af\',\nkAudioFileM4BType               = \'m4bf\',\nkAudioFileCAFType               = \'caff\',\nkAudioFile3GPType               = \'3gpp\',\nkAudioFile3GP2Type              = \'3gp2\',\nkAudioFileAMRType               = \'amrf\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的问题是:FFmpeg 中是否有一个简单的 API,可以根据音频流所在的编解码器来选择兼容的输出容器?

\n

audio ffmpeg libavcodec libav libavformat

4
推荐指数
1
解决办法
2470
查看次数

avio_set_interrupt_cb的替代是什么?

是否在新的ffmpeg版本中弃用了avio_set_interrupt_cb?替补是什么?

ffmpeg libav libavformat

3
推荐指数
1
解决办法
1752
查看次数

FFMpeg 无需转码即可复制流

我正在尝试将多个文件中的所有流复制到一个文件中,而无需对流进行转码。你通常用ffmpeg效用做的事情ffmpeg -i “file_with_audio.mp4” -i “file_with_video.mp4” -c copy -shortest file_with_audio_and_video.mp4

这是代码:

int ffmpegOpenInputFile(const char* filename, AVFormatContext **ic) {

    int ret;
    unsigned int i;

    *ic = avformat_alloc_context();
    if (!(*ic))
        return -1; // Couldn't allocate input context

    if((ret = avformat_open_input(ic, filename, NULL, NULL)) < 0)
        return ret; // Couldn't open file

    // Get format info (retrieve stream information)
    if ((ret = avformat_find_stream_info(*ic, NULL)) < 0)
        return ret; // Couldn't find stream information

    for (int i = 0; i < (*ic)->nb_streams; …
Run Code Online (Sandbox Code Playgroud)

c ffmpeg libavcodec libavformat

3
推荐指数
1
解决办法
7269
查看次数

在Visual Studio 2010中链接libavformat

我正在尝试围绕libavformat构建一些视频阅读代码.获得编译的DLL和之后.lib的文件在这里,我去打造我的代码,并链接器无法找到任何即使我在所提供的已关联了libavformat符号的 .lib文件.

检查libavformat.libdumpbin -headers显示它导出所需功能以下划线前缀.例如,当我想调用时avformat_open_input,.lib文件给出_avformat_open_input.

为什么会这样,为什么我不能链接预编译的dll?

c++ ffmpeg visual-studio-2010 visual-c++ libavformat

2
推荐指数
1
解决办法
3295
查看次数

如何使用 ffmpeg 的库将 YUV420P 图像转换为 JPEG?

我正在尝试AV_PIX_FMT_YUV420P使用 ffmpeglibavformat和将 YUV420P 图像()转换为 JPEG libavcodec。到目前为止,这是我的代码:

AVFormatContext* pFormatCtx;
AVOutputFormat* fmt;
AVStream* video_st;
AVCodecContext* pCodecCtx;
AVCodec* pCodec;

uint8_t* picture_buf;
AVFrame* picture;
AVPacket pkt;
int y_size;
int got_picture=0;
int size;

int ret=0;

FILE *in_file = NULL;                            //YUV source
int in_w = 720, in_h = 576;                      //YUV's width and height
const char* out_file = "encoded_pic.jpg";    //Output file

in_file = fopen(argv[1], "rb");
av_register_all();

pFormatCtx = avformat_alloc_context();

fmt = NULL;
fmt = av_guess_format("mjpeg", NULL, NULL);
pFormatCtx->oformat = fmt;

//Output URL …
Run Code Online (Sandbox Code Playgroud)

jpeg yuv libavcodec libavformat

2
推荐指数
1
解决办法
5024
查看次数

如何将 AVFrame 写出为 JPEG 图像

我正在编写一个程序来从视频流中提取图像。到目前为止,我已经弄清楚如何寻找正确的帧,解码视频流,并将相关数据收集到 AVFrame 结构中。我现在试图将数据写成 JPEG 图像,但我的代码不起作用。我得到的代码来自这里:https : //gist.github.com/RLovelett/67856c5bfdf5739944ed

int save_frame_as_jpeg(AVCodecContext *pCodecCtx, AVFrame *pFrame, int FrameNo) {
    AVCodec *jpegCodec = avcodec_find_encoder(AV_CODEC_ID_JPEG2000);
    if (!jpegCodec) {
        return -1;
    }
    AVCodecContext *jpegContext = avcodec_alloc_context3(jpegCodec);
    if (!jpegContext) {
        return -1;
    }

    jpegContext->pix_fmt = pCodecCtx->pix_fmt;
    jpegContext->height = pFrame->height;
    jpegContext->width = pFrame->width;

    if (avcodec_open2(jpegContext, jpegCodec, NULL) < 0) {
        return -1;
    }
    FILE *JPEGFile;
    char JPEGFName[256];

    AVPacket packet = {.data = NULL, .size = 0};
    av_init_packet(&packet);
    int gotFrame;

    if (avcodec_encode_video2(jpegContext, &packet, pFrame, &gotFrame) < 0) {
        return …
Run Code Online (Sandbox Code Playgroud)

encoding jpeg ffmpeg libavcodec libavformat

2
推荐指数
1
解决办法
4664
查看次数

我可以使用 av_write_frame() 而不是 av_interleaved_write_frame() 吗?

我正在使用 ffmpeg 在 Windows 平台上编写 AV muxer DirectShow Filter,它将视频和音频流混合到 mp4/ts/flv 文件或 rtsp/rtmp/udp 流中,我确认视频/音频流的 dts 有序增加所以不需要 dts 重新排序,所以我可以用av_write_frame()代替av_interleaved_write_frame()吗?av_write_frame()直接将数据包写入多路复用器,av_interleaved_write_frame()如果没有引用计数,则会复制数据包,所以我更喜欢使用,av_write_frame()因为我认为它应该更有效(没有复制或缓冲),我的想法正确吗?我可以使用av_write_frame()吗?

directshow ffmpeg libavformat

2
推荐指数
1
解决办法
2445
查看次数