FFMPEG 工具方法

av_strerror
复制代码
int av_strerror	(	int 	errnum,
char * 	errbuf,
size_t 	errbuf_size
)
ffmpeg获取与设置mp4文件旋转方向方法

设置与获取都是对AVStream的dict操作.
设置

复制代码
for (i = 0; i < ifmt_ctx_v->nb_streams; i++) {  
        //Create output AVStream according to input AVStream  
        if(ifmt_ctx_v->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){  
            AVStream *in_stream = ifmt_ctx_v->streams[i];  
            AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);  
            videoindex_v=i;  
            if (!out_stream) {  
                printf( "Failed allocating output stream\n");  
                ret = AVERROR_UNKNOWN;  
                goto end;  
            }  
            videoindex_out=out_stream->index;  
            //Copy the settings of AVCodecContext  
            ret = av_dict_set(&out_stream->metadata,"rotate","90",0); //设置旋转角度  
            if(ret>=0)  
            {  
                printf("=========yes=====set rotate success!===\n");  
            }  

            if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {  
                printf( "Failed to copy context from input to output stream codec context\n");  
                goto end;  
            }  
            out_stream->codec->codec_tag = 0;  
            if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)  
                out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;  
            break;  
        }  
    }  

读取

复制代码
for (i = 0; i < ifmt_ctx_v->nb_streams; i++) {  
        //Create output AVStream according to input AVStream  
        if(ifmt_ctx_v->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){  
            AVStream *in_stream = ifmt_ctx_v->streams[i];  
            AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);  
            videoindex_v=i;  
            if (!out_stream) {  
                printf( "Failed allocating output stream\n");  
                ret = AVERROR_UNKNOWN;  
                goto end;  
            }  
            videoindex_out=out_stream->index;  
            //Copy the settings of AVCodecContext  
            ret = av_dict_set(&out_stream->metadata,"rotate","90",0); //设置旋转角度  
            if(ret>=0)  
            {  
                printf("=========yes=====set rotate success!===\n");  
            }  

            if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {  
                printf( "Failed to copy context from input to output stream codec context\n");  
                goto end;  
            }  
            out_stream->codec->codec_tag = 0;  
            if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)  
                out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;  
            break;  
        }  
    }  


double g_rotate_theta = get_rotation(decoder->is_video);//is_video是video的AVStream
        int rotate = 0;
        if (fabs(g_rotate_theta - 90) < 1.0)
        {
            rotate = 90;
        }
        else if(fabs(g_rotate_theta - 180) < 1.0||fabs(g_rotate_theta + 180) < 1.0)
        {
            rotate = 180;
        }
        else if(fabs(g_rotate_theta - 270) < 1.0||fabs(g_rotate_theta + 90) < 1.0)
        {
            rotate = 270;
        }
        LOGI("get rotate is : %d" , rotate);
        metadata->rotate = rotate;
相关推荐
qq_430855881 分钟前
线代第三章向量第三节:向量组的秩
人工智能·机器学习
Saniffer_SH5 分钟前
【每日一题】笔记本电脑上从U盘拷贝文件到M.2 SSD过程中为什么链路还会偶尔进入L1.2低功耗?
服务器·网络·人工智能·驱动开发·单片机·嵌入式硬件·电脑
lusasky5 分钟前
AgentScope的主要开源竞品框架对比
人工智能·开源
高光视点5 分钟前
共话 AI Agent 规模化落地!快鹭科技受邀参与福田 “益企 LINK” 沙龙圆桌讨论
人工智能·科技
mys55185 分钟前
杨建允:AI搜索优化对全链路营销的影响
人工智能·aigc·geo·ai搜索优化·ai引擎优化
汤姆yu6 分钟前
基于深度学习的电动车头盔佩戴检测系统
人工智能·深度学习
木头左8 分钟前
强化学习结合LSTM的量化交易策略奖励函数与入参关联
人工智能·rnn·lstm
数字化转型20258 分钟前
金风科技 vs 远景能源:风机产品核心差异分析【基本面分析】
人工智能
聚铭网络9 分钟前
聚铭网络入选《ISC.AI 2025创新能力全景图谱》6大细分领域
网络·人工智能
Deepoch11 分钟前
硬件赋能智能:Deepoc开发板如何成为无人机自主飞行的核心引擎
人工智能·无人机·具身模型·deepoc