2011-04-19 60 views
1

我正在使用MPMoviePlayerController播放用於iOS 3.1.2的直播m3u8視頻。它全屏顯示,這很好。但是,通常在播放10-20秒後,屏幕會自行調整大小。屏幕保持其寬度,但縮小高度,導致縮小,拉伸的圖像。但是,在播放預錄製的mp4視頻時,我沒有這個問題。MPMoviePlayerController延伸/扭曲直播視頻(m3u8)

任何想法是怎麼回事以及如何解決它?

這裏是我的代碼:

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]; 

回答

2

MPMovieScalingModeFill不保持縱橫比。如果要保留寬高比,則應使用MPMovieScalingModeAspectFit或MPMovieScalingModeAspectFill。

查看MPMovieScalingMode documentation瞭解所有模式的信息。

+0

我嘗試了你列出的適合和填充模式,但它仍然不起作用。它最初起作用。但是,玩家在片刻之後仍然會調整大小。 m3u8有什麼特別的可能導致我的問題? – user359519 2011-04-19 20:07:00

+0

我嘗試使用蘋果的blip blop feed播放我的播放器:http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8。到目前爲止,沒有調整大小。這表明我的Feed的編碼可能存在問題。我會和那些爲我的Feed設置編碼的人聊聊。 – user359519 2011-04-19 20:25:42

2

mpeg-ts流頭部有一個寬高比字段。如果存在,MPMoviePlayerController將擴展視頻,無論報告的寬度和高度如何。不正確的值會導致視頻失真。我不確定爲什麼這隻會在20秒內進入流,但MPMoviePlayerController是一個上帝糟糕的類(特別是在iOS 4.0之前),所以誰可以告訴...如果您使用FFmpeg創建mpeg-ts流,您可以使用-aspect%f來設置寬高比。

+0

20秒可能是因爲第一個TS塊已被正確編碼,但接下來的一個不是。爲了好的和正確的答案+1。 – Till 2011-04-20 10:35:34