Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

YUV Overlay

13 views
Skip to first unread message

tmu...@wumpus-cave.net

unread,
Jul 23, 2013, 5:44:29 PM7/23/13
to sdl-...@perl.org
I'm working on a project involving decoding h.264 video frames with
ffmpeg and then outputting them to an SDL surface. From what I've read,
the YUV overlay is meant for this kind of job, but I'm having trouble
getting it to work with the Perl bindings.

One thing that seems odd to me in the Perl docs is:

As of release 2.3 direct right to overlay is disable.

Besides the typos, this troubles me because it seems that disabling the
feature makes the YUV overlay completely useless.

Not to be deterred, I wrote this code:

SDL::Video::lock_YUV_overlay( $overlay );
# The order of array indexen is correct, according to:
# http://dranger.com/ffmpeg/tutorial02.html
my $pitches = $overlay->pitches;
$$pitches[0] = scalar @{ $last_vid_frame[0] };
$$pitches[2] = scalar @{ $last_vid_frame[1] };
$$pitches[1] = scalar @{ $last_vid_frame[2] };
my $pixels = $overlay->pixels;
$$pixels[0] = $last_vid_frame[0];
$$pixels[2] = $last_vid_frame[1];
$$pixels[1] = $last_vid_frame[2];
SDL::Video::unlock_YUV_overlay( $overlay );

SDL::Video::update_rects( $sdl, $bg_rect );
SDL::Video::display_YUV_overlay( $sdl, $bg_rect );

When I run this, I get an error about not being able to find the
pitches() method against the class "SDL::Overlay". Eh? (Same thing
happens for the pixels() method if I put that call first.) I can call
width() and format() and such just fine on that object.

If needed, I can handle the overlay entirely at the C level. I may end
up doing that anyway; the C array that comes out of ffmpeg is being
transformed into a Perl array-of-arrays, which is going to be an
expensive operation to do for 720p at 30 fps in realtime. But I'd like
to try this at the Perl level for now.

I might also have to convert the output from ffmpeg using sws_scale().
It's coming out in YUV420P mode, and I'm using YV12 to init the overlay.
But I'd like to get the above working before messing with that.

Thanks,
Timm Murray

Tobias Leich

unread,
Jul 24, 2013, 2:00:02 AM7/24/13
to tmu...@wumpus-cave.net, sdl-...@perl.org
Hi, can you paste a complete example please? Maybe with a link to a test
video file.

What I would try first is SDL's latest release, which is 2.540 or so.

Cheers, FROGGS

tmu...@wumpus-cave.net

unread,
Jul 24, 2013, 8:22:27 AM7/24/13
to sdl-...@perl.org
Short on time at the moment, but I have the complete code on a github
repo:

https://github.com/frezik/UAV-Pilot

The relevant code is in UAV::Pilot::SDL::Video, and the decoding
happens in the xs file for UAV::Pilot::Video::H264Decoder. The test
t/160_video_decode.t should run the decoding end of things. There's a
test video in t_data/ardrone_video_stream_dump.bin, though that contains
the PaVE headers from the UAV before each frame. Those headers can be
stripped out by bin/uav_video_dump.

I'll try to come up with a more concise example later this evening.

Thanks,
Timm

Kartik Thakore

unread,
Jul 24, 2013, 9:17:32 AM7/24/13
to tmu...@wumpus-cave.net, sdl-...@perl.org
Can we run this with out needing ARDdrone?

tmu...@wumpus-cave.net

unread,
Jul 24, 2013, 9:34:20 AM7/24/13
to sdl-...@perl.org
Yes. For my own testing purposes, it's not always convenient to
connect to the ARDrone, so I overrode much of the behavior in Mock
classes.

For decoding the video stream to a file, you can do:

$ uav_video_dump --in t_data/ardrone_video_stream_dump.bin --out
/tmp/ardrone_video_stream_dump.h264

And then play the out file in a mplayer or vlc. Mplayer might need you
to manually set the -fps option (set to "25", I think), or it will
mangle the output.

Playing the video in real time should work with:

