3

现在,我正在使用静态librtmp.a库来打开我的 iphone 和服务器之间的 RTMP 连接。当按下录制按钮时,相机开始接收输入,并在 captureoutput 上使用AVAssetWriter不同线程中的 's 将视频编码为 h264/AAC。然后将视频保存到特定的 URL。我正在尝试获取这些处理过的帧并使用librtmp.

-(void)writeURL:(NSURL*)segmentURL {
    NSLog(@"Utilities are writing...");
    NSData *segmentData = [NSData dataWithContentsOfURL:segmentURL];
    const char* body = [segmentData bytes];

    NSLog(@"%i", [segmentData length]);
    NSLog(@"%s", body);

    RTMPPacket packet = _rtmp->m_write;
    RTMPPacket_Alloc(&packet, [segmentData length]);
    packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
    packet.m_packetType = RTMP_PACKET_TYPE_VIDEO;
    packet.m_body = (char*)body;

    RTMPPacket_Dump(&packet);
    RTMP_SendPacket(_rtmp, &packet, TRUE);
    //RTMP_Write(_rtmp, packet.m_body, packet.m_nBodySize);
}

每次通话都会崩溃RTMPPacket_alloc,我不确定该怎么做。这是通过网络发送数据的正确方法吗?

编辑:
样本输出

2013-03-31 22:53:16.163 videoAppPrototype[2567:907] Switching encoders
2013-03-31 22:53:16.179 videoAppPrototype[2567:1703] Encoder switch finished
2013-03-31 22:53:16.220 videoAppPrototype[2567:1703] Upload public.mpeg-4
2013-03-31 22:53:16.223 videoAppPrototype[2567:1703] Utilities are writing...
2013-03-31 22:53:16.230 videoAppPrototype[2567:1703] 339171
DEBUG: RTMP PACKET: packet type: 0x09. channel: 0x00. info 1: 0 info 2: 0. Body size: 0.     body: 0x00

编辑 2:
我将代码更改为使用RTMP_Write()而不是RTMP_SendPacket().

新方法:

-(void)writeURL:(NSURL*)segmentURL {
NSLog(@"Utilities are writing...");
NSData *segmentData = [NSData dataWithContentsOfURL:segmentURL];

NSUInteger len = [segmentData length] / sizeof(unsigned char);
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [segmentData bytes], len);
free(byteData);

NSLog(@"%i", [segmentData length]); 

NSLog(@"First write attempt...");
RTMP_Write(_rtmp, (char *)byteData, len);
NSLog(@"Successful?");
}

现在在 RTMP_Write 崩溃,如堆栈跟踪所示:
堆栈跟踪 如果有人有任何想法或需要更多信息,请让我知道!

4

0 回答 0