标签: libavcodec

FFMPEG无法显示视频的持续时间

我正在尝试使用ffmpeg从视频文件中捕获帧,但我甚至无法获得视频的持续时间.每次当我尝试访问它时,pFormatCtx->duration 我都会得到0.我知道指针已初始化并包含正确的持续时间,因为如果我使用 av_dump_format(pFormatCtx, 0, videoName, 0);那么我实际上得到持续时间数据以及有关视频的其他信息.这是我使用时得到的av_dump_format(pFormatCtx, 0, videoName, 0);:

输入#0,avi,来自'futurama.avi':

持续时间:00:21:36.28,开始:0.000000,比特率:1135 kb/s

流#0.0:视频:mpeg4(高级简单配置文件),yuv420p,512x384

[PAR 1:1 DAR 4:3],25 tbr,25 tbn,25 tbc

流#0.1:音频:ac3,48000Hz,立体声,s16,192kb/s

我不明白为什么av_dum_format可以显示持续时间而我不能.我检查了函数定义,显示持续时间,该函数也使用pFormatCtx-> duration.当我在main.cpp中调用它们时,其他成员变量也不会显示正确的数据

这是我的main.cpp:

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


int main(int argc, char *argv[]) {
    AVFormatContext *pFormatCtx = NULL;

    const char videoName[] = "futurama.avi";

    // Register all formats and codecs.
    av_register_all();
    cout << "Opening the video file";
    // Open video file
    int ret = avformat_open_input(&pFormatCtx, videoName, NULL, NULL) != 0;
    if (ret …
Run Code Online (Sandbox Code Playgroud)

c c++ ffmpeg video-processing libavcodec

6
推荐指数
2
解决办法
5909
查看次数

在mp4容器中保存视频时FPS太高

当我从avi文件解码帧然后在x264中解码它们并保存到mp4文件时,输出文件的fps总是12,800.因此文件播放速度非常快.但是,当我以avi格式保存编码的h264帧而不是mp4时,所以fps就像我想要的那样--25.

可能是什么问题呢?

这里是我在VS2010中编写的代码:

#include "stdafx.h"
#include "inttypes.h"

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include <libswscale/swscale.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}

#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
   const char* inFileName = "C:\\000227_C1_GAME.avi";
   const char* outFileName = "c:\\test.avi";
   const char* outFileType = "avi";

   av_register_all();

   AVFormatContext* inContainer = NULL;   
   if(avformat_open_input(&inContainer, inFileName, NULL, NULL) < 0)   
      exit(1);

   if(avformat_find_stream_info(inContainer, NULL) < 0)
      exit(1);

   // Find video stream
   int videoStreamIndex = -1;
   for (unsigned int i …
Run Code Online (Sandbox Code Playgroud)

c++ mp4 ffmpeg libavcodec libx264

6
推荐指数
1
解决办法
3764
查看次数

当输入pcm样本计数不等于1024时,如何使用ffmpeg-API将重采样的PCM音频编码为AAC

我正在努力捕获并将音频流传输到RTMP服务器.我在MacOS下工作(在Xcode中),所以为了捕获音频样本缓冲区我使用AVFoundation-framework.但是对于编码和流媒体,我需要使用ffmpeg-API和libfaac编码器.因此输出格式必须是AAC(用于支持iOS设备上的流播放).

我遇到了这样的问题:音频捕获设备(在我的案例中是罗技相机)为我提供了512个LPCM样本的样本缓冲区,我可以选择16000,24000,36000或48000 Hz的输入采样率.当我将这512个样本提供给AAC编码器(配置为适当的采样率)时,我听到一个缓慢而抽搐的音频(在每帧之后看起来像是沉默的骰子).

我想通了(也许我错了),libfaac编码器只接受1024个样本的音频帧.当我将输入采样率设置为24000并在编码之前将输入采样缓冲区重采样为48000时,我获得1024个重采样样本.将这些1024个样本编码到AAC后,我听到输出声音正确.但是,当输出采样率必须为48000 Hz时,我的网络摄像头会在缓冲区中为任何输入采样率生成512个样本.所以我需要在任何情况下进行重采样,重新采样后我不会在缓冲区中获得1024个样本.

有没有办法在ffmpeg-API功能中解决这个问题

我将不胜感激任何帮助.

PS:我想我可以累积重采样缓冲区,直到样本数变为1024,然后对其进行编码,但这是流,因此会产生时间戳和其他输入设备的麻烦,并且这种解决方案不合适.

当前问题出自[问题]中描述的问题:如何使用从CMSampleBufferRef(AVFoundation)获得的数据填充音频AVFrame(ffmpeg)?

这是一个带有音频编解码器配置的代码(还有视频流,但视频工作正常):

    /*global variables*/
    static AVFrame *aframe;
    static AVFrame *frame;
    AVOutputFormat *fmt; 
    AVFormatContext *oc; 
    AVStream *audio_st, *video_st;
Init ()
{
    AVCodec *audio_codec, *video_codec;
    int ret;

    avcodec_register_all();  
    av_register_all();
    avformat_network_init();
    avformat_alloc_output_context2(&oc, NULL, "flv", filename);
    fmt = oc->oformat;
    oc->oformat->video_codec = AV_CODEC_ID_H264;
    oc->oformat->audio_codec = AV_CODEC_ID_AAC;
    video_st = NULL;
    audio_st = NULL;
    if (fmt->video_codec != AV_CODEC_ID_NONE) 
      { //…  /*init video codec*/}
    if (fmt->audio_codec != AV_CODEC_ID_NONE) {
    audio_codec= avcodec_find_encoder(fmt->audio_codec);

    if (!(audio_codec)) {
        fprintf(stderr, "Could …
Run Code Online (Sandbox Code Playgroud)

ffmpeg aac resampling libavcodec libfaac

6
推荐指数
1
解决办法
1万
查看次数

FFmpeg使用avcodec_decode_video2解码原始缓冲区

我收到一个h264流,我至少知道一帧的大小.流正好进入,因为我可以将其存储在文件中并使用vlc进行播放.回放文件对我来说没问题,因为我包含了libavformat.但是libavformat给了我一个AVPacket,我可以直接给avogramc_decode_video2.在这种情况下,我得到了一个字节流.如何将原始h264流提供给avcodec_decode_video2?如何将数据包装到AVPacket中.VLC不需要猜测任何数据.

c++ ffmpeg libavcodec

6
推荐指数
1
解决办法
9649
查看次数

无法安装avconv/libav

我在OS X Mavericks上没有运气安装libav.我尝试了一切.

我正在遵循本指南:http://earthwithsun.com/questions/568464/install-latest-libav-avconv-on-osx

在完成macport依赖性检查后,我会运行

./configure \
--enable-gpl --enable-libx264 --enable-libxvid \
--enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb \
--enable-nonfree --enable-libfaac \
--enable-libmp3lame --enable-libspeex --enable-libvorbis --enable-libtheora --enable-libvpx \
--enable-libopenjpeg --enable-libfreetype --enable-doc --enable-gnutls --enable-shared
Run Code Online (Sandbox Code Playgroud)

此操作失败,并显示以下错误:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
ERROR: gnutls not found

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report …
Run Code Online (Sandbox Code Playgroud)

macos configure libavcodec libav avconv

6
推荐指数
2
解决办法
7353
查看次数

创建一个mpeg-dash段

我有用mpeg-dash编码的视频(*.mpd,init段,视频片段)任务是用我生成的片段替换其中一个视频片段.所以视频仍然可以播放.

我使用了读取一个段的属性(组合init段和视频段)

avformat_open_input
avformat_find_stream_info
Run Code Online (Sandbox Code Playgroud)

1)我曾尝试使用dash muxer生成新的段.

avformat_alloc_output_context2(&avFormatContext, NULL, "dash", filename)
Run Code Online (Sandbox Code Playgroud)

但问题是它创建了mpd清单和其他段.那么如何强制它创建一个细分?

2)当我解析段时,我注意到它的格式为"QuickTime/MOV".

avformat_alloc_output_context2(&avFormatContext, NULL, "mov", filename);
Run Code Online (Sandbox Code Playgroud)

所以我的另一个想法是使用"mov"编码器.并设置与初始段(开始时间,持续时间,分辨率)相同的属性.但这里的问题是如何删除init标头?因为我已经有了init段.

有没有其他方法来生成一个mpeg-dash段以及如何解决我的问题?

c++ ffmpeg libavcodec libav mpeg-dash

6
推荐指数
0
解决办法
427
查看次数

如何使用 ffmpeg / libavfilter 输出原始频率 (fft) 数据

我正在尝试编写 libavfilter 绑定以将任意音频文件转换为原始频率(频谱)数据以进行后续音频分析。是否有内置的 ffmpeg 或 libavfilter 来输出二进制频率数据,而不是正确的音频/视频文件?

FFmpeg 有一些执行 FFT 的内置过滤器,例如afftfiltshowfreqs,但是这些过滤器总是将输出转换回视频或音频。我需要的是类似于afftfilt过滤器的东西,但它会转储原始 FFT 数据,而不是将其重新编码回 PCM。

audio ffmpeg libavcodec libav

6
推荐指数
1
解决办法
1006
查看次数

为什么将音频流添加到 ffmpeg 的 libavcodec 输出容器会导致崩溃?

就目前而言,我的项目正确使用 libavcodec 解码视频,其中每一帧都被操纵(无论如何)并输出到新视频。我从网上找到的例子拼凑起来,它的工作原理。结果是处理过的帧的完美 .mp4,减去音频。

我的问题是,当我尝试将音频流添加到输出容器时,我在 mux.c 中遇到了无法解释的崩溃。它在static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt). 当st->internal->priv_pts->val = pkt->dts;尝试,priv_pts是nullptr。

我不记得版本号,但这是 2020 年 11 月 4 日 ffmpeg 从 git 构建的。

我的MediaContentMgr比我在这里的要大得多。我正在剥离与帧操作有关的所有内容,因此如果我遗漏了任何内容,请告诉我,我会进行编辑。

添加时触发 nullptr 异常的代码被内联调用

.h:

#ifndef _API_EXAMPLE_H
#define _API_EXAMPLE_H

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "glm/glm.hpp"

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
}

#include "shader_s.h"

class MediaContainerMgr {
public:
    MediaContainerMgr(const std::string& infile, const std::string& vert, const std::string& frag, …
Run Code Online (Sandbox Code Playgroud)

c++ crash ffmpeg nullptr libavcodec

6
推荐指数
1
解决办法
406
查看次数

FFmpeg中按字节查找

我将感谢您对以下方面的建议。我正在开发一个基于FFmpeg的libavformat的视频转换器,我需要实现一个精确的查找API。首先,我开发了一个视频流索引器,它只保存每个数据包的呈现时间戳(PTS)。然后我的编码器使用这个索引来寻找视频文件。例如,在此操作之前,我将文件重新混合到 mp4 容器。对于内部没有正确索引或视频根本没有索引的视频,需要进行 Remux。我需要实现按字节查找,当然需要使用之前构建的索引。我尝试了很多方法来实现这一点,但没有成功。也许你知道如何在FFmpeg中实现按字节精确查找?此致。

ffmpeg fseek seek libavcodec libavformat

5
推荐指数
1
解决办法
2450
查看次数

avcodec_open2 错误 -542398533:“外部库中的一般错误”

我在尝试使用 . 打开编解码器时遇到错误avcodec_open2()avi如果我指定而不是在函数h264中指定,我已经尝试了相同的代码,没有任何问题av_guess_format()

我不知道该怎么办。还有其他人遇到过类似的问题吗?

我正在使用的库是ffmpeg-20160219-git-98a0053-win32-dev。如果您能帮助我摆脱这种困惑,我将非常感激。

这是我的控制台输出:

视频编码
[libx264 @ 01383460] 检测到损坏的 ffmpeg 默认设置
[libx264 @ 01383460] 使用编码预设(例如 -vpre 中)
[libx264 @ 01383460] 预设用法:-vpre -vpre
[libx264 @ 01383460] 速度预设在 x264 中列出--help
[libx264 @ 01383460] 配置文件是可选的;x264 默认为高
无法打开视频编解码器,-542398533

这是我正在使用的代码:

// Video encoding sample
AVCodec *codec = NULL;
AVCodecContext *codecCtx= NULL;
AVFormatContext *pFormatCtx = NULL;
AVOutputFormat *pOutFormat = NULL;
AVStream * pVideoStream = NULL;;
AVFrame *picture = NULL;;

int i, x, y, ret; …
Run Code Online (Sandbox Code Playgroud)

c++ ffmpeg libavcodec

5
推荐指数
1
解决办法
7873
查看次数