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;
相关推荐
LaughingZhu5 小时前
Product Hunt 每日热榜 | 2026-05-31
前端·人工智能·经验分享·搜索引擎·chatgpt·html
GIOTTO情5 小时前
智能舆情处置系统技术方案:基于NLP语义算法的全链路风险处置落地
人工智能·算法·自然语言处理
筑梦调音师5 小时前
从知识沉淀到 AI 执行:一次本地知识库工作流的 Harness 实践
人工智能
程序员cxuan5 小时前
MiniMax M3 发布,据说接近 Opus 4.7?真的假的
人工智能·后端·程序员
kcuwu.5 小时前
BERT文本分类完整实战指南
人工智能·分类·bert
ViiTor_AI6 小时前
视频翻译出海完整流程:翻译、克隆原声、对口型怎么做
人工智能
MacroZheng6 小时前
给Claude Code装上这个超酷的状态栏,瞬间高大上了!
java·人工智能·后端
私域合规研究6 小时前
聚焦新消费商业模式 专家研讨会在台州举行
人工智能
霸道流氓气质6 小时前
Spring AI Alibaba + Ollama Function Calling 项目完整指南
人工智能·windows·spring
码农小白AI6 小时前
从分段审核到一体化闭环:AI 报告审核如何用 IACheck 重构仪器校准与期间核查流程
人工智能·重构