【问题标题】:FFMPEG: Is it possible to get coded_width in new API?FFMPEG:是否有可能在新 API 中获得 coded_width?
【发布时间】:2018-07-25 10:53:26
【问题描述】:

考虑以下代码(为简洁起见,不进行初始化)。

AVFormatContext *formatCtx;
int coded_width = formatCtx->streams[videoStreamIndex]->codec->coded_width;

在旧 API 中,可以通过这种方式获取 coded_widthcoded_height。目前它已被弃用。有 AVCodecParametersstruct 但它只提供:

int width
int height

可能与

不同
int coded_width
int coded_height

那么,是否有可能在不使用已弃用的streams[videoStreamIndex]->codec 的情况下获得 coded_width?

【问题讨论】:

    标签: ffmpeg libavcodec libav libavformat


    【解决方案1】:

    对于迟到的回复,我深表歉意。根据@the kamilz FFMPEG: Is it possible to get coded_width in new API? 的回复,最好的解决方案似乎只是在头文件中抑制这个警告。 (我正在使用 gcc 编译器)。

    #pragma GCC 诊断忽略“-Wdeprecated-declarations”

    【讨论】:

      【解决方案2】:

      根据最新的 doxygen 文档,这些仍然有效,目前在 ffmpeg 中使用:

      声明(不带deprecated pragma):
      https://www.ffmpeg.org/doxygen/trunk/structAVCodecContext.html#ae3c157e97ff15d46e898a538c6bc7f09

      用于:
      https://www.ffmpeg.org/doxygen/trunk/qsvdec_8c-example.html#a21

      希望对您有所帮助。

      【讨论】:

      • 代码:formatCtx->streams[videoStreamIndex]->codec->coded_width,类型:AVFormatContext->AVStream->AVCodecContext->int。我可以在没有警告的情况下声明或使用AVCodecContext struct 等等。但是使用formatCtx->streams[videoStreamIndex]->codec 会引发警告。因此,通常可以毫无问题地使用AVCodecContext 结构,但不建议从 AVStream 中获取此结构的信息。看看ffmpeg.org/doxygen/3.0/structAVStream.htmlffmpeg.org/doxygen/3.3/structAVStream.htmlAVCodecContext *codec 在新的一个文档中不存在。
      • 我认为你应该使用编译指示来抑制弃用警告作为这种情况的例外,我刚刚检查了带有关键字coded_width的ffmpeg源代码(github)。像您一样使用签名,似乎非常合法,至少对于最新版本而言。
      【解决方案3】:

      为了获得 coded_width 和 coded_height 你也可以使用ffprobe,如果你运行的话:

      ffprobe -show_streams -i video.mp4
      

      你会得到一个包含 coded_width & coded_height 的流对象:

      index=0
      codec_name=h264
      codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
      profile=High
      codec_type=video
      codec_time_base=9772827/468627200
      codec_tag_string=avc1
      codec_tag=0x31637661
      width=1280
      height=720
      coded_width=1280
      coded_height=720
      has_b_frames=2
      

      【讨论】:

      • 问题是关于 API 使用,而不是命令行。在后台ffprobe 显示了已弃用结构中的值。这正是提问者试图避免的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多