Ffplay on SDL2 II

Source: Internet
Author: User

This stage completes the ffplay transplant to SDL2, the basic test on the PC: Picture, video OK.

API 1.2
Sdl_surface *screen;
Screen = Sdl_setvideomode (w, h, 0, flags);
Sdl_wm_setcaption
Sdl_fillrect
Screen->format, W, h
Sdl_updaterect

Sdl_overlay *bmp;
Sdl_createyuvoverlay (screen);
Sdl_lockyuvoverlay
Bmp->pixels[i],pitches[i]//video_thread-->queue_picture; Video_image_display-->blend_subrect
Video_refresh-->video_display-->video_image_display
Sdl_displayyuvoverlay

API 2.0
Sdl_window *win;
Sdl_createwindow, Sdl_setwindowsize, Sdl_setwindowtitle,
Sdl_getwindowsurface (Win)->format,w,h
Sdl_renderer *render;
Sdl_createrenderer (Win), Sdl_renderclear, Sdl_rendercopy, sdl_renderpresent
Sdl_texture *texture;
Sdl_createtexture (render), Sdl_locktexture/transform/sdl_unlocktexture, Sdl_updateyuvtexture,

problem
Q. YUV format conversion.
A. The pixel/pitch that locktexture gets points to Y. YUV is a compact arrangement, without align, so that the U,v Data/pitch can be launched.
Q. Ffplay a.png output also yuv420p?
A. Yes. In Configure_video_filters (), set the Filt_out "Pix_fmts". Vf_scale.c the tune?
Avfilter_graph_config-->
Graph_config_formats-->query_formats--> "auto-inserted scaler%d"
Sdl_window--Physical pixels you see, corresponds to multiple
Sdl_renderer--store settings and context, corresponding to multiple
Sdl_texture--Resource, element.

Q:texture is displayed in another view.
Main view--composited layers
Layer View--individual layer

A:SRC = Sdl_getwindowsurface (Src_win);
FMT = Sdl_getwindowpixelformat (Src_win);
Sdl_renderreadpixels (src_render, 0, FMT, Src->pixels, Src->pitch);
Sdl_updatetexture (Dst_render, Src->pixels, Src->pitch);

Q:resize,blend,colorkey?
A:sdl_rendersetscale (SX, SY)/sdl_rendercopy with diff rect,
Sdl_settexturealphamod (a)/sdl_setrenderdrawblendmode (blend),

Q: Green Edge processing duplicate_right_border_pixels ().
Does the A:SDL2 still exist?
Render to texture
Direct pixels operation

Q: Using Sdl2_image,
Sdl_surface *s = img_load ("In.png");
Sdl_texture *t = Sdl_createtexturefromsurface (render, s);
Sdl_freesurface (s);
Can you manipulate textures directly?
A: [1] Examples are for ARGB, using sdl_updatetexture (t,rect, pixels, pitch);
Write pixels, what if you want to read pixels?
Sdl_locktexture (t, rect, &pixels, &pitch);
Provides a write-only pixel pointer.
Sdl_locksurface (s) can read and write to S->pixels.
Pixel read for render:
Sdl_renderreadpixels (R, Rect, FMT, pixels, pitch);

Q: Because the video aspect ratio and window width are different, the surrounding black edge, to Fill_border-->fill_rectangle-->sdl_fill/updaterect
A:sdl_setrenderdrawcolor (Render, a,r,g,b);
4 times Sdl_renderfillrect (Render, rect);
1 times sdl_renderpresent (render);
According to SDL2 inside the note, sdl_renderpresent (render) after the backbuffer display,
Backbuffer is no longer valid, so it is recommended to Sdl_renderclear () before the new drawing starts, even if each pixel is overridden.
So the Fill_border code can be omitted completely.

Retrofit Program
====
Some people say that locktexture is slower than updateyuvtexture.
The lock is introduced here in order to directly modify the pixels, subtitles mixed blend_subrect used.
We do not have to lock, as long as the caption as texture can!
In fact, the SDL2 bottom of the YUV processing is also used three texture to do.
Screen-to-win
BMP--Texture
Blend_subrect-Sdl_updateyuvtexture (T,rect, Ydata, Ypitch,...);
The rest of the matter is considering how big the graphics memory is,
Video_picture_queue_size, how much is subpicture_queue_size configured.

Debug
====
Q. Sdl_createrenderer flag =sdl_renderer_software was not dead, 0 died in glenable ().
A. Render only on the main thread.
Put
Video_thread-->queue_picture-->sdl_updateyuvtexture_real
Move to the main thread:
Refresh_loop_wait_event-->video_refresh-->video_display-->video_image_display
In fact, for the sake of simplicity, update at alloc_picture.

The code is placed in

Https://github.com/DeYangLiu/ffmpeg-streaming/blob/master/ffplay2.c


Todo
After full screen, the left and right sides are red edges.

Test the video with subtitles.

Ref
====
[1] http://www.programmersranch.com/2014/02/sdl2-pixel-drawing.html


Ffplay on SDL2 II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.