首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓MediaPlayer不播放mp4视频

安卓MediaPlayer不播放mp4视频
EN

Stack Overflow用户
提问于 2017-04-30 22:06:39
回答 1查看 967关注 0票数 2

我正在尝试播放一个在mp4上呈现的TextureView视频,它在API级别的>= 21上工作(在Lollipop之后),但是在以前的版本中它没有播放。我在logcat中得到了以下错误:error (1, -2147483648)。我认为这是一个未知的错误(据我所知)。

文件是从“资产”文件夹加载的。

代码语言:javascript
复制
private MediaPlayer mMediaPlayer;

@Override
protected void onCreate(Bundle savedState) {
   super.onCreate(savedState);

   TextureView textureView = (TextureView) findViewById(R.id.textureView);
   textureView.setSurfaceTextureListener(this);       
}

@Override
public void onSurfaceTextureAvailable(SurfaceTexture txtSurface, final int width, final int height) {
   Surface surface = new Surface(txtSurface);

   mMediaPlayer = new MediaPlayer();
   AssetFileDescriptor afd = getAssets().openFd("video/test.mp4");
   mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
   mMediaPlayer.setSurface(surface);
   mMediaPlayer.setLooping(false);
   mMediaPlayer.setVolume(0f, 0f);

   mMediaPlayer.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);

   mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
               mMediaPlayer.start();
            }
   });
   mMediaPlayer.prepareAsync();
}

表面尺寸为: 768x1280,视频尺寸为:350×500 px。我还试图调整不同大小的视频(创建新视频)的大小: 768x1280、1080x1920和4k。是什么导致了这个错误?高宽比还是不同的设备/视频分辨率?

当文件准备就绪时,我将在logcat中获得以下消息:

代码语言:javascript
复制
04-30 17:56:01.752 432-432/? V/FFmpegExtractor: SniffFFMPEG
04-30 17:56:01.752 432-432/? I/FFmpegExtractor: android-source:0xb83b8e00
04-30 17:56:01.752 432-432/? D/FFMPEG: android source begin open
04-30 17:56:01.752 432-432/? D/FFMPEG: android open, url: android-source:0xb83b8e00
04-30 17:56:01.752 432-432/? D/FFMPEG: ffmpeg open android data source success, source ptr: 0xb83b8e00
04-30 17:56:01.752 432-432/? D/FFMPEG: android source open success
04-30 17:56:01.800 432-432/? I/FFMPEG: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'android-source:0xb83b8e00':
04-30 17:56:01.800 432-432/? I/FFMPEG:   Metadata:
04-30 17:56:01.800 432-432/? I/FFMPEG:     major_brand     : mp42
04-30 17:56:01.800 432-432/? I/FFMPEG:     minor_version   : 0
04-30 17:56:01.800 432-432/? I/FFMPEG:     compatible_brands: mp42mp41
04-30 17:56:01.800 432-432/? I/FFMPEG:     creation_time   : 2017-04-30 21:22:53
04-30 17:56:01.800 432-432/? I/FFMPEG:   Duration: 00:00:29.50, start: 0.000000, bitrate: 2522 kb/s
04-30 17:56:01.800 432-432/? I/FFMPEG:     Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 350x500, 2517 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
04-30 17:56:01.800 432-432/? I/FFMPEG:     Metadata:
04-30 17:56:01.800 432-432/? I/FFMPEG:       creation_time   : 2017-04-30 21:22:53
04-30 17:56:01.800 432-432/? I/FFMPEG:       handler_name    : Alias Data Handler
04-30 17:56:01.800 432-432/? I/FFmpegExtractor: FFmpegExtrator, url: android-source:0xb83b8e00, format_name: mov,mp4,m4a,3gp,3g2,mj2, format_long_name: QuickTime / MOV
04-30 17:56:01.800 432-432/? I/FFmpegExtractor: list the formats suppoted by ffmpeg: 
04-30 17:56:01.800 432-432/? I/FFmpegExtractor: ========================================
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[00]: mpeg
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[01]: mpegts
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[02]: mov,mp4,m4a,3gp,3g2,mj2
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[03]: matroska,webm
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[04]: asf
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[05]: rm
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[06]: flv
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[07]: swf
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[08]: avi
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[09]: ape
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[10]: dts
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[11]: flac
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[12]: ac3
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[13]: wav
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[14]: ogg
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[15]: vc1
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: format_names[16]: hevc
04-30 17:56:01.800 432-432/? I/FFmpegExtractor: ========================================
04-30 17:56:01.800 432-432/? V/FFmpegExtractor: major_brand tag is:mp42
04-30 17:56:01.800 432-432/? D/FFmpegExtractor: suppoted codec(h264) by official Stagefright
04-30 17:56:01.800 432-432/? D/FFMPEG: android source close
04-30 17:56:01.800 432-432/? I/FFmpegExtractor: sniff through BetterSniffFFMPEG success
04-30 17:56:01.800 432-432/? D/FFmpegExtractor: ffmpeg detected media content as 'video/mp4' with confidence 0.08
04-30 17:56:01.804 432-432/? I/SampleTable: There are reordered frames present.
04-30 17:56:01.816 432-15591/? I/OMXCodec: [OMX.google.h264.decoder] AVC profile = 77 (Main), level = 31
04-30 17:56:01.816 432-15591/? I/OMXCodec: [OMX.google.h264.decoder] video dimensions are 320 x 240
04-30 17:56:01.816 432-15591/? I/OMXCodec: [OMX.google.h264.decoder] Crop rect is 320 x 240 @ (0, 0)

该视频使用Adobe After Effects创建,并保存为.AVI文件,然后导入Adobe Premier Pro并导出到.mp4(H.264)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-30 22:24:54

看起来,导出的文件没有有效的配置文件。上市媒体格式显示,唯一支持的配置文件是H.264的基线配置文件。

要添加基线配置文件,需要通过下载ffmpeg并使用以下命令行创建一个新的mp4文件来添加它:

代码语言:javascript
复制
ffmpeg.exe -i your_file.mp4 -c:v libx264 -profile:v baseline -level 1 new_file_name.mp4
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43711847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档