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;
相关推荐
杨小扩5 小时前
第4章:实战项目一 打造你的第一个AI知识库问答机器人 (RAG)
人工智能·机器人
whaosoft-1435 小时前
51c~目标检测~合集4
人工智能
雪兽软件5 小时前
2025 年网络安全与人工智能发展趋势
人工智能·安全·web安全
元宇宙时间6 小时前
全球发展币GDEV:从中国出发,走向全球的数字发展合作蓝图
大数据·人工智能·去中心化·区块链
小黄人20256 小时前
自动驾驶安全技术的演进与NVIDIA的创新实践
人工智能·安全·自动驾驶
ZStack开发者社区7 小时前
首批 | 云轴科技ZStack加入施耐德电气技术本地化创新生态
人工智能·科技·云计算
X Y O8 小时前
神经网络初步学习3——数据与损失
人工智能·神经网络·学习
唯创知音8 小时前
玩具语音方案选型决策OTP vs Flash 的成本功耗与灵活性
人工智能·语音识别
Jamence8 小时前
多模态大语言模型arxiv论文略读(151)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记
tongxianchao8 小时前
LaCo: Large Language Model Pruning via Layer Collapse
人工智能·语言模型·剪枝