Using x264enc - fails in gst-factory-make

I have a program using gstreamer which I have not compiled for many years. I recently needed to compile it again - and it throws up a problem.
In my program I attempt to use x264enc as part of my pipeline - but when I attempt to build my pipeline, the x264enc element fails.
I have included the ugly plugins on my system.
What should I look at to rectify my problem?

Perhaps you could tell us how it fails, for what kind of pipeline?

I create the pipeline like this.
/* Create gstreamer elements */
pipeline = gst_pipeline_new (“av-recorder”);
vsource = gst_element_factory_make (“v4l2src”, “vid-source”);
queue1a = gst_element_factory_make (“queue”, “queue1a”);
vidrate = gst_element_factory_make (“videorate”, “vidrate”);
vidscale = gst_element_factory_make (“videoscale”, “vidscale”);
vcapsfilter = gst_element_factory_make (“capsfilter”, “vid-caps”);
queue1 = gst_element_factory_make (“queue”, “queue1”);
vidconvert = gst_element_factory_make (“videoconvert”,“vidconvert”);
videnc = gst_element_factory_make (“x264enc”, “videnc”);
asource = gst_element_factory_make (“alsasrc”, “alsa-source”);
acapsfilter = gst_element_factory_make (“capsfilter”, “audio-caps”);
queue2 = gst_element_factory_make (“queue”, “queue2”);
audrate = gst_element_factory_make (“audiorate”, “audrate”);
queue3 = gst_element_factory_make (“queue”, “queue3”);
lameenc = gst_element_factory_make (“lamemp3enc”, “lameenc”);
mux = gst_element_factory_make (“mp4mux”, “mp4-mux”);
sink = gst_element_factory_make (“filesink”, “file-output”);

tee = gst_element_factory_make (“tee”, “tee”);
aconv2 = gst_element_factory_make (“audioconvert”, “audio2-conv”);
queue4 = gst_element_factory_make (“queue”, “queue4”);
wavenc = gst_element_factory_make (“wavenc”, “wav-encoder”);
asink = gst_element_factory_make (“filesink”, “wav-output”);

videotee = gst_element_factory_make (“tee”, “videotee”);
queue5 = gst_element_factory_make (“queue”, “queue5”);
monrate = gst_element_factory_make (“videorate”, “monrate”);
monscale = gst_element_factory_make (“videoscale”, “monscale”);
moncapsfilter = gst_element_factory_make (“capsfilter”, “mon-caps”);
monconvert = gst_element_factory_make (“videoconvert”, “mon-convert”);

videosink = gst_element_factory_make (“autovideosink”, “videosink”);

if (!pipeline || !vsource || !vidrate || !vcapsfilter || !queue1 || !videnc || !asource || !acapsfilter || !queue2 || !audrate || !queue3 || !lameenc || !mux || !sink || !tee || !aconv2 || !queue4 || !wavenc || !asink || !videotee || !queue5 || !monrate || !monscale || !moncapsfilter || !monconvert || !videosink) {
g_printerr (“One element could not be created. Exiting.\n”);
return;
}

I modified the code to check each element individually and only ‘videnc’ failed.

Is there a list of plugins - so that I can select an alternative encoder to x264 for testing purposes? I can’t find one.

gst-inspect-1.0 would list the available plugins/elements in your system.
gst-inspect-1.0 your_element would display various information about that element.

OK. So that showed that I do not have x264enc. That would explain why the gst_element_factory_make did not work.
I thought that x264enc was supposed to be in the ugly plugin. I have gstreamer-plugins-ugly-free installed, so it obviously wasn’t there. Has it moved elsewhere?

Not sure, it mainly means that it is not yet working within gstreamer.
The plugin might be installed in your system, though gstreamer might not be aware of it or it might have missing dependencies.

Gstreamer has a cache that may need to be updated. You would just delete it (or move it) and it will be recreated next time you use a gstreamer command.
The cache location depends on your OS (Linux: $HOME/.cache/gstreamer-1.0/, Windows: $HOME\AppData\Local\Microsoft\Windows\INetCache\gstreamer-1.0), and name on your platform architecture (such as registry.arch.bin).
Then re-create the cache and show any blacklisted element:

gst-inspect-1.0 -b

You can quickly check if the same happens with:

gst-launch-1.0 videotestsrc ! x264enc ! fakesink

I tried

and it reported that there was no x264enc.

I checked what packages I have installed and it came up with

