Chu*_*ran 5 c++ iphone ffmpeg objective-c ios
我有一个使用C++类和FFmpeg的项目,我需要使用fopen并将文件写入应用程序沙箱,因此我需要用C++编写的代码相当于:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs_dir = [paths objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
这将是我的应用程序沙箱,我几乎可以操作我的文件问题是我如何在C++中编写此代码,以便我可以在文件上使用fopen?
这是需要实现的方法:
int testGrabAndWrite(const char* streamURL, bool decode, const char* filename)
{
FILE *outfile;
int ret;
int counter = 0;
uint8_t *data; // Pointer to the received audio mem
int size; // Size of the received audio buffer
outfile = fopen(filename, "w");
if (outfile == NULL)
exit(1);
// Open the RTP stream
if ((ret = openStream(streamURL, decode)) < 0)
return ret;
// Print out info about the stream found
int tmpSampleRate, tmpBitRate, tmpChannels;
ret = getStreamInfo(tmpSampleRate, tmpBitRate, tmpChannels);
printf("\nSample rate:%d Bit rateL%d Channels:%d\n",tmpSampleRate,tmpBitRate, tmpChannels);
// Grab some sample data and write it to file.
while (counter < 500)
{
ret = getStreamData(data, size);
fwrite(data, 1, size, outfile); // Write RTP packets, i.e. mp3, to file.
printf("Wrote packet %d with size %d which returned %d. ", ++counter, size, ret);
}
fclose(outfile);
closeStream();
return ret;
}
Run Code Online (Sandbox Code Playgroud)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs_dir = [paths objectAtIndex:0];
NSString* aFile = [docs_dir stringByAppendingPathComponent: @"somedocthatdefinitelyexists.doc"];
FILE* fp = fopen([aFile fileSystemRepresentation], "r");
Run Code Online (Sandbox Code Playgroud)
该消息-fileSystemRepresentation重新编译为文件系统适当编码的char*,例如可能转换为UTF-8
| 归档时间: |
|
| 查看次数: |
5212 次 |
| 最近记录: |