I have a project that uses the C ++ and FFmpeg classes, I need to use fopen and write the file to the application sandbox, so the code I need to write in C ++ is equivalent:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs_dir = [paths objectAtIndex:0];
This would be for my application sandbox where I can pretty much manipulate files. The question is, how can I write this code in C ++ so that I can use fopen in a file?
This is a method that needs to be implemented:
int testGrabAndWrite(const char* streamURL, bool decode, const char* filename)
{
FILE *outfile;
int ret;
int counter = 0;
uint8_t *data;
int size;
outfile = fopen(filename, "w");
if (outfile == NULL)
exit(1);
if ((ret = openStream(streamURL, decode)) < 0)
return ret;
int tmpSampleRate, tmpBitRate, tmpChannels;
ret = getStreamInfo(tmpSampleRate, tmpBitRate, tmpChannels);
printf("\nSample rate:%d Bit rateL%d Channels:%d\n",tmpSampleRate,tmpBitRate, tmpChannels);
while (counter < 500)
{
ret = getStreamData(data, size);
fwrite(data, 1, size, outfile);
printf("Wrote packet %d with size %d which returned %d. ", ++counter, size, ret);
}
fclose(outfile);
closeStream();
return ret;
}
source
share