您的位置:首页 > 房产 > 家装 > FFMPEG 工具方法

FFMPEG 工具方法

2025/1/3 15:32:26 来源:https://blog.csdn.net/sjw890821sjw/article/details/141029825  浏览:    关键词: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的AVStreamint 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;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com