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;
相关推荐
晨非辰23 分钟前
数据结构排序系列指南:从O(n²)到O(n),计数排序如何实现线性时间复杂度
运维·数据结构·c++·人工智能·后端·深度学习·排序算法
2301_8129148723 分钟前
简单神经网络
人工智能·深度学习·神经网络
koo3641 小时前
pytorch环境配置
人工智能·pytorch·python
模型启动机5 小时前
黄仁勋GTC开场:「AI-XR Scientist」来了!
人工智能·ai·大模型
k***1955 小时前
自动驾驶---E2E架构演进
人工智能·架构·自动驾驶
Techblog of HaoWANG6 小时前
目标检测与跟踪 (4)- 基于YOLOv8的工业仪器仪表智能读数与状态检测算法实
人工智能·视觉检测·智能制造·yolov8·工业检测·指针式仪表·仪器仪表检测
1***Q7846 小时前
深度学习技术
人工智能·深度学习
KKKlucifer6 小时前
2025 国产化数据分类分级工具实测:国产化适配、多模态识别与动态分级能力深度解析
人工智能·分类·数据挖掘
虹科网络安全7 小时前
从AI模型到云生态:构建系统化的企业AI安全管理体系【系列文章(3)】
人工智能·安全
互联网江湖7 小时前
这个Q3,百度开始AI
人工智能·百度