4 Stimmen

avfoundation: appendPixelBuffer withPresentationTime, Adaptor nicht bereit

Ich verwende den folgenden Code, um ein Video aus einer Folge von Bildern zu erstellen, die in einem Array (takenImages) gespeichert sind. Dauer ist die Bilddauer in Sekunden.

Alles wird dann in der Bibliothek gespeichert.

Mein Problem ist, dass wenn ich mit eingeschaltetem Debugger laufe, das Video perfekt gespeichert wird, aber wenn ich ohne Debugger laufe, wird das Video nicht vollständig gespeichert (nur die ersten Bilder wurden gespeichert).

int timescale = duration * [takenImages count];

    for (int i = 0; i < [takenImages count]; i++) {
        CVPixelBufferRef buffer = NULL;

        buffer = [self pixelBufferFromCGImage:[[takenImages objectAtIndex:i] CGImage]];

        BOOL append_ok = NO;
        int j = 0;
        while (!append_ok && j < 30) {
            if (adaptor.assetWriterInput.readyForMoreMediaData) {
                printf("appending %d attemp %d\n", i, j);
                append_ok = [adaptor appendPixelBuffer:buffer withPresentationTime:CMTimeMake(i*duration,timescale)];
            } else {
                printf("adaptor not ready %d, %d\n", i, j);
                [NSThread sleepForTimeInterval:0.1];
            }
            j++;
        }

        if (!append_ok) {
            printf("error appending image %d times %d\n", i, j);
        }

    }

Dies ist ein Beispiel dafür, was ich in der Konsole nach der Ausführung habe (Debugger aus):

appending 0 attemp 0
appending 1 attemp 0
adaptor not ready 2, 0
adaptor not ready 2, 1
adaptor not ready 2, 2
adaptor not ready 2, 3
adaptor not ready 2, 4
adaptor not ready 2, 5
adaptor not ready 2, 6
adaptor not ready 2, 7
adaptor not ready 2, 8
adaptor not ready 2, 9
adaptor not ready 2, 10
adaptor not ready 2, 11
adaptor not ready 2, 12
adaptor not ready 2, 13
adaptor not ready 2, 14
adaptor not ready 2, 15
adaptor not ready 2, 16
adaptor not ready 2, 17
adaptor not ready 2, 18
adaptor not ready 2, 19
adaptor not ready 2, 20
adaptor not ready 2, 21
adaptor not ready 2, 22
adaptor not ready 2, 23
adaptor not ready 2, 24
adaptor not ready 2, 25
adaptor not ready 2, 26
adaptor not ready 2, 27
adaptor not ready 2, 28
adaptor not ready 2, 29
error appending image 2 times 30
adaptor not ready 3, 0
adaptor not ready 3, 1
adaptor not ready 3, 2
adaptor not ready 3, 3
adaptor not ready 3, 4
adaptor not ready 3, 5
adaptor not ready 3, 6
adaptor not ready 3, 7
adaptor not ready 3, 8
adaptor not ready 3, 9
adaptor not ready 3, 10
adaptor not ready 3, 11
adaptor not ready 3, 12
adaptor not ready 3, 13
adaptor not ready 3, 14
adaptor not ready 3, 15
adaptor not ready 3, 16
adaptor not ready 3, 17
adaptor not ready 3, 18
adaptor not ready 3, 19
adaptor not ready 3, 20
adaptor not ready 3, 21
adaptor not ready 3, 22
adaptor not ready 3, 23
adaptor not ready 3, 24
adaptor not ready 3, 25
adaptor not ready 3, 26
adaptor not ready 3, 27
adaptor not ready 3, 28
adaptor not ready 3, 29
error appending image 3 times 30
adaptor not ready 4, 0
adaptor not ready 4, 1
adaptor not ready 4, 2
adaptor not ready 4, 3
adaptor not ready 4, 4
adaptor not ready 4, 5
adaptor not ready 4, 6
adaptor not ready 4, 7
adaptor not ready 4, 8
adaptor not ready 4, 9
adaptor not ready 4, 10
adaptor not ready 4, 11
adaptor not ready 4, 12
adaptor not ready 4, 13
adaptor not ready 4, 14
adaptor not ready 4, 15
adaptor not ready 4, 16
adaptor not ready 4, 17
adaptor not ready 4, 18
adaptor not ready 4, 19
adaptor not ready 4, 20
adaptor not ready 4, 21
adaptor not ready 4, 22
adaptor not ready 4, 23
adaptor not ready 4, 24
adaptor not ready 4, 25
adaptor not ready 4, 26
adaptor not ready 4, 27
adaptor not ready 4, 28
adaptor not ready 4, 29
error appending image 4 times 30

Haben Sie einen Vorschlag?

Vielen Dank im Voraus.

tschüss
Tommaso

5voto

Jeff Walstrom Punkte 71

Versuchen Sie dies bei der Einstellung der Puffer.

[adaptor appendPixelBuffer:buffer withPresentationTime:presentTime];
if(buffer)
    CVBufferRelease(buffer);
[NSThread sleepForTimeInterval:0.05];

0 Stimmen

Danke Jeff, jetzt funktioniert es! Alle Bilder wurden beim ersten Versuch angehängt!

0 Stimmen

Für mich funktioniert das perfekt :)

2voto

Jeff Walstrom Punkte 71

WriterInput.expectsMediaDataInRealTime = YES;

0 Stimmen

Danke, ich habe diesen Befehl hinzugefügt (ich habe auch die Dokumentation überprüft und er wird in meinem Fall eindeutig benötigt), aber das Ergebnis ist, dass ein weiterer Frame angehängt wird, und der Adapter wird nie fertig

2voto

Peter DeWeese Punkte 17855

Es ist angemessener, Folgendes zu verwenden requestMediaDataWhenReadyOnQueue:usingBlock: auf Ihr writerInput-Objekt. Wenn es wieder zur Eingabe bereit ist, wird der Block erneut aufgerufen.

1 Stimmen

Ich musste trotzdem einen Schlafmodus verwenden, damit es richtig funktioniert. Schrecklich.

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X