Skip to content

Instantly share code, notes, and snippets.

@crowjdh
Created February 22, 2016 09:47
Show Gist options
  • Save crowjdh/486589c1530c6195af4b to your computer and use it in GitHub Desktop.
Save crowjdh/486589c1530c6195af4b to your computer and use it in GitHub Desktop.
Set HTTP header information to FFmpeg avformat_open_input function in iOS
- (AVDictionary*) createAVFormatContextOptions: (NSDictionary*)dict
{
AVDictionary *options = NULL;
for (NSString* keyString in dict) {
av_dict_set(&options, [keyString UTF8String], [[dict objectForKey:keyString] UTF8String], 0);
}
return options;
}
- (void) updateAVFormatContextWithOptions: (AVDictionary**)options {
if (_formatCtx)
return;
AVDictionary *tmp = NULL;
if (options) {
av_dict_copy(&tmp, *options, 0);
}
if (av_opt_set_dict(_formatCtx, &tmp) < 0) {
av_dict_free(&tmp);
}
}
- (void) someWhereElse
{
NSMutableString* cookieString = [NSMutableString stringWithString:@"Cookie: "];
for (NSHTTPCookie* cookie in [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies) {
[cookieString appendFormat:@"%@=%@;", cookie.name, cookie.value];
}
[cookieString appendString:@"\n"];
NSDictionary* dict = [NSDictionary dictionaryWithObject:cookieString forKey: @"headers"];
AVDictionary* options = [self createAVFormatContextOptions:dict];
avformat_open_input(&amp;formatCtx, [path cStringUsingEncoding: NSUTF8StringEncoding], NULL, &amp;options)
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment