How to include x264enc on yocto

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to include x264enc on yocto

22,627 Views
tejasshah
Contributor III

DaianeAngolini

I have a wandboard-dual board and I am using master branch.

Here is my build configuration:

Build Configuration:

BB_VERSION        = "1.21.0"

BUILD_SYS         = "x86_64-linux"

NATIVELSBSTRING   = "Ubuntu-12.04"

TARGET_SYS        = "arm-poky-linux-gnueabi"

MACHINE           = "wandboard-dual"

DISTRO            = "poky"

DISTRO_VERSION    = "1.5+snapshot-20131030"

TUNE_FEATURES     = "armv7a vfp neon callconvention-hard cortexa9"

TARGET_FPU        = "vfp-neon"

I am doing a power consumption of video applications and therefore need to add x264enc to my image.

Now I have tried it two ways but x264 is not showing up in my final image.

1) First, I have placed gst-plugins-ugly-x264enc in local.conf file

COMMERCIAL_VIDEO_PLUGINS ?= " \

    gst-plugins-ugly-x264enc \

"

and added this line to local.conf file: @PACKAGECONFIG_pn_gstreamer1.0-plugins-ugly += "x264" to enable it.

This configuration gives me an error:

| Computing transaction...error: Can't install gst-meta-video-0.10-r13@cortexa9hf_vfp_neon: no package provides gst-plugins-ugly-x264enc

|

| Saving cache...

|

| WARNING: exit code 1 from a shell command.

| ERROR: Function failed: do_rootfs (log file is located at /home/pshah9/Desktop/yocto-master/fsl-community-bsp/build/tmp/work/wandboard_dual-poky-linux-gnueabi/fsl-image-gui/1.0-r0/temp/log.do_rootfs.16656)

ERROR: Task 7 (/home/pshah9/Desktop/yocto-master/fsl-community-bsp/sources/meta-fsl-demos/recipes-fsl/images/fsl-image-gui.bb, do_rootfs) failed with exit code '1'

NOTE: Tasks Summary: Attempted 6575 tasks of which 6522 didn't need to be rerun and 1 failed.

No currently running tasks (6575 of 6576)

Summary: 1 task failed:

  /home/pshah9/Desktop/yocto-master/fsl-community-bsp/sources/meta-fsl-demos/recipes-fsl/images/fsl-image-gui.bb, do_rootfs

Summary: There was 1 WARNING message shown.

Summary: There was 1 ERROR message shown, returning a non-zero exit code.


2) Second, I have placed gst-plugins-ugly-meta in local.conf file

CORE_IMAGE_EXTRA_INSTALL += " \

       gst-plugins-ugly-meta \

"

and again added this line to local.conf file: PACKAGECONFIG_pn_gstreamer1.0-plugins-ugly += "x264"

Please help. It is urgent

Labels (2)
75 Replies

2,274 Views
LeonardoSandova
Specialist I

Hey Tejas,

strange.

try

gdb

(gdb) file gst-launch

(gdb) run filesrc ! ..........

.

.

Here the core dump should ocurr

.

(gdb) bt

I have built an image with unstripped binaries (with debug symbols). I will try the same pipeline and let you know the result. Seems that the issue is occurring on the libx264.so (x264_git.bb recipe, under poky) library, so we need symbols at least on that lib.

Leo

0 Kudos

2,738 Views
tejasshah
Contributor III

Hi Leo,

I was successful this time with the above commands

root@wandboard-dual:/home# gdb

GNU gdb (GDB) 7.6

Copyright (C) 2013 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "arm-poky-linux-gnueabi".

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>.

(gdb) file gst-launch

Reading symbols from /usr/bin/gst-launch...Reading symbols from /usr/bin/.debug/

gst-launch...done.

done.

(gdb) run v4l2src num-buffers=500 ! video/x-raw-yuv ! queue ! ffmpegcolorspace !

queue ! x264enc ! matroskamux ! filesink location=outputh264.mp4 sync=false

Starting program: /usr/bin/gst-launch v4l2src num-buffers=500 ! video/x-raw-yuv

! queue ! ffmpegcolorspace ! queue ! x264enc ! matroskamux ! filesink location=o

utputh264.mp4 sync=false

[Thread debugging using libthread_db enabled]

Using host libthread_db library "/lib/libthread_db.so.1".

process 1641 is executing new program: /usr/bin/gst-launch-0.10

[Thread debugging using libthread_db enabled]

Using host libthread_db library "/lib/libthread_db.so.1".                      

