Re: Re: Re: Overlaying an image on a video

Jan Spurný JSpurny at seznam.cz
Fri Mar 2 01:43:34 PST 2012


Hi,

I was doing similar thing yesterday - I was trying to overlay a logo on
output from one of ours videofilters. I had several mp4 files with h264 video
and no audio. I finally found 2 solutions, which had worked fine when playing
to xvimagesink, but which failed to stop (and also made everything in video
look somehow slowed) so I was unable to store the resulting video in another
video file.

Here's what I had:

 * video-input.mp4:
    - 640x480, 30000/1001 fps h264 stream in mp4 container with no audio
 * logo.png:
    - a color 640x480 png image with transparency
      (mostly fully transparent, only in top left corner small logo)

What I wanted:
 1) to see if it works using some videosink - and it did
 2) to store the result in a file - it worked but it worked forever..

1) to see if it works (I left out our company's filter)
  (a) variant using multifilesrc with caps:

    caps="video/x-raw-yuv,format=(fourcc)AYUV,width=640,height=480,framerate=(fraction)30000/1001"
    caps_png="image/png,framerate=(fraction)30000/1001"

    logo=logo.png
    vid=video-input.mp4

    gst-launch  \
        videomixer name=mix \
            ! ffmpegcolorspace \
            ! xvimagesink sync=false \
        multifilesrc location = $logo caps = $caps_png \
            ! pngdec \
            ! ffmpegcolorspace \
            ! $caps \
            ! mix. \
        filesrc location = $vid \
            ! qtdemux \
            ! ffdec_h264 \
            ! ffmpegcolorspace \
            ! $caps \
            ! mix.

    There's probably more 'ffmpegcolorspace's than needed, but it shouldn't
    hurt anything.

  (b) variant using imagefreeze:

    caps="video/x-raw-yuv,format=(fourcc)AYUV,width=640,height=480,framerate=(fraction)30000/1001"

    logo=logo.png
    vid=video-input.mp4

    gst-launch  \
        videomixer name=mix \
            ! ffmpegcolorspace \
            ! xvimagesink sync=false \
        filesrc location = $logo \
            ! pngdec \
            ! imagefreeze \
            ! ffmpegcolorspace \
            ! $caps \
            ! mix. \
        filesrc location = $vid \
            ! qtdemux \
            ! ffdec_h264 \
            ! ffmpegcolorspace \
            ! $caps \
            ! mix.

    And it works too.


2) Here comes the problem - storing the result. If you're fine with just
displaying - feel free to ignore the rest. But if anyone sees where my problem
lies I'd be grateful for any help or suggestions.

So I'm trying to store the video. The pipeline is almost the same (I'll use
the (a) variant):

    caps="video/x-raw-yuv,format=(fourcc)AYUV,width=640,height=480,framerate=(fraction)30000/1001"
    caps_png="image/png,framerate=(fraction)30000/1001"

    logo=logo.png
    vid=video-input.mp4
    res=video-result.mp4

    gst-launch  \
        videomixer name=mix \
            ! ffmpegcolorspace \
            ! x264enc \
            ! mp4mux \
            ! filesink location = $res
        multifilesrc location = $logo caps = $caps_png \
            ! pngdec \
            ! ffmpegcolorspace \
            ! $caps \
            ! mix. \
        filesrc location = $vid \
            ! qtdemux \
            ! ffdec_h264 \
            ! ffmpegcolorspace \
            ! $caps \
            ! mix.

It looks fine, it works, but it works forever - the png image part keeps
sending images even after the video part ends. I came up with only one
solution - limiting nuber of frames sent by multifilesrc, so i changed the
line:
        multifilesrc location = $logo caps = $caps_png \
    to:
        multifilesrc location = $logo caps = $caps_png num-buffers = $frames \

    where '$frames' is number of frames in 'video-input.mp4' I have calculated
    earlier.

I was hoping that when both sources have the same framerate it must work.
Well.. it didn't. I got video which was rouhgly 2.6 times longer and part
where mixer's video input was still working was strangely slowed in some
places and then there was just 1 minute of plain png with transparency
(checkerboard almost all over the place). That was differen than it was when I
was using the 'xvimagesink' - with 'xvimagesink' I got the last video-input's
frame "freezed" and even though it was going forever, it at least looked
normal.

 Here are some things that I tried before I gave up and reencoded the
resulting video with mencoder's 'bmovl' feature:

 * queue
    - I had put queues everywhere - no effect

 * qos
    - I had turned qos everywhere (qos=false) - no effect

 * I tried queues and no-qos with all combinations also with freezeframe
   variant - still no effect

I guess it could work if I just wrote small python program and disconnected
png mixer input on video's eof.. but I didn't had enough time, so I sticked
with mencoder and worse quality (because of another re-encoding).

I hope it may help someone or someone could help me :)


sincerely,
Jan Spurny

    

> 
> Ok, I added a trailing dot. 
> But I got:
>  
> gstpngdec.c(550): gst_pngdec_task (): /GstPipeline:pipeline0/GstPngDec:pngdec0:
> stream stopped, reason error
>  
> with the impossibility to make the "preroll".
>  
> Cheers,
> K.
> -----Messaggio originale-----
> Da: Tim-Philipp Müller <t.i.m at zen.co.uk>
> Inviato il: 01 Mar 2012 - 19:50
> A: gstreamer-devel at lists.freedesktop.org
> 
> 
> On Thu, 2012-03-01 at 11:40 -0800, kususe wrote:
> 
> > I want to code a pipeline to overlay an image on a video. 
> > First I would like to understand how to implement this one and then to code
> > it. 
> > So I attemped with this: 
> > 
> > gst-launch filesrc location=/home/boss/test/video.mpg ! decodebin2 !
> > vid
>  eomixer name=mix ! xvimagesink filesrc location =
> > /home/boss/test/image.png ! pngdec ! ffmpegcolorspace ! mix
> > 
> > but I got: "pipeline wrong. No element called mix"
> 
> I believe the syntax you're looking for is mix. with a trailing dot,
> this basically means "a suitable pad on the element named 'mix'".
> 
>  Cheers
>  -Tim
> 
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
> 
> 
> 
> -------------------------------------------------------------------------------
> Valore legale alle tue mail
> InterfreePEC - la tua Posta Elettronica Certificata
> http://pec.interfree.it
> -------------------------------------------------------------------------------
> 
> 


More information about the gstreamer-devel mailing list