2011-03-01 13 views
8

मेरे पास एक साधारण वीडियो संपादन दृश्य है जो AVPlayer का उपयोग करता है। मैं एक या कई AVURLASSet का उपयोग कर एक AVMutableComposition बनाते हैं। सभी ठीक काम करते हैं लेकिन वीडियो हमेशा 90 डिग्री घुमाए जाते हैं। यानी अगर स्रोत वीडियो पोर्ट्रेट मोड में लिया गया था। एवीप्लेयर इसे लैंडस्केप मोड में दिखाता है और इसके विपरीत। मैं प्रलेखन के माध्यम से चला गया हूं और इसे "गोलाकार" कर दिया है और इसे हल नहीं किया जा सकता है। मैबे मैं गलत जगहों में देख रहा हूँ।आईफोन एसडीके। AVRLlAsset/AVMutableComposition का उपयोग करके AVplayer में वीडियो घुमाने के लिए संभव है?

क्या कोई मदद कर सकता है?

अग्रिम में धन्यवाद;

जीन पियरे

+0

AVFoundation पर एक WWDC10 सत्र मेरा मानना ​​है कि एक सेटिंग कहीं नहीं है लेकिन मैं इसे फिर से देखने की जरूरत है देखने के बाद। मुझे जवाब पोस्ट होगा जब मुझे यकीन है कि –

+1

क्या आपने कभी इस समस्या को हल किया है? मुझे भी वही समस्या हो रही है। –

+0

आपने इस समस्या को हल किया है? मुझे एक ही समस्या है, मुझे नहीं पता कि मुझे क्या करना है –

उत्तर

1

जांच करने के लिए कोड होने के बिना, यह पता करने के लिए क्या चल रहा है मुश्किल ... लेकिन सबसे शायद, तो अपनी समस्या के कारण होता है, क्योंकि आप अपने preferredTransform संपत्ति के मूल्य खो रहे हैं है।

सभी AVAssetTrack ऑब्जेक्ट्स में preferredTransform प्रॉपर्टी है जिसका उपयोग यह निर्दिष्ट करने के लिए किया जाता है कि वीडियो को घुमाया जाना चाहिए या नहीं। यदि आप नई AVMutableAssetTrack ऑब्जेक्ट्स बना रहे हैं, तो आपको उस संपत्ति का मान सेट करना पड़ सकता है ताकि वीडियो इच्छित अभिविन्यास में रहता है।

3

मेरी समझ में आपके पास पोर्ट्रेट वीडियो जैसे कुछ अभिविन्यास मुद्दे हैं, जैसे लैंडस्केप वीडियो लैंडस्केप मोड में है, और कभी-कभी वीडियो उल्टा हो जाते हैं। यह डिफ़ॉल्ट AVAsset अभिविन्यास के कारण है। डिफ़ॉल्ट आईफ़ोन कैमरा एप्लिकेशन का उपयोग करके रिकॉर्ड की गई सभी फिल्मों और छवि फ़ाइलों में वीडियो फ्रेम को लैंडस्केप पर सेट किया गया है, और इसलिए मीडिया लैंडस्केप मोड में सहेजा गया है। AVAsset में एक पसंदीदा ट्रान्सफॉर्म संपत्ति है जिसमें मीडिया अभिविन्यास जानकारी होती है, और जब भी आप इसे फ़ोटो ऐप या क्विकटाइम का उपयोग करके देखते हैं तो इसे मीडिया फ़ाइल पर लागू किया जाता है। आप अपने AVAsset ऑब्जेक्ट्स में आवश्यक परिवर्तनों को लागू करके इसे आसानी से सही कर सकते हैं। लेकिन चूंकि आपकी दो वीडियो फ़ाइलों में अलग-अलग उन्मुखताएं हो सकती हैं, इसलिए आपको मूल रूप से किए गए एक (अनुमान) के बजाय दो अलग AVMutableCompositionTrack उदाहरणों का उपयोग करना होगा। दो AVMutableCompositionTrack वीडियो ट्रैक बनाएं क्योंकि अब आपके पास दो अलग AVMutableCompositionTrack उदाहरण हैं, इसलिए आपको अभिविन्यास को ठीक करने के लिए प्रत्येक ट्रैक में AVMutableVideoCompositionLayerInstruction लागू करने की आवश्यकता है। तो निम्नलिखित कोड

