An alternative to ffmpeg is the gstreamer library, which comes with optional plug-ins to perform video encoding using Intel GPUs.
Gstreamer can be installed on Ubuntu by following instructions on https://gstreamer.freedesktop.org/documentation/installing/on-linux.html?gi-language=c
Assuming gstreamer has been installed on Ubuntu, you can run the following command to save the video into an output.mp4 video file.
$ gst-launch-1.0 \ v4l2src device=/dev/video0 num-buffers=300 ! \ 'video/x-raw,framerate=10/1,width=1280,height=720' ! \ videoconvert ! \ vaapih264enc ! \ h264parse ! \ filesink location=output.mp4
Note 1: device specifies the video source /dev/video0 and num-buffers specifies the number of frames to read.
Note 2: The line video/x-raw specifies the format, frame rate and resolution to read from the video source.
Note 3: vaapih264enc specifies the Intel Video Accelerated encoder to use.
Note 4: filesink location specifies the output video file.
While the gstreamer command is processing the video, in another terminal, run the command to monitor the Intel GPU.
$ sudo intel_gpu_top
As shown above, the printout in red indicates the GPU is being used.
Caution: On some Intel boards I have tested, sometimes running the gstreamer vaapih264enc plugin resulted in the following error message even though the plugin has been installed:
WARNING: erroneous pipeline: no element "vaapih264enc"
In my case, I managed to resolve that error by setting the following environment variables before running the encoding command:
$ export LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri/
$ export LIBVA_DRIVER_NAME=i965
No comments:
Post a Comment