FFmpeg移植到Android(版本10)后,播放手机上的MP4,avformat_open_input(&formatContext, videoPath, NULL, NULL)返回-13的问题

背景:

移植FFmpeg到Android上,自定义一个播放器。打开手机MP4 文件时,

avformat_open_input(&formatContext, videoPath, NULL, NULL)返回-13

MP4 文件在路径:/sdcard/DCIM/Camera/killer.mp4

添加了读写权限。

处理:

1、尝试用Android自带的mediaplayer播放,依旧无法播放

2、在手机手动创建一个文件夹:/sdcard/aatest,放在这个目录下,用mediaplayer可以播放;videoPath=/sdcard/aatest/killer.mp4,用FFmpeg解码后可以播放

3、在路径下:/storage/emulated/0/DCIM/Camera/killer.mp4,也就是手机的相册目录下。想要播放的话,除了读写权限,针对Android10,还需要在manifest文件的application中添加

android:requestLegacyExternalStorage="true";这样就可以播放了。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用FFmpegavformat_open_input函数打开一个媒体文件之后,为了正常关闭,需要按照以下步骤: 1. 调用avformat_find_stream_info函数获取媒体文件的流信息。 2. 调用av_read_frame函数读取媒体文件中的数据帧。 3. 当需要停止读取数据帧时,调用avformat_close_input函数关闭输入流。 4. 释放所有相关的资源,包括AVFormatContextAVIOContextAVCodecContext等。 示例代码: ``` AVFormatContext *pFormatCtx = NULL; int videoStream = -1; AVCodecContext *pCodecCtx = NULL; AVCodec *pCodec = NULL; AVPacket packet; av_register_all(); if(avformat_open_input(&pFormatCtx, filename, NULL, NULL)!=0){ printf("Could not open file\n"); return -1; } if(avformat_find_stream_info(pFormatCtx, NULL)<0){ printf("Could not find stream information\n"); return -1; } videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); if(videoStream == -1){ printf("Could not find video stream\n"); return -1; } pCodecCtx = pFormatCtx->streams[videoStream]->codec; pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if(pCodec == NULL){ printf("Codec not found\n"); return -1; } if(avcodec_open2(pCodecCtx, pCodec, NULL)<0){ printf("Could not open codec\n"); return -1; } av_init_packet(&packet); while(av_read_frame(pFormatCtx, &packet)>=0){ // 处理读取到的数据帧 av_packet_unref(&packet); } avformat_close_input(&pFormatCtx); avcodec_free_context(&pCodecCtx); ``` 以上代码演示了如何打开一个媒体文件,读取其中的数据帧,并在完成后正常关闭。在关闭输入流之前,需要确保所有的数据帧都已经被处理完毕,并且相关的资源已经被释放。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值