centricular / gstcefsrc

A simple gstreamer wrapper around Chromium Embedded Framework
84 stars 45 forks source link

Save cef video + audio output to file #16

Closed reinismu closed 3 years ago

reinismu commented 3 years ago

Hi,

I'm pretty new with gstreamer. One thing I would like to do is save cef video + audio to file.

My attempts

Attempt 1

gst-launch-1.0 cefsrc url="https://soundcloud.com/platform/sama" ! \
    video/x-raw, width=1920, height=1080, framerate=60/1 ! \
    cefdemux name=demux ! videoconvert ! queue ! x264enc ! \
    mp4mux name=muxer fragment-duration=1000 ! filesink location='test.mp4' \
    demux. ! queue ! audioconvert ! audiorate ! audioresample ! faac bitrate=128000 ! muxer.

Stuck at

gst-launch-1.0 cefsrc url="https://soundcloud.com/platform/sama" ! \
    video/x-raw, width=1920, height=1080, framerate=60/1 ! \
    cefdemux name=demux ! videoconvert ! queue ! x264enc ! \
    mp4mux name=muxer fragment-duration=1000 ! filesink location='test.mp4' \
    demux. ! queue ! audioconvert ! audiorate ! audioresample ! faac bitrate=128000 ! muxer.
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Redistribute latency...

Attempt 2

After reading this comment https://github.com/centricular/gstcefsrc/issues/10#issuecomment-555431647 I tried that and it worked, but only 20% of the time. The rest 80% it still stuck and didn't do anything.

I see that @MathieuDuponchelle mentions "pad-added / pad-removed signals"' Tho from last CEF updates we have consistent audio pad right?

Maybe someone could shine light on me on what I am doing wrong and how to fix it?

Thanks!

MathieuDuponchelle commented 3 years ago

I think this is a classic case of too small queues, please try queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 for both queues and report back :)

reinismu commented 3 years ago

@MathieuDuponchelle Thanks!!

The command I run to get it working

gst-launch-1.0 cefsrc url="https://soundcloud.com/platform/sama" ! \
    video/x-raw, width=1920, height=1080, framerate=60/1 ! \
    cefdemux name=demux ! videoconvert ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! x264enc ! \
    mp4mux name=muxer fragment-duration=1000 ! filesink location='test.mp4' \
    demux. ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! audioconvert ! audiorate ! audioresample ! faac bitrate=128000 ! muxer.

Tho now pages where there is no sound won't work :(

gst-launch-1.0 cefsrc url="https://google.com" ! \
    video/x-raw, width=1920, height=1080, framerate=60/1 ! \
    cefdemux name=demux ! videoconvert ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! x264enc ! \
    mp4mux name=muxer fragment-duration=1000 ! filesink location='test.mp4' \
    demux. ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! audioconvert ! audiorate ! audioresample ! faac bitrate=128000 ! muxer.

My end goal is to record a webpage where the sound is just sometimes and it won't start with a sound. Maybe there is easy way I can modify my pipeline to achieve it?

MathieuDuponchelle commented 3 years ago

yes, add an audiomixer, hooked up to a live audiotestsrc that outputs silence

reinismu commented 3 years ago

You are the best! Thanks a lot!

For anyone reading this later. This is how my pipeline looks line now

With silent site

gst-launch-1.0 cefsrc url="https://google.com" ! \
    video/x-raw, width=1920, height=1080, framerate=60/1 ! \
    cefdemux name=demux ! videoconvert ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! x264enc ! \
    mp4mux name=muxer fragment-duration=1000 ! filesink location='test.mp4' \
    audiotestsrc do-timestamp=true is-live=true  volume=0.00 ! audiomixer name=mix ! \
    queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! audioconvert ! audiorate ! audioresample ! faac bitrate=128000 ! muxer. \
    demux. ! mix.

With music

gst-launch-1.0 cefsrc url="https://soundcloud.com/platform/sama" ! \
    video/x-raw, width=1920, height=1080, framerate=60/1 ! \
    cefdemux name=demux ! videoconvert ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! x264enc ! \
    mp4mux name=muxer fragment-duration=1000 ! filesink location='test.mp4' \
    audiotestsrc do-timestamp=true is-live=true  volume=0.00 ! audiomixer name=mix ! \
    queue max-size-bytes=0 max-size-buffers=0 max-size-time=3000000000 ! audioconvert ! audiorate ! audioresample ! faac bitrate=128000 ! muxer. \
    demux. ! mix.
MathieuDuponchelle commented 3 years ago

@reinismu cool, maybe make a MR and update the README with an audiomixer?