Installed packages
gstreamer1.i686                               1.24.8-1.fc41  fedora
gstreamer1.x86_64                             1.24.8-1.fc41  fedora
gstreamer1-devel.x86_64                       1.24.8-1.fc41  fedora
gstreamer1-plugin-libav.x86_64                1.24.11-1.fc41 updates
gstreamer1-plugin-openh264.x86_64             1.24.11-1.fc41 updates
gstreamer1-plugins-bad-free.x86_64            1.24.11-1.fc41 updates
gstreamer1-plugins-bad-free-libs.x86_64       1.24.11-1.fc41 updates
gstreamer1-plugins-base.x86_64                1.24.11-1.fc41 updates
gstreamer1-plugins-good.x86_64                1.24.11-1.fc41 updates
gstreamer1-plugins-good-gtk.x86_64            1.24.11-1.fc41 updates
gstreamer1-plugins-good-qt.x86_64             1.24.11-1.fc41 updates
gstreamer1-plugins-ugly-free.x86_64           1.24.11-1.fc41 updates

I noticed that the first three packages were not at the same level as the rest. I did an update, and now they are. However the result is the same. gst-inspect-1.0 -b shows no blacklisted files.

After upgrading, did you try to clear the cache ?
If yes and no blacklisted plugin, didn’t then gst-inspect-1.0 show x264enc and the shell command still fails ?
If yes you would have to check the directory where you have gstreamer-plugins-ugly installed, check if there is a lib such as libgstx264.so. If installed into an unusual path, you may add this path in front of GST_PLUGIN_PATH environment variable, then recreate the cache and check.

Hello, I’ve never used fedora but x264 is not even listed as a file in that package:

lib64/
  gstreamer-1.0/
    libgsta52dec.so
    libgstasf.so
    libgstcdio.so
    libgstdvdlpcmdec.so
    libgstdvdread.so
    libgstdvdsub.so
    libgstmpeg2dec.so
    libgstrealmedia.so

Compare that to the ugly package for debian where x264enc is listed.

/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstx264.so

There is another software encoder for h264 called openh264enc, you have the package for that installed already. You might be able to use that instead? Or there might be hardware encoders available on your device.

1 Like

I originally wrote the program over 10 years ago and at that time, x264enc came with the fedora ‘set’.
I have tried the openh264enc - but the pipeline did not link properly. I haven’t determined why as yet.

You may try (assuming that you’ve a working local display):

gst-launch-1.0 -v videotestsrc ! video/x-raw,format=I420 ! openh264enc ! h264parse ! queue ! decodebin ! autovideoconvert ! autovideosink

Otherwise just:

gst-launch-1.0 -v videotestsrc ! video/x-raw,format=I420 ! openh264enc ! fakesink

If you’re on fedora, you may need to use some rpmfusion packages. Or you can build x264/GStreamer yourself.

OK. I attempted the first option - but it ‘could not initialize the supporting library’

an@fedora:~$ gst-launch-1.0 -v videotestsrc ! video/x-raw,format=I420 ! openh264enc ! h264parse ! queue ! decodebin ! autovideoconvert ! autovideosink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter3.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
ERROR: from element /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0: Could not initialise supporting library.
Additional debug info:
../ext/openh264/gstopenh264enc.cpp(764): gst_openh264enc_set_format (): /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0:
Failed to create OpenH264 encoder.
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
ERROR: from element /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0: Could not initialise supporting library.
Additional debug info:
../ext/openh264/gstopenh264enc.cpp(764): gst_openh264enc_set_format (): /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0:
Failed to create OpenH264 encoder.
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0: Could not initialise supporting library.
Additional debug info:
../ext/openh264/gstopenh264enc.cpp(764): gst_openh264enc_set_format (): /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0:
Failed to create OpenH264 encoder.
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0: Could not initialise supporting library.
Additional debug info:
../ext/openh264/gstopenh264enc.cpp(764): gst_openh264enc_set_format (): /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0:
Failed to create OpenH264 encoder.
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0: Internal data stream error.
Additional debug info:
../libs/gst/base/gstbasesrc.c(3177): gst_base_src_loop (): /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0: Could not initialise supporting library.
Additional debug info:
../ext/openh264/gstopenh264enc.cpp(764): gst_openh264enc_set_format (): /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0:
Failed to create OpenH264 encoder.
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0: Could not initialise supporting library.
Additional debug info:
../ext/openh264/gstopenh264enc.cpp(764): gst_openh264enc_set_format (): /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0:
Failed to create OpenH264 encoder.
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0: Could not initialise supporting library.
Additional debug info:
../ext/openh264/gstopenh264enc.cpp(764): gst_openh264enc_set_format (): /GstPipeline:pipeline0/GstOpenh264Enc:openh264enc0:
Failed to create OpenH264 encoder.
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstTypeFindElement:typefind: Stream doesn't contain enough data.
Additional debug info:
../plugins/elements/gsttypefindelement.c(1012): gst_type_find_element_chain_do_typefinding (): /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstTypeFindElement:typefind:
Can't typefind stream
ERROR: pipeline doesn't want to preroll.
Freeing pipeline ...