尝试确定 h.264 配置文件和务实的水平

发布于 2024-12-14 14:13:47 字数 405 浏览 2 评论 0原文

理想情况下,解决方案是在 python 和跨平台中,但这可能不太可能,所以我所需要的只是它在 Linux 中工作,并且如果需要,我可以使用 ac 扩展来与 python 接口。我看到有一个用于 ffmpeg 的 python 绑定,我正在考虑使用它,但是我无法弄清楚如何使用 fmmpeg 或其他任何东西来确定配置文件和级别,更不用说实用了。谷歌在这件事上也没有提供太多帮助。

我已经能够确定我要寻找的功能,如果我需要手动确定配置文件和级别,那么我可以这样做,但这会导致问题,ffmpeg 可以确定视频是否用该编码进行编码吗?功能集?我想我想知道的是,编码后是否可能无法完全确定级别和特定配置文件?我认为你必须知道才能解码它,但也许不是;这可以解释为什么我找不到任何相关信息。我已经断断续续地考虑这个问题有一段时间了,但最近决定考虑一个我一直在考虑的项目,但这是阻碍我的大事之一。

Ideally the solution would be in python and cross platform, but that's probably not too likely, so all I require is it work in linux, and I can use a c extension to interface w/python if necessary. I see there is a python binding for ffmpeg which I was thinking about using, however I can't figure out how to determine the profile and level as it is, with fmmpeg or anything else, much less do it pragmatically. Google is not much help on the matter either.

I've been able to determine what features I'd be looking for if I needed to determine the profile and levels manually then I can do that, but then that leads to the question, can ffmpeg then determine if the video was encoded with that feature set? I guess what I'm wondering to that effect is, is it perhaps not possible to fully determine the level and specific profile after encoding? I would think you'd have to know in order to decode it, but maybe not; that would explain why I can't find any information on it. I've been toying with this on and off for awhile, but recently decided to consider a project I'd been thinking about, but this is one of this big things holding me back.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄人书 2024-12-21 14:13:47

这是我写的一个小程序。它打印使用 h264 作为视频编解码器的 MP4 文件的配置文件和级别。
您可以使用以下命令行编译它:

gcc -std=c99 printProfileAndLevel.c -o printProfileAndLevel

这是 C 源代码:

#include <stdio.h>
#include <stdlib.h>

void printProfile(int profile_idc, int profile_iop, int level_idc) {
  switch(profile_idc) {
    case 0x42: printf("Baseline Profile"); break;
    case 0x4D: printf("Main Profile"); break;
    case 0x58: printf("Extended Profile"); break;
    case 0x64: printf("High Profile"); break;
    default:   printf("Unknown profile (%x)", profile_idc);
  }

  switch(level_idc) {
    case 0x15: printf(" @ Level 2.1\n"); break;
    case 0x1F: printf(" @ Level 3.1\n"); break;
    case 0x29: printf(" @ Level 4.1\n"); break;
    case 0x33: printf(" @ Level 5.1\n"); break;
    default:   printf(" @ unknown level (%x)", level_idc);
  }
}

int main(int argc, char* argv[])
{
  if(argc < 2) {
    printf("syntax: %s <files>\n", argv[0]);
    exit(-1);
  }

  int buffsize = 1024;
  char *buffer = malloc(buffsize + 1);

  for(int nArg = 1; nArg < argc; nArg++) {
    printf("File %s:\n", argv[nArg]);
    FILE *file = fopen(argv[nArg], "r+");
    if(file == NULL) {
      printf("Cannot open input file %s\n", argv[nArg]);
      continue;
    }

    int nRead = 0;
    nRead = fread(buffer, 1, buffsize, file);

    for(int i = 0; i < nRead - 7; i++) {
      if(buffer[i] == 0x61 && buffer[i+1] == 0x76 && buffer[i+2] == 0x63 && buffer[i+3] == 0x43) {
        printProfile(buffer[i+5], buffer[i+6], buffer[i+7]);
      }
    }
    fclose(file);
  }
  free(buffer);
  return 0;
}

Here is a small program I wrote. It prints the profile and level of MP4 files that use h264 as the video codec.
You can compile it with the following command line:

gcc -std=c99 printProfileAndLevel.c -o printProfileAndLevel

Here is the C source :

#include <stdio.h>
#include <stdlib.h>

void printProfile(int profile_idc, int profile_iop, int level_idc) {
  switch(profile_idc) {
    case 0x42: printf("Baseline Profile"); break;
    case 0x4D: printf("Main Profile"); break;
    case 0x58: printf("Extended Profile"); break;
    case 0x64: printf("High Profile"); break;
    default:   printf("Unknown profile (%x)", profile_idc);
  }

  switch(level_idc) {
    case 0x15: printf(" @ Level 2.1\n"); break;
    case 0x1F: printf(" @ Level 3.1\n"); break;
    case 0x29: printf(" @ Level 4.1\n"); break;
    case 0x33: printf(" @ Level 5.1\n"); break;
    default:   printf(" @ unknown level (%x)", level_idc);
  }
}

int main(int argc, char* argv[])
{
  if(argc < 2) {
    printf("syntax: %s <files>\n", argv[0]);
    exit(-1);
  }

  int buffsize = 1024;
  char *buffer = malloc(buffsize + 1);

  for(int nArg = 1; nArg < argc; nArg++) {
    printf("File %s:\n", argv[nArg]);
    FILE *file = fopen(argv[nArg], "r+");
    if(file == NULL) {
      printf("Cannot open input file %s\n", argv[nArg]);
      continue;
    }

    int nRead = 0;
    nRead = fread(buffer, 1, buffsize, file);

    for(int i = 0; i < nRead - 7; i++) {
      if(buffer[i] == 0x61 && buffer[i+1] == 0x76 && buffer[i+2] == 0x63 && buffer[i+3] == 0x43) {
        printProfile(buffer[i+5], buffer[i+6], buffer[i+7]);
      }
    }
    fclose(file);
  }
  free(buffer);
  return 0;
}
单挑你×的.吻 2024-12-21 14:13:47

基本上,您需要识别比特流中的 SPS(序列参数集)并解码其前导字节。

请参阅 H.264 流标头 及其链接。

Basically you need to identify SPS (Sequence Parameter Set) in the bitstream and decode a couple of its leading bytes.

See H.264 stream header and links there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文