Setting pipeline to PAUSED ...                                                 

[New Thread 0x4133f460 (LWP 1644)]                                             

[New Thread 0x41b3f460 (LWP 1645)]                                             

[New Thread 0x42695460 (LWP 1646)]                                             

Pipeline is live and does not need PREROLL ...                                 

Setting pipeline to PLAYING ...                                                

New clock: GstSystemClock                                                      

[New Thread 0x438c2460 (LWP 1647)]                                             

[New Thread 0x440c2460 (LWP 1648)]                                             

[New Thread 0x448c2460 (LWP 1649)]                                             

[New Thread 0x45dff460 (LWP 1650)]                                             

                                                                               

Program received signal SIGSEGV, Segmentation fault.                           

[Switching to Thread 0x45dff460 (LWP 1650)]                                    

0x40989e6c in x264_vbv_lookahead (keyframe=<optimized out>,                    

    num_frames=<optimized out>, frames=<optimized out>, a=<optimized out>,     

    h=<optimized out>) at encoder/slicetype.c:1297                             

warning: Source file is more recent than executable.                           

1297                frames[next_nonb]->i_planned_type[idx] = frames[cur_nonb]->i

_type;                                                                         

(gdb) bt                                                                       

#0  0x40989e6c in x264_vbv_lookahead (keyframe=<optimized out>,                

    num_frames=<optimized out>, frames=<optimized out>, a=<optimized out>,     

    h=<optimized out>) at encoder/slicetype.c:1297                             

#1  x264_slicetype_analyse (h=h@entry=0x42edc7d0,                              

    intra_minigop=intra_minigop@entry=1) at encoder/slicetype.c:1681           

#2  0x409bf7e8 in x264_lookahead_slicetype_decide (h=h@entry=0x42edc7d0)       

    at encoder/lookahead.c:85                                                  

#3  0x409bf8d0 in x264_lookahead_thread (h=0x42edc7d0)                         

    at encoder/lookahead.c:113                                                 

#4  0x4027106c in start_thread (arg=0x45dff460) at pthread_create.c:314        

#5  0x4035a810 in ?? () at ../ports/sysdeps/unix/sysv/linux/arm/clone.S:97     

   from /lib/libc.so.6                                                         

#6  0x4035a810 in ?? () at ../ports/sysdeps/unix/sysv/linux/arm/clone.S:97     

   from /lib/libc.so.6                                                         

Backtrace stopped: previous frame identical to this frame (corrupt stack?)     

(gdb)

0 Kudos

2,847 Views
tejasshah
Contributor III

As I said, since it is my thesis, I need different results on different frameworks.

So I did hardware encoder vs software encoder on ffmpeg and I also need to do

hardware encoder vs software encoder on gstreamer. Hardware encoder on gstreamer

result is done, now I need this to be done. It is very important result and I need it to be working.

0 Kudos

2,847 Views
LeonardoSandova
Specialist I

So why do you want to use the x264enc element?

0 Kudos

2,847 Views
tejasshah
Contributor III

Yes, I have used libx264(SW encoding) with ffmpeg and it works perfect.

0 Kudos

2,847 Views
LeonardoSandova
Specialist I

Tejas,

BTW, have you tried SW encoding without GStreamer? I am almost sure the x264 lib should have some test apps what you can base on.

0 Kudos

2,847 Views
tejasshah
Contributor III

Hi Bruno,

I have the gst-fsl-plugins in my image and I am able to use hardware h264(vpuenc codec=6) properly.

And, could you please provide me with a patch?

I mean I got I need to comment the patch you mentioned and also optimize it by using compiler options.

0 Kudos

2,847 Views
daiane_angolini
NXP Employee
NXP Employee

BrunoCastelucci, Would you mind to send a patch to fix this upstream?

0 Kudos

2,847 Views
bfac
NXP Employee
NXP Employee

Hello Tejas,

I was reading your original question and have a question:

The steps above will add a Software based h264 encoder to you image, we wont be making use of the hardware acceleration VPU that can do 1080p h264 encode by hardware.

In case you plan to use the hardware acceleration, I believe we should be adding different packages to your image, the Freescale gst plugins.

BR,

Bruno

0 Kudos

2,847 Views
bfac
NXP Employee
NXP Employee

Hello Leo, Tejas,

I didn't need to go so far as you in regards of the frame rate, queue, but I was able to solve the Segmentation Fault while running the command.

In short words, the compiler was optimizing out many of the frame handling functions, so I needed to change the compiler optimization level.

