gpt4 book ai didi

Android MediaPlayer 不播放 Lollipop 前的 mp4 视频

转载 作者:行者123 更新时间:2023-11-29 02:41:32 25 4
gpt4 key购买 nike

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

文件是从 Assets 文件夹中加载的。

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,视频尺寸为:350x500 像素。我还尝试调整不同尺寸的视频(创建新视频):768x1280、1080x1920 和 4k。是什么导致了错误?纵横比或不同的设备/视频分辨率?

在准备文件时,我在 logcat 中收到以下消息:

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)

最佳答案

导出的文件似乎没有有效的配置文件。 listed media formats显示唯一支持的配置文件是 H.264 的基线配置文件。

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

ffmpeg.exe -i your_file.mp4 -c:v libx264 -profile:v baseline -level 1 new_file_name.mp4

关于Android MediaPlayer 不播放 Lollipop 前的 mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43711847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com