ffmpeg 获取和设置视频旋转角度

转自 : http://download.csdn.net/detail/hcstar/5244510




[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.        AVDictionaryEntry *tag = NULL;  
  2. tag = av_dict_get(m_pVideoStream->metadata, "rotate", tag, 0);  
  3. if (tag == NULL)  
  4. {  
  5.     m_Rotate = MT_VIDEO_ROTATE_0;  
  6. }  
  7. else  
  8. {  
  9.     int angle = atoi(tag->value);  
  10.     angle %= 360;  
  11.     if (angle == 90)  
  12.     {  
  13.         m_Rotate = MT_VIDEO_ROTATE_90;  
  14.     }  
  15.     else if (angle == 180)  
  16.     {  
  17.         m_Rotate = MT_VIDEO_ROTATE_180;  
  18.     }  
  19.     else if (angle == 270)  
  20.     {  
  21.         m_Rotate = MT_VIDEO_ROTATE_270;  
  22.     }  
  23.     else  
  24.     {  
  25.         m_Rotate = MT_VIDEO_ROTATE_0;  
  26.     }  
  27. }  


设置旋转角度

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ret = av_dict_set(&m_pDstVideoStream->metadata,"rotate","90",0);  


open之前设置

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //  
  2. class CStudent  
  3. {  
  4. public:  
  5.     CStudent(const char* pInputName,int id)  
  6.     {  
  7.         int nLen = strlen(pInputName);  
  8.         m_pName = new char[nLen + 1];  
  9.         strcpy(m_pName,pInputName);  
  10.         m_ID = id;  
  11.     }  
  12.     ~CStudent()  
  13.     {  
  14.         delete [] m_pName;  
  15.     }  
  16.     void SetID(int id)  
  17.     {  
  18.         m_ID = id;  
  19.     }  
  20.     int GetID()  
  21.     {  
  22.         return m_ID;  
  23.     }  
  24. private:  
  25.     char* m_pName;  
  26.     int m_ID;  
  27. };  
  28.   
  29. int main()  
  30. {  
  31.     CStudent A("Joy",10001);  
  32.     CStudent B("Lily",10002);  
  33.   
  34.     //Swap ID  
  35.     CStudent nTempC = A;  
  36.     A.SetID(B.GetID());  
  37.     B.SetID(nTempC.GetID());  
  38.   
  39.     return 0;  
  40. }  

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.        AVDictionaryEntry *tag = NULL;  
  2. tag = av_dict_get(m_pVideoStream->metadata, "rotate", tag, 0);  
  3. if (tag == NULL)  
  4. {  
  5.     m_Rotate = MT_VIDEO_ROTATE_0;  
  6. }  
  7. else  
  8. {  
  9.     int angle = atoi(tag->value);  
  10.     angle %= 360;  
  11.     if (angle == 90)  
  12.     {  
  13.         m_Rotate = MT_VIDEO_ROTATE_90;  
  14.     }  
  15.     else if (angle == 180)  
  16.     {  
  17.         m_Rotate = MT_VIDEO_ROTATE_180;  
  18.     }  
  19.     else if (angle == 270)  
  20.     {  
  21.         m_Rotate = MT_VIDEO_ROTATE_270;  
  22.     }  
  23.     else  
  24.     {  
  25.         m_Rotate = MT_VIDEO_ROTATE_0;  
  26.     }  
  27. }  


设置旋转角度

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ret = av_dict_set(&m_pDstVideoStream->metadata,"rotate","90",0);  


open之前设置

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //  
  2. class CStudent  
  3. {  
  4. public:  
  5.     CStudent(const char* pInputName,int id)  
  6.     {  
  7.         int nLen = strlen(pInputName);  
  8.         m_pName = new char[nLen + 1];  
  9.         strcpy(m_pName,pInputName);  
  10.         m_ID = id;  
  11.     }  
  12.     ~CStudent()  
  13.     {  
  14.         delete [] m_pName;  
  15.     }  
  16.     void SetID(int id)  
  17.     {  
  18.         m_ID = id;  
  19.     }  
  20.     int GetID()  
  21.     {  
  22.         return m_ID;  
  23.     }  
  24. private:  
  25.     char* m_pName;  
  26.     int m_ID;  
  27. };  
  28.   
  29. int main()  
  30. {  
  31.     CStudent A("Joy",10001);  
  32.     CStudent B("Lily",10002);  
  33.   
  34.     //Swap ID  
  35.     CStudent nTempC = A;  
  36.     A.SetID(B.GetID());  
  37.     B.SetID(nTempC.GetID());  
  38.   
  39.     return 0;  
  40. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值