// Create AVMutableVideoCompositionInstruction 
AVMutableVideoCompositionInstruction *mainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; 
mainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeAdd(firstAsset.duration, secondAsset.duration)); 
// Create an AVMutableVideoCompositionLayerInstruction for the first track 
AVMutableVideoCompositionLayerInstruction *firstlayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:firstTrack]; 
AVAssetTrack *firstAssetTrack = [[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; 
UIImageOrientation firstAssetOrientation_ = UIImageOrientationUp; 
BOOL isFirstAssetPortrait_ = NO; 
CGAffineTransform firstTransform = firstAssetTrack.preferredTransform; 
if (firstTransform.a == 0 && firstTransform.b == 1.0 && firstTransform.c == -1.0 && firstTransform.d == 0) { 
    firstAssetOrientation_ = UIImageOrientationRight; 
    isFirstAssetPortrait_ = YES; 
} 
if (firstTransform.a == 0 && firstTransform.b == -1.0 && firstTransform.c == 1.0 && firstTransform.d == 0) { 
    firstAssetOrientation_ = UIImageOrientationLeft; 
    isFirstAssetPortrait_ = YES; 
} 
if (firstTransform.a == 1.0 && firstTransform.b == 0 && firstTransform.c == 0 && firstTransform.d == 1.0) { 
    firstAssetOrientation_ = UIImageOrientationUp; 
} 
if (firstTransform.a == -1.0 && firstTransform.b == 0 && firstTransform.c == 0 && firstTransform.d == -1.0) { 
    firstAssetOrientation_ = UIImageOrientationDown; 
} 
[firstlayerInstruction setTransform:firstAsset.preferredTransform atTime:kCMTimeZero]; 
[firstlayerInstruction setOpacity:0.0 atTime:firstAsset.duration]; 
// Create an AVMutableVideoCompositionLayerInstruction for the second track 
AVMutableVideoCompositionLayerInstruction *secondlayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:secondTrack]; 
AVAssetTrack *secondAssetTrack = [[secondAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; 
UIImageOrientation secondAssetOrientation_ = UIImageOrientationUp; 
BOOL isSecondAssetPortrait_ = NO; 
CGAffineTransform secondTransform = secondAssetTrack.preferredTransform; 
if (secondTransform.a == 0 && secondTransform.b == 1.0 && secondTransform.c == -1.0 && secondTransform.d == 0) { 
    secondAssetOrientation_= UIImageOrientationRight; 
    isSecondAssetPortrait_ = YES; 
} 
if (secondTransform.a == 0 && secondTransform.b == -1.0 && secondTransform.c == 1.0 && secondTransform.d == 0) { 
    secondAssetOrientation_ = UIImageOrientationLeft; 
    isSecondAssetPortrait_ = YES; 
} 
if (secondTransform.a == 1.0 && secondTransform.b == 0 && secondTransform.c == 0 && secondTransform.d == 1.0) { 
    secondAssetOrientation_ = UIImageOrientationUp; 
} 
if (secondTransform.a == -1.0 && secondTransform.b == 0 && secondTransform.c == 0 && secondTransform.d == -1.0) { 
    secondAssetOrientation_ = UIImageOrientationDown; 
} 
[secondlayerInstruction setTransform:secondAsset.preferredTransform atTime:firstAsset.duration]; 
} 

अंत में निर्देश जोड़ें, यह केवल दूसरे ट्रैक पर लागू अभिविन्यास फिक्स है।

mainInstruction.layerInstructions = [NSArray arrayWithObjects:firstlayerInstruction, secondlayerInstruction,nil]; 
AVMutableVideoComposition *mainCompositionInst = [AVMutableVideoComposition videoComposition]; 
mainCompositionInst.instructions = [NSArray arrayWithObject:mainInstruction]; 
mainCompositionInst.frameDuration = CMTimeMake(1, 30); 

CGSize naturalSizeFirst, naturalSizeSecond; 
if(isFirstAssetPortrait_){ 
    naturalSizeFirst = CGSizeMake(FirstAssetTrack.naturalSize.height, FirstAssetTrack.naturalSize.width); 
} else { 
    naturalSizeFirst = FirstAssetTrack.naturalSize; 
} 
if(isSecondAssetPortrait_){ 
    naturalSizeSecond = CGSizeMake(SecondAssetTrack.naturalSize.height, SecondAssetTrack.naturalSize.width); 
} else { 
    naturalSizeSecond = SecondAssetTrack.naturalSize; 
} 

float renderWidth, renderHeight; 
if(naturalSizeFirst.width > naturalSizeSecond.width) { 
    renderWidth = naturalSizeFirst.width; 
} else { 
    renderWidth = naturalSizeSecond.width; 
} 
if(naturalSizeFirst.height > naturalSizeSecond.height) { 
    renderHeight = naturalSizeFirst.height; 
} else { 
    renderHeight = naturalSizeSecond.height; 
} 
MainCompositionInst.renderSize = CGSizeMake(renderWidth, renderHeight); 

आशा है कि यह मदद करता है

संबंधित मुद्दे