开发者

MPMoviePlayerController stretches / distorts live streaming video (m3u8)

开发者 https://www.devze.com 2023-02-27 06:18 出处:网络
I am using MPMoviePlayerController to play live streaming m3u8 video for iOS 3.1.2.It opens in full scree开发者_如何学Pythonn landscape, which is fine.However, usually after playing for 10-20 seconds,

I am using MPMoviePlayerController to play live streaming m3u8 video for iOS 3.1.2. It opens in full scree开发者_如何学Pythonn landscape, which is fine. However, usually after playing for 10-20 seconds, the screen resizes on its own. The screen maintains its width, but shrinks the height, resulting in a narrow, stretched image. I don't have this problem when playing pre-recorded mp4 videos, though.

Any idea what's going on and how to fix it?

Here's my code:

MyViewController.h:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface WatchNowViewController : UIViewController {
    MPMoviePlayerController *mMPPlayer;
}
@property (nonatomic, retain)           MPMoviePlayerController *mMPPlayer;

@end

MyViewController.m:

mMPPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/myVideo.m3u8"]];
mMPPlayer.scalingMode=MPMovieScalingModeFill;
mMPPlayer.backgroundColor=[UIColor blackColor];
[mMPPlayer play];


MPMovieScalingModeFill does not preserve aspect ratio. You should use either MPMovieScalingModeAspectFit or MPMovieScalingModeAspectFill if you want the aspect ratio preserved.

Check out the MPMovieScalingMode documentation for information on all the modes.


There is an aspect ratio field in the header of an mpeg-ts stream. If this is present, MPMoviePlayerController will stretch the video, regardless of the reported width and height. An incorrect value will yield distorted video. I'm not sure why this would only happen 20s into the stream, but MPMoviePlayerController is a God-awful class (especially before iOS 4.0) so who can tell... If you are creating the mpeg-ts stream with FFmpeg, you can use -aspect %f to set the aspect ratio.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号