$ uav_video_display --in t_data/ardrone_video_stream_dump.bin

Which should pop up the SDL window, and then dump a bunch of error
messages to the console. This is the one I'm trying to get working here.

Thanks,
Timm

On 24.07.2013 08:17, Kartik Thakore wrote:
> Can we run this with out needing ARDdrone?
>
> On Wed, Jul 24, 2013 at 8:22 AM, <tmu...@wumpus-cave.net> wrote:
>
>> Short on time at the moment, but I have the complete code on a
>> github repo:
>>
>> https://github.com/frezik/UAV-Pilot [2]
>>
>> The relevant code is in UAV::Pilot::SDL::Video, and the decoding
>> happens in the xs file for UAV::Pilot::Video::H264Decoder.  The test
>> t/160_video_decode.t should run the decoding end of things. There's a
>> test video in t_data/ardrone_video_stream_dump.bin, though that
>> contains the PaVE headers from the UAV before each frame.  Those
>> headers can be stripped out by bin/uav_video_dump.
>>
>> I'll try to come up with a more concise example later this evening.
>>
>> Thanks,
>> Timm
>>
>> On 24.07.2013 01 [3]:00, Tobias Leich wrote:
>>
>>> Hi, can you paste a complete example please? Maybe with a link to a
>>> test
>>> video file.
>>>
>>> What I would try first is SDL's latest release, which is 2.540 or
>>> so.
>>>
>>> Cheers, FROGGS
>>>
>>> Am 23.07.2013 23:44, schrieb tmu...@wumpus-cave.net:
>>>
>>>> I'm working on a project involving decoding h.264 video frames
>>>> with
>>>> ffmpeg and then outputting them to an SDL surface. From what I've
>>>> read, the YUV overlay is meant for this kind of job, but I'm
>>>> having
>>>> trouble getting it to work with the Perl bindings.
>>>>
>>>> One thing that seems odd to me in the Perl docs is:
>>>>
>>>>     As of release 2.3 direct right to overlay is disable.
>>>>
>>>> Besides the typos, this troubles me because it seems that
>>>> disabling
>>>> the feature makes the YUV overlay completely useless.
>>>>
>>>> Not to be deterred, I wrote this code:
>>>>
>>>>     SDL::Video::lock_YUV_overlay( $overlay );
>>>>     # The order of array indexen is correct, according to:
>>>>     # http://dranger.com/ffmpeg/tutorial02.html [1]
> Links:
> ------
> [1] http://dranger.com/ffmpeg/tutorial02.html
> [2] https://github.com/frezik/UAV-Pilot
> [3] tel:24.07.2013%2001

tmu...@wumpus-cave.net

unread,
Jul 24, 2013, 4:53:38 PM7/24/13
to sdl-...@perl.org
I've made a simplified, standalone example:

http://pastebin.com/dPPNc8VL

The big array at the top is a single YUV420P frame. Expected behavior
is to display that frame in a window for 5 seconds, and then quit. If I
comment out the overlay handling, it displays a green background.

I've verified that I'm running SDL 2.540.

Thanks,
Timm

