H264解碼SPS獲取寬高和幀率
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include <math.h>
- typedef unsigned intUINT;
- typedef unsigned charBYTE;
- typedef unsigned longDWORD;
- UINT Ue(BYTE *pBuff, UINT nLen, UINT &nStartBit)
- {
- //計算0bit的個數
- UINT nZeroNum = 0;
-
while (nStartBit < nLen * 8)
- {
- if (pBuff[nStartBit / 8] & (0x80 >> (nStartBit % 8))) //&:按位與,%取餘
- {
- break;
- }
- nZeroNum++;
- nStartBit++;
- }
- nStartBit ++;
- //計算結果
- DWORD dwRet = 0;
- for (UINT i=0; i<nZeroNum; i++)
- {
-
dwRet <<= 1;
- if (pBuff[nStartBit / 8] & (0x80 >> (nStartBit % 8)))
- {
- dwRet += 1;
- }
- nStartBit++;
- }
- return (1 << nZeroNum) - 1 + dwRet;
- }
- int Se(BYTE *pBuff, UINT nLen, UINT &nStartBit)
- {
-
int UeVal=Ue(pBuff,nLen,nStartBit);
- double k=UeVal;
- int nValue=ceil(k/2);//ceil函式:ceil函式的作用是求不小於給定實數的最小整數。ceil(2)=ceil(1.2)=cei(1.5)=2.00
- if (UeVal % 2==0)
- nValue=-nValue;
- return nValue;
- }
- DWORD u(UINT BitCount,BYTE * buf,UINT &nStartBit)
- {
- DWORD dwRet = 0;
- for (UINT i=0; i<BitCount; i++)
- {
- dwRet <<= 1;
- if (buf[nStartBit / 8] & (0x80 >> (nStartBit % 8)))
- {
- dwRet += 1;
- }
- nStartBit++;
- }
- return dwRet;
- }
- /**
- * H264的NAL起始碼防競爭機制
- *
- * @param buf SPS資料內容
- *
- * @無返回值
- */
- void de_emulation_prevention(BYTE* buf,unsigned int* buf_size)
- {
- int i=0,j=0;
- BYTE* tmp_ptr=NULL;
- unsigned int tmp_buf_size=0;
- int val=0;
- tmp_ptr=buf;
- tmp_buf_size=*buf_size;
- for(i=0;i<(tmp_buf_size-2);i++)
- {
- //check for 0x000003
- val=(tmp_ptr[i]^0x00) +(tmp_ptr[i+1]^0x00)+(tmp_ptr[i+2]^0x03);
- if(val==0)
- {
- //kick out 0x03
- for(j=i+2;j<tmp_buf_size-1;j++)
- tmp_ptr[j]=tmp_ptr[j+1];
- //and so we should devrease bufsize
- (*buf_size)--;
- }
- }
- }
- /**
- * 解碼SPS,獲取視訊影象寬、高和幀率資訊
- *
- * @param buf SPS資料內容
- * @param nLen SPS資料的長度
- * @param width 影象寬度
- * @param height 影象高度
- * @成功則返回true , 失敗則返回false
- */
- bool h264_decode_sps(BYTE * buf,unsigned int nLen,int &width,int &height,int &fps)
- {
- UINT StartBit=0;
- fps=0;
- de_emulation_prevention(buf,&nLen);
- int forbidden_zero_bit=u(1,buf,StartBit);
- int nal_ref_idc=u(2,buf,StartBit);
- int nal_unit_type=u(5,buf,StartBit);
- if(nal_unit_type==7)
- {
- int profile_idc=u(8,buf,StartBit);
- int constraint_set0_flag=u(1,buf,StartBit);//(buf[1] & 0x80)>>7;
- int constraint_set1_flag=u(1,buf,StartBit);//(buf[1] & 0x40)>>6;
- int constraint_set2_flag=u(1,buf,StartBit);//(buf[1] & 0x20)>>5;
- int constraint_set3_flag=u(1,buf,StartBit);//(buf[1] & 0x10)>>4;
- int reserved_zero_4bits=u(4,buf,StartBit);
- int level_idc=u(8,buf,StartBit);
- int seq_parameter_set_id=Ue(buf,nLen,StartBit);
- if( profile_idc == 100 || profile_idc == 110 ||
- profile_idc == 122 || profile_idc == 144 )
- {
- int chroma_format_idc=Ue(buf,nLen,StartBit);
- if( chroma_format_idc == 3 )
- int residual_colour_transform_flag=u(1,buf,StartBit);
- int bit_depth_luma_minus8=Ue(buf,nLen,StartBit);
- int bit_depth_chroma_minus8=Ue(buf,nLen,StartBit);
- int qpprime_y_zero_transform_bypass_flag=u(1,buf,StartBit);
- int seq_scaling_matrix_present_flag=u(1,buf,StartBit);
- int seq_scaling_list_present_flag[8];
- if( seq_scaling_matrix_present_flag )
- {
- for( int i = 0; i < 8; i++ ) {
- seq_scaling_list_present_flag[i]=u(1,buf,StartBit);
- }
- }
- }
- int log2_max_frame_num_minus4=Ue(buf,nLen,StartBit);
- int pic_order_cnt_type=Ue(buf,nLen,StartBit);
- if( pic_order_cnt_type == 0 )
- int log2_max_pic_order_cnt_lsb_minus4=Ue(buf,nLen,StartBit);
- elseif( pic_order_cnt_type == 1 )
- {
- int delta_pic_order_always_zero_flag=u(1,buf,StartBit);
- int offset_for_non_ref_pic=Se(buf,nLen,StartBit);
- int offset_for_top_to_bottom_field=Se(buf,nLen,StartBit);
- int num_ref_frames_in_pic_order_cnt_cycle=Ue(buf,nLen,StartBit);
- int *offset_for_ref_frame=newint[num_ref_frames_in_pic_order_cnt_cycle];
- for( int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ )
- offset_for_ref_frame[i]=Se(buf,nLen,StartBit);
- delete [] offset_for_ref_frame;
- }
- int num_ref_frames=Ue(buf,nLen,StartBit);
- int gaps_in_frame_num_value_allowed_flag=u(1,buf,StartBit);
- int pic_width_in_mbs_minus1=Ue(buf,nLen,StartBit);
- int pic_height_in_map_units_minus1=Ue(buf,nLen,StartBit);
- width=(pic_width_in_mbs_minus1+1)*16;
- height=(pic_height_in_map_units_minus1+1)*16;
-
int
相關推薦
H264解碼SPS獲取寬高和幀率
#include <stdio.h> #include <stdint.h> #include <string.h> #include <math.h> typedef unsigned intUINT; typed
H.264(H264)解碼SPS獲取解析度和幀率
#include <stdio.h> #include <stdint.h> #include <string.h> #include <math.h> typedef unsigned int UINT; typedef
從H264/H265碼流中獲取寬、高及幀率
在做碼流分析時,影象解析度、幀率這類的基本資訊,當然不可少。本文介紹如何從NAL中計算到影象寬、高,還有解析度。於是H264和H265有相似性,就在一起寫了。 一、從碼流獲得寬、高 1、H264 寬高可從SPS欄位計算得到,公式如下: Width = (pic_width_in_mb
js 獲取圖片寬高 和 圖片大小
src 查看 nts 執行 input java image 創建 wid 獲取要查看大小的img varimg_url = ‘http://img5.imgtn.bdimg.com/it/u=4267222417,1017407570&fm=
C# 獲取當前屏幕的寬高和位置
rim 如何獲取 寬高 尺寸 裏的 獲取 建議 nds prim 上一篇博客《C# 獲取當前屏幕DPI》,介紹了如何獲取當前屏幕的DPI設置 本章主要介紹如何獲取當前窗口所在屏幕的信息 當前屏幕信息 如果當前是單屏幕,可以直接獲取主屏幕 var prim
獲取遠端圖片的寬高和體積大小(php封裝方法)
/** * 獲取遠端圖片的寬高和體積大小 * * @param string $url 遠端圖片的連結 * @param string $type 獲取遠端圖片資源的方式, 預設為 curl 可選 fread * @param boolean $isGetFiles
【Android】獲取控制元件的寬高和位置
獲取控制元件的絕對位置(包括狀態列)可以用這種方法,呼叫方法後,location[0]和location[1]就分別被賦值了。 int[] location = new int[2]; view.getLocationOnScreen(loc
獲取當前螢幕的寬高和畫素點
import React, {Component} from 'react'; import { AppRegistry,//註冊 StyleSheet,//樣式 Text,/
Android——View寬高的設定和多種獲取寬高的方法、layout_grivaty與grivaty的區別
一、設定控制元件寬高 設定Layout_width/height引發的寬高思考 方式一: 結果不符合預期。 執行結果: 方式二: 結果符合預期。 如下圖: Android控制元件寬高的規則: Android下的控制元件預設沒有寬高,是由
JS 、JQ 獲取寬高總結
bsp image 技術 獲取 cnblogs 技術分享 src 寬高 png JS 、JQ 獲取寬高總結
div的最小寬高和最大寬高
才會 width 問題 就會 裏的 屬性 解決 auto 內容 div的最小寬高和最大寬高很少使用但是很實用,今天敲代碼,就遇到了,要在div裏設置滾動條,眾所周知,一般是設overflow-y:auto,但需要一個高度,只有div裏的內容超過這個高度時,才會有滾動條效果。
小程序之創建節點選擇器獲取寬高
http cli GC idt exe class 創建 程序 sele 1.獲取方法 onLoad: function (e) { var that = this; wx.createSelectorQuery().select(‘
JavaScript 中禁止用戶右鍵菜單,復制,選取,Ctrl,Alt,Shift. 獲取寬高
UNC 瀏覽器 func nth 包括 窗口 etl ron menu //禁用右鍵菜單 document.oncontextmenu = function(){ event.returnValue = false; } //禁用選取內容 document.ons
ImageView獲取寬高
public @override eas ide red 獲取 runnable creat 圖片 在Android裏放置一個ImageView,寬和高都是200.1、在Android OnCreate裏如果直接使用iv.GetWidth()返回值為0. 2、如果使用網上
***獲取螢幕寬高 :width(),height(),clientHeight,clientWidth 獲取寬高的區別*
獲取螢幕寬高 :width(),height(),clientHeight,clientWidth 獲取寬高的區別 $(window).width() & $(window).height():獲得的是螢幕可視區域的寬高,不包括滾動條與工具條。 $(window).heigh
Java小遊戲DanceWithStars(二):修改本地文件中的圖片(圖片寬高和圖片型別)以及將圖片設定為JButton的影象
1. 修改本地文件中的圖片(圖片寬高和圖片型別) 為了使下載的圖片素材都具有統一的width和height,需要對下載來的圖片重新處理並另存 主要思想是:構造一個BufferedImage物件,用ImageIO.read()讀入,再用ImageIO.write()重畫 程式碼如下: 1 pac
H264解析sps獲取解析度等資訊
#include <stdio.h> #include <stdint.h> #include <string.h> #include <math.h> typedef unsigned int UINT; typedef &
DOM中獲取寬高、位置總結
原生JS 一、文件、視窗的寬高和位置 // 獲取螢幕的寬高 window.screen.height | window.screen.width // 螢幕可用工作區寬高 window.screen.availHeight | window.screen.availWidth //
CCD靶面尺寸對應的寬高和對角線長度
CCD靶面規格尺寸:單位mm 規格 寬 高 對角線 1/6" 2.4 1.8 3 1/4" 3.2 2.4 4 3.6 2.7 4.5 1/3.6" 4 3 5 1/3.2" 4.536
View在屬性為wrap_content/match_parent時獲取寬高不準確的解決辦法
View 或ViewGroup在建立時設定寬度高度為match_parent或者wrap_content時,通過getWidth()、getHeight()或者getMeasuredWidth()、getMeasuredHeight()不能獲取到真實的寬高.