【问题标题】:Trying to determine h.264 profile & level pragmatically尝试务实地确定 h.264 配置文件和级别
【发布时间】:2011-12-25 05:18:38
【问题描述】:

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

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

【问题讨论】:

    标签: encoding ffmpeg h.264 video-encoding


    【解决方案1】:

    这是我写的一个小程序。它打印使用 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;
    }
    

    【讨论】:

      【解决方案2】:

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

      查看H.264 stream header 和那里的链接。

      【讨论】:

        猜你喜欢
        • 2016-10-24
        • 2021-12-27
        • 1970-01-01
        • 1970-01-01
        • 2019-08-03
        • 2013-10-21
        • 1970-01-01
        • 2022-01-19
        • 2012-03-25
        相关资源
        最近更新 更多