On 24.07.2013 08:17, Kartik Thakore wrote:
> Can we run this with out needing ARDdrone?
>
> On Wed, Jul 24, 2013 at 8:22 AM, <tmu...@wumpus-cave.net> wrote:
>
>> Short on time at the moment, but I have the complete code on a
>> github repo:
>>
>> https://github.com/frezik/UAV-Pilot [2]
>>
>> The relevant code is in UAV::Pilot::SDL::Video, and the decoding
>> happens in the xs file for UAV::Pilot::Video::H264Decoder.  The test
>> t/160_video_decode.t should run the decoding end of things. There's a
>> test video in t_data/ardrone_video_stream_dump.bin, though that
>> contains the PaVE headers from the UAV before each frame.  Those
>> headers can be stripped out by bin/uav_video_dump.
>>
>> I'll try to come up with a more concise example later this evening.
>>
>> Thanks,
>> Timm
>>
>> On 24.07.2013 01 [3]:00, Tobias Leich wrote:
>>
>>> Hi, can you paste a complete example please? Maybe with a link to a
>>> test
>>> video file.
>>>
>>> What I would try first is SDL's latest release, which is 2.540 or
>>> so.
>>>
>>> Cheers, FROGGS
>>>
>>> Am 23.07.2013 23:44, schrieb tmu...@wumpus-cave.net:
>>>
>>>> I'm working on a project involving decoding h.264 video frames
>>>> with
>>>> ffmpeg and then outputting them to an SDL surface. From what I've
>>>> read, the YUV overlay is meant for this kind of job, but I'm
>>>> having
>>>> trouble getting it to work with the Perl bindings.
>>>>
>>>> One thing that seems odd to me in the Perl docs is:
>>>>
>>>>     As of release 2.3 direct right to overlay is disable.
>>>>
>>>> Besides the typos, this troubles me because it seems that
>>>> disabling
>>>> the feature makes the YUV overlay completely useless.
>>>>
>>>> Not to be deterred, I wrote this code:
>>>>
>>>>     SDL::Video::lock_YUV_overlay( $overlay );
>>>>     # The order of array indexen is correct, according to:
>>>>     # http://dranger.com/ffmpeg/tutorial02.html [1]

Tobias Leich

unread,
Aug 5, 2013, 9:41:22 AM8/5/13
to tmu...@wumpus-cave.net, sdl-...@perl.org
Hi, I installed UAV-Pilot right now, but it explodes like:
$ bin/uav_video_dump
Can't locate UAV/Pilot/Control/ARDrone/Video/FileDump.pm in @INC (@INC
contains: /etc/perl /usr/local/lib/perl/5.14.2
/usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5
/usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at
bin/uav_video_dump line 9.
BEGIN failed--compilation aborted at bin/uav_video_dump line 9.

Is there something I can do in order to test your example script?

Cheers, FROGGS

tmu...@wumpus-cave.net

unread,
Aug 5, 2013, 9:58:38 AM8/5/13
to sdl-...@perl.org
Well, that's a bug. I'll have to update that script with the right
module name. Thanks for letting me know.

That script only dumps the video to a file without displaying it. The
script 'uav_video_display', released with version 0.5, is the important
one here.

I ended up solving my overlay issue by doing most of it in C. I
probably needed to do this, anyway, as doing it with Perl datastructures
would have meant creating an SV for each value in the three YUV channels
and pushing them onto an AV. 720p is 0.9 megapixels, so that would have
been a very expensive operation to do 30 times a second to handle
realtime video.

The C technique is used in the recently released UAV::Pilot v0.5.

I have run across a new problem when trying to draw on top of the YUV
overlay. I can draw a line using the RGB colorspace, but it shows up
black. Maybe I need to convert RGB to YUV? Or perhaps draw on a
separate surface and blit that on top?

Thanks,
Timm

Tobias Leich

unread,
Aug 5, 2013, 10:50:39 AM8/5/13
to tmu...@wumpus-cave.net, sdl-...@perl.org
Hi, I am unable tun run that script either:

$ perl bin/uav_video_display
perl: symbol lookup error:
/usr/local/lib/perl/5.14.2/auto/UAV/Pilot/Video/H264Decoder/H264Decoder.so:
undefined symbol: av_init_packet

Do you have an example of your line-drawing problem somewhere?

tmu...@wumpus-cave.net

unread,
Aug 5, 2013, 11:04:51 AM8/5/13
to sdl-...@perl.org
Do you happen to have ffmpeg installed? I'm not really sure how best
to list a Perl module dependency on a C library. Alien::ffmpeg seems to
recompile the whole library, which shouldn't be necessary for people who
already have ffmpeg installed.

The code for drawing on top of the overlay is on github:

https://github.com/frezik/UAV-Pilot/blob/master/lib/UAV/Pilot/SDL/VideoOverlay/Reticle.pm

The "after 'init_video_overlay'" sub gets and stores the RGB color
mapping. Drawing the lines is done in process_video_overlay().

Thanks,
Timm
0 new messages