I will post below the solution, and we can then check if this applies to your case too.

The steps I did to add the x264 lib into my image, and running a camera encoding example was:

On ~/Build/MXT/fsl-community-bsp/sources/poky/meta/recipes-multimedia/x264$ x264_git.bb

Comment patch: file://don-t-default-to-cortex-a9-with-neon.patch \

Add: #EXTRA_OECONF += “--extra-cflags=-O1”

On ~/Build/MXT/fsl-community-bsp/sources/poky/meta/recipes-multimedia/gstreamer$ gst-plugins-ugly_0.10.19.bb

Change line 18 to: PACKAGECONFIG ??= "x264"

On ~/Build/fsl-community-bsp/build/conf$ local.conf

Add:

LICENSE_FLAGS_WHITELIST = "commercial"

CORE_IMAGE_EXTRA_INSTALL += " \

x264-bin \

x264-dev \

gst-plugins-ugly-meta \

"

Gstreammer Pipeline:

time gst-launch -e v4l2src device=/dev/video1 num-buffers=1000 ! 'video/x-raw-yuv, width=640, height=480, framerate=(fraction)30/1' ! ffmpegcolorspace ! x264enc profile=0  bitrate=1024 bframes=0 cabac=FALSE  speed-preset=ultrafast tune=zerolatency intra-refresh=1 sync-lookahead=0 ! avimux ! filesink location=teste.264.avi

This successfully generated a 4.2MB file with an acceptable video quality, framerate of encoding is around 10fps.

Regarding changing the camera frame rate, someone recommended me to change it on the linux driver level, as it looks the driver does not accept a different frame rate when it was initialized with 30 fps, but I have not tested this solution.

Rgds!

Bruno

0 Kudos

2,847 Views
tejasshah
Contributor III

I changed the framerate to 15 and even to 10, but still I get the same warnings and the "internal data flow error".

There is one more thing I want to mention.

I was trying to do capture a video with h264 encoding on ffmpeg and I was getting this error in it:

[   91.072720] ERROR: v4l2 capture: VIDIOC_REQBUFS: not enough buffers

[   91.087779] YUV420                                                          

Input #0, video4linux2,v4l2, from '/dev/video0':  


Now to solve this error, I made a change inside mxc_v4l2_capture.h file. Could that be a issue?

yocto/fsl-community-bsp/build/tmp/work/wandboard_dual-poky-linux-gnueabi/linux-wandboard/3.0.35-r1/git/drivers/media/video/mxc/capture/mxc_v4l2_capture.h

#define FRAME_NUM 10 to

#define FRAME_NUM 300

0 Kudos

2,847 Views
tejasshah
Contributor III

I am doing a current comparison of hardware h264 vs software h264 using csi camera.

This is for my thesis.

The warning turns into error due to slow encoding, but the real error is at the bottom.

I get this "internal data flow error". Is this also due to slow encoding:

ERROR: from element /GstPipeline:pipeline0/MFWGstV4LSrc:mfwgstv4lsrc0: Internal data flow error.

Additional debug info:

/home/tejas/yocto/fsl-community-bsp/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/gstreamer/0.10.36-r2/gstreamer-0.10.36/libs/gst/base/gstbasesrc.c(2625): gst_base_src_loop (): /GstPipeline:pipeline0/MFWGstV4LSrc:mfwgstv4lsrc0:

streaming task paused, reason error (-5)

0 Kudos

2,847 Views
LeonardoSandova
Specialist I

Tejas,

seems that the encoding part is taking too long, and somehow this triggers the error:

0:00:05.189429001  1603    0x7d630 ERROR             mfw_v4lsrc mfw_gst_v4lsrc.c

:1239:mfw_gst_v4lsrc_buffer_new: no buffer available in 1000 ms

1000ms delay is a lot for a source element! If you slow down the fps, do you observe the same problem? More general, let me try to the understand the general picture: what do you need SW encoding?

0 Kudos

2,845 Views
tejasshah
Contributor III

Hi Leo,

Can you please tell me on how can I solve this x264enc problem I am having.

0 Kudos

2,845 Views
tejasshah
Contributor III

It doesn't change anything. I get the same error. Here it is.

root@wandboard-dual:~# gst-launch mfw_v4lsrc ! 'video/x-raw-yuv,width=640,height=480,framerate=30/1,format=(fourcc)I420' ! queue max-size-buffers=2 ! x264enc ! mp4mux ! filesink location=gst-5sec-softwareenc.mp4

