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;
相关推荐
晓数1 小时前
“平价”微智码初尝试
人工智能·jetbrains
新加坡内哥谈技术1 小时前
MCP:人工智能时代的HTTP?探索AI通信新标准
人工智能·自然语言处理·chatgpt
0x2113 小时前
[论文阅读]REPLUG: Retrieval-Augmented Black-Box Language Models
论文阅读·人工智能·语言模型
JOYCE_Leo164 小时前
一文详解卷积神经网络中的卷积层和池化层原理 !!
人工智能·深度学习·cnn·卷积神经网络
~央千澈~5 小时前
对鸿蒙 Next 系统“成熟论”的深度剖析-优雅草卓伊凡
人工智能
Donvink5 小时前
【视频生成模型】通义万相Wan2.1模型本地部署和LoRA微调
人工智能·深度学习·aigc·音视频
訾博ZiBo5 小时前
AI日报 - 2025年04月29日
人工智能
爱喝奶茶的企鹅5 小时前
Ethan独立开发产品日报 | 2025-04-27
人工智能·程序员·开源
极小狐5 小时前
如何对极狐GitLab 议题进行过滤和排序?
人工智能·git·机器学习·gitlab