第11月第14天openglyuv

lianhuaren lianhuaren     2022-09-15     235

关键词:

1.

Here is some snippets of code from my project ‘movie player for iOS‘.

1. fragment shader

varying highp vec2 v_texcoord;  
uniform sampler2D s_texture_y;  
uniform sampler2D s_texture_u;  
uniform sampler2D s_texture_v;   
void main() {  
    highp float y = texture2D(s_texture_y, v_texcoord).r;  
    highp float u = texture2D(s_texture_u, v_texcoord).r - 0.5;  
    highp float v = texture2D(s_texture_v, v_texcoord).r - 0.5;  
    highp float r = y +             1.402 * v;  
    highp float g = y - 0.344 * u - 0.714 * v;  
    highp float b = y + 1.772 * u;  
    gl_FragColor = vec4(r,g,b,1.0);  
}

2. create textures from YUV420p frame

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);  
glGenTextures(3, _textures);  
const UInt8 *pixels[3] = { yuvFrame.luma.bytes, yuvFrame.chromaB.bytes, yuvFrame.chromaR.bytes };  
const NSUInteger widths[3]  = { frameWidth, frameWidth / 2, frameWidth / 2 };  
const NSUInteger heights[3] = { frameHeight, frameHeight / 2, frameHeight / 2 };  
for (int i = 0; i < 3; ++i) {  
    glBindTexture(GL_TEXTURE_2D, _textures[i]);  
    glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, widths[i],heights[i],0,GL_LUMINANCE,GL_UNSIGNED_BYTE,pixels[i]);  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);  
}

3. init vertices and texture coords

static const GLfloat texCoords[] = { 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f };  
static const GLfloat vertices[]= {-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f };

4. render frame

[EAGLContext setCurrentContext:_context];  
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);  
glViewport(0, 0, _backingWidth, _backingHeight);  
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  
glClear(GL_COLOR_BUFFER_BIT);  
glUseProgram(_program);  
for (int i = 0; i < 3; ++i) {  
    glActiveTexture(GL_TEXTURE0 + i);  
    glBindTexture(GL_TEXTURE_2D, _textures[i]);  
    glUniform1i(_uniformSamplers[i], i);  
}  
glVertexAttribPointer(ATTRIBUTE_VERTEX, 2, GL_FLOAT, 0, 0, vertices);  
glEnableVertexAttribArray(ATTRIBUTE_VERTEX);  
glVertexAttribPointer(ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, 0, 0, texCoords);  
glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD);  
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);  
[_context presentRenderbuffer:GL_RENDERBUFFER];

The link to project on github.

https://stackoverflow.com/questions/12428108/ios-how-to-draw-a-yuv-image-using-opengl

第25月第11天deeplearning.ai

1.网易云课堂深度学习工程师点击进入课程地址(英文)(收费)点击进入课程地址(中文)(免费)第一门神经网络和深度学习第二门改善神经网络第三门结构化机器学习项目第四门卷积神经网络第五门序列模型  查看详情

第11月第8天ffmpegffplay

1.staticintfunc_fill_frame(SDL_VoutOverlay*overlay,constAVFrame*frame){assert(overlay);SDL_VoutOverlay_Opaque*opaque=overlay->opaque;AVFrameswscale_dst_pic={{0}};av_frame_unref(opaque->linked_fr 查看详情

第13月第25天ios11uitableviewreloaddatacontentsize

1.          [tableViewreloadData];        dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(0.1*NSEC_PE 查看详情

第11月第18天racsequence

1. RACSequence的内部存储结构就像一个单链表,有两个指针head和tail,head指针指向了当前链表的第一个元素,tail指向head指针下一个元素;根据RACSequence是否还有内容来判断是否还需要递归遍历RACSequence(将数组中的元素一个一... 查看详情

第11月第23天markedtextrange崩溃

1.在对textView、textField限制文字长度时,如果不做特殊处理,当联想文字加上已输入文字超出设定长度时,iOS 7.0系统会崩溃(ios 8.0以上系统做了处理,不会崩溃)。 http://blog.csdn.net/hero_wqb/article/details/52075579?locationNum=4... 查看详情

第29月第14天evpp

1.evpp https://github.com/Qihoo360/evpp/tree/master/examples/recipes/self_control_timerhttps://blog.csdn.net/zieckey/article/details/70245013  2.enable_shared_from_this shared_ptr接收裸指针,更改引用计数。shared_ptr接收shared_ptr,更改引用计数。在类的内... 查看详情

第27月第27天https

1. 14.这么多机器,第三方机构的公钥怎么跑到了客户端的机器中呢?    其实呢,现实中,浏览器和操作系统都会维护一个权威的第三方机构列表(包括它们的公钥)。因为客户端接收到的证书中会写有颁发机... 查看详情

第9月第3天uilabelcontentscale

1. http://blog.csdn.net/u012703795/article/details/43706449 查看详情

第9月第30天mvp

1. importUIKitstructPerson{//ModelletfirstName:StringletlastName:String}protocolGreetingView:class{funcsetGreeting(greeting:String)}protocolGreetingViewPresenter{init(view:GreetingView,person:Per 查看详情

第16月第27天pipinstallvirtualenv

1.pipinstallvirtualenvvirtualenvtestvircdtestvircdScriptsactivatepipinstalldjango==1.9.8 https://zhuanlan.zhihu.com/p/32286726 查看详情

第2月第24天coretext行高

1.NSMutableAttributedString 行高 NSMutableAttributedString*attributedString=[[NSMutableAttributedStringalloc]initWithString:labelText];NSMutableParagraphStyle*paragraphStyle=[[NSMutableParagra 查看详情

第10月第28天touchesbegan

1.-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event{[[selfnextResponder]touchesBegan:toucheswithEvent:event];[supertouchesBegan:toucheswithEvent:event];}-(void)touchesMoved:(NSSet*)touchesw 查看详情

第37月第29天avplayer截屏

1.-(void)displayLinkCallback:(CADisplayLink*)sender{CMTimetime=[snapshotOutputitemTimeForHostTime:CACurrentMediaTime()];if([snapshotOutputhasNewPixelBufferForItemTime:time]){lastSnapshotPixelBuffer=[s 查看详情

第5月第18天视频编辑水印

1.//***********ForASpecialTimeCABasicAnimation*animation=[CABasicAnimationanimationWithKeyPath:@"opacity"];[animationsetDuration:0];[animationsetFromValue:[NSNumbernumberWithFloat:1.0]];[animationsetT 查看详情

第16月第3天afurlsessionmanager

1. -(AFURLSessionManagerTaskDelegate*)delegateForTask:(NSURLSessionTask*)task{  NSParameterAssert(task);   AFURLSessionManagerTaskDelegate*delegate=nil;  [self. 查看详情

第28月第11天vim-b

1.首先以二进制方式编辑这个文件:      vim-bdatafile现在用xxd把这个文件转换成十六进制:      :%!xxd文本看起来像这样:      0000000:1f8b080839d7173b02037474002b4e49  ..... 查看详情

第26月第3天javagradle

1.430/Applications/AndroidStudio.app/Contents/gradle/gradle-2.8/bin/gradle-v434mkdirgradle01435cdgradle01 437 /Applications/AndroidStudio.app/Contents/gradle/gradle-2.8/bin/gradleinit--typ 查看详情

第5月第6天nsoperationisconcurrent

1. @implementationAFURLConnectionOperation...-(BOOL)isConcurrent{returnYES;} NSOperation调用start方法即可开始执行操作,NSOperation对象默认按同步方式执行,也就是在调用start方法的那个线程中直接执行。NSOperation对象的isConcurrent方法会告诉我... 查看详情