MFW_GST_V4LSRC_PLUGIN 3.0.10 build on Mar 20 2014 06:25:42.

Setting pipeline to PAUSED ...

Pipeline is live and does not need PREROLL ...

Setting pipeline to PLAYING ...

New clock: GstSystemClock

ERROR: from element /GstPipeline:pipeline0/MFWGstV4LSrc:mfwgstv4lsrc0: Internal data flow error.

Additional debug info:

/home/tejas/yocto/fsl-community-bsp/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/gstreamer/0.10.36-r2/gstreamer-0.10.36/libs/gst/base/gstbasesrc.c(2625): gst_base_src_loop (): /GstPipeline:pipeline0/MFWGstV4LSrc:mfwgstv4lsrc0:

streaming task paused, reason error (-5)

Execution ended after 1224964644 ns.

Setting pipeline to PAUSED ...

Setting pipeline to READY ...

Setting pipeline to NULL ...

Freeing pipeline ...

root@wandboard-dual:~# ^C

root@wandboard-dual:~#

0 Kudos

2,845 Views
LeonardoSandova
Specialist I

One last try:


gst-launch mfw_v4lsrc ! 'video/x-raw-yuv,width=640,height=480,framerate=30/1,format=(fourcc)I420' ! queue max-size-buffers=2 ! x264enc ! mp4mux ! filesink location=gst-5sec-softwareenc.mp4



the ipucsc is just needed in case there is no match between source and sink caps between peer elements, so I believe you do not need it. What you need is a capsfilter, and this is specified with 'video/...' string.



0 Kudos

2,844 Views
tejasshah
Contributor III

No, I didn't take out ipucsc element because I am using it for scaling my video and framerate.

I tried using videorate before, but with that video capture wasn't happening, therefore I used ipucsc element.

Here it is without the ipucsc element, and in this I haven't placed -v --gst-debug=2, because it gives the same warning and then this error below.

root@wandboard-dual:~# gst-launch mfw_v4lsrc ! queue max-size-buffers=2 ! x264enc ! mp4mux ! filesink location=gst-5sec-softwareenc.mp4

MFW_GST_V4LSRC_PLUGIN 3.0.10 build on Mar 20 2014 06:25:42.

Setting pipeline to PAUSED ...

Pipeline is live and does not need PREROLL ...

Setting pipeline to PLAYING ...

New clock: GstSystemClock

ERROR: from element /GstPipeline:pipeline0/MFWGstV4LSrc:mfwgstv4lsrc0: Internal data flow error.

Additional debug info:

/home/tejas/yocto/fsl-community-bsp/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/gstreamer/0.10.36-r2/gstreamer-0.10.36/libs/gst/base/gstbasesrc.c(2625): gst_base_src_loop (): /GstPipeline:pipeline0/MFWGstV4LSrc:mfwgstv4lsrc0:

streaming task paused, reason error (-5)

Execution ended after 1292847666 ns.

Setting pipeline to PAUSED ...

Setting pipeline to READY ...

Setting pipeline to NULL ...

Freeing pipeline ...

root@wandboard-dual:~#

0 Kudos

2,844 Views
LeonardoSandova
Specialist I

Even if you take out the ipucsc element?

0 Kudos

2,844 Views
tejasshah
Contributor III

I tried the command below and it is still the same error as I reported before.

gst-launch mfw_v4lsrc ! mfw_ipucsc ! 'video/x-raw-yuv,width=640,height=480,framerate=30/1,format=(fourcc)I420' ! queue max-size-buffers=2 ! x264enc ! mp4mux ! filesink location=gst-5sec-softwareenc.mp4

0 Kudos

2,844 Views
LeonardoSandova
Specialist I

Tejas,

max-size-buffers is the number of internal buffers on queue's pool that can be used and it is not related of the number of buffers you want to capture.

Leo

0 Kudos

2,844 Views
tejasshah
Contributor III

Hello Leo,

Are you saying to change it to following in my command to capture video using csi camera and video encoded through h264.

gst-launch mfw_v4lsrc ! mfw_ipucsc ! 'video/x-raw-yuv,width=640,height=480,framerate=30/1,format=(fourcc

)I420' ! queue max-size-buffers=2 ! x264enc ! mp4mux ! filesink location=gst-5sec-softwareenc.mp4

I need to capture segments of 5sec and each second will have 30 frames, and therefore I wrote num-buffers=150.

So if I make it to 2, how would it even capture anything? Could you please explain?

0 Kudos