ffmpeg H264 encoding with cedrus (Cedarx, Transcoding, Allwinner A20, Mediatomb)

Started by alcantor, July 20, 2014, 03:44:18 am

Previous topic - Next topic

sandmen

 Is there any how to, or did you have experience with /dev/disp ?
How can I be sure that hw-encoder is using?
Any experience with binary blob ?
Speed ...?
Did I need any special mem, for using cedar....
Loading modules is workin?


Quote from: alcantor on September 13, 2014, 06:32:44 pm
I use cubieez... Well i didn't try with HD video... But with SD video it is definitely quicker compare to libx264.

Did you compare with libx264?

Of course you could do optimisation! The scaler is software to convert to nv12, this could be done in hardware with /dev/disp.

sandmen

And, would be nice if you can test also the BigBunny video.
So we can compare.
Thanks

alcantor

The only experience I had with the scaler (/dev/disp), is in http://www.cubieforums.com/index.php/topic,2843.0.html, we had use it to convert from YUV420 to RGB888.

If you see "cedrus264" in the stream mapping, you're using the hardware encoder.


[VE SUNXI] VE version 0x1623 opened.
...
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (cedrus264))
Press [q] to stop, [?] for help
frame=  830 fps= 10 q=30.0 size=N/A time=00:00:34.58 bitrate=N/A


I've done a try with the binary blob: http://www.forum-cubieboard.de/Thread-avconv-h-264-hardware-encoding-mit-cubietruck-mediatomb-transcoding

I've created a rule in "/etc/udev/rules.d/80-cedar.rules" to load the modules automatically:
KERNEL=="disp", MODE="0666"
KERNEL=="cedar_dev", MODE="0666"


The big bunny test:

./ffmpeg -i /mnt/data/Film/Autre/big_buck_bunny_1080p_h264.mov -t 10 -an -pix_fmt nv12 -c:v cedrus264 -f null /dev/null

Run at about 15 fps with hardware (And use a lot of processor!).

./ffmpeg -i /mnt/data/Film/Autre/big_buck_bunny_1080p_h264.mov -t 10 -an -preset:v fast -c:v libx264 -f null /dev/null

Run at about 0.8 fps with software.

So hardware encoding is about 20x much faster....

jbrnd

Quote from: alcantor on September 10, 2014, 03:19:27 pm
But you need to clone the sunxi-cedrus branch.


Ahh, got it. Thank you! With that, I was able to transcode 1920x1080 MPEG2 to H264 at about 7 frames/sec. Do you know if deinterlacing can also be done in hardware? With software deinterlacing (-vf yadif) , throughput drops to one frame per second.


arrhenius

Hi:

im very interested in this.

i want to transcode an mpeg2 stream (4000kb/s) to mpeg4 stream (constant 1000Kb/s) (i want to stream over internet)

im trying with ffmpeg and i get just 8-10fps.


im trying know to compile your code but im noob and i m getting ton of problems.


1. i did the git clone you gave
2. i tried to configure
3. i resolved every problem that configure told me installing the proper packages with apt-get
4. i couldnt resolve the faac issue, there is no libfaac package in wheezy?



i tried this too :

1. download the ffmpeg binary
2. exeute the binary -> i get an error
./ffmpeg: /lib/arm-linux-gnueabihf/libc.so.6: version `GLIBC_2.17' not found (required by ./ffmpeg)


my system : debian wheezy with kernel 3.4.75-sun7i


Any help?



EDIT: i just removed the enable faac and get this complied.

i tried the command and i can encode now 40fps, but the bitrate is very higth, i changed de qp value and get smoller file but the quality sucks a lot..


how can i get lower bitrate with decent quality?

thanks

alcantor

Quotei tried the command and i can encode now 40fps, but the bitrate is very higth, i changed de qp value and get smoller file but the quality sucks a lot..

how can i get lower bitrate with decent quality?


1. Try different value of qp.
2. Check if the audio stream is in the corrected format, if anyone (try -an to remove it).
3. Implement P-Frame (The open source version does not yet implementation the P and B Frame)

It would be nice to have P-Frame, but for that I need help too, that's also why i'have start this thread.

arrhenius

Quote from: alcantor on November 06, 2014, 09:22:04 am
Quotei tried the command and i can encode now 40fps, but the bitrate is very higth, i changed de qp value and get smoller file but the quality sucks a lot..

how can i get lower bitrate with decent quality?


1. Try different value of qp.
2. Check if the audio stream is in the corrected format, if anyone (try -an to remove it).
3. Implement P-Frame (The open source version does not yet implementation the P and B Frame)

It would be nice to have P-Frame, but for that I need help too, that's also why i'have start this thread.


thanks for the tips, but it doesnt help.

i tried no audio and get same results, my stream is 3000kb/s and gp 30 generates 7000kbs, if a want to smaller file i use gp40 and the quality is awful.


i read about p-frames and it looks like they are essential to get smaller files.. but looks very difficult to me to implement that.


im computer programmer but im not used to this kind of job .

wickwire

Quote from: alcantor on July 20, 2014, 03:44:18 am
Hello Everyone,

Based on https://github.com/jemk/cedrus/tree/master/h264enc, I have made a version of ffmpeg with that included.

I also tried with the proprietary cedarx library, but it need SUNXI_MEM in Kernel, which is less convenience and it was also complicated to have a proper implementation (Only bitrate constant?).

This open source version only support I Frame and constant quality with QP between 2 and 47.

To use it:

sudo modprobe sunxi_cedar_mod
./ffmpeg -y -i src.avi -filter:v pad="trunc((iw+31)/32)*32:trunc((ih+31)/32)*32" -pix_fmt nv12 -qp 20 -vewait 3600 -c:v cedrus264 -c:a copy -f avi dst.avi


The parameter vewait is only useful, when you're starting multiple instance of ffmpeg at the same time.

I have done this to use transcoding feature of mediatomb on my CT. I will put some details on my mediatomb configuration, but I am not done yet.

Would it be complicated to implement P-Frame?
Should I put this on Git? I never used Git except to clone source.
HW Decoding should be possible with vdpau-sunxi, but i not tried yet (and it will probably collide with the HW Encoder).

https://www.dropbox.com/s/zarytvsgch4jclr/FFmpeg-2014.08.23.tar.xz?dl=0
https://github.com/Alcantor/FFmpeg/tree/sunxi-cedrus

The binaries are compile with libx264 libmp3lame libfaac x11grab libpulse libv4l2, so you probably need the appropriate libraries. But it can be useful to encode from camera, or to try streaming Desktop http://realmike.org/blog/2011/02/09/live-desktop-streaming-via-dlna-on-gnulinux/comment-page-1/ ;)

Bye bye


Hi, nice work! I found your post while browsing for cedarx video encoding on cubieboard. I followed your guide and set up 2 cubieboards, an A10 and an A20, both with webcams connected and ran some tests:


Cubieboard 2 (A20)
./ffmpeg -f v4l2 -s 510x400 -i /dev/video0 -filter:v 'pad=trunc((iw+31)/32)*32' -pix_fmt nv12 -qp 20 -r 30 -c:v cedrus264 -an -f mpegts udp://192.168.55.100:1234
45% PID CPU, bitrate=5166.6kbits, 30fps

./ffmpeg -f v4l2 -s 510x400 -i /dev/video0 -filter:v 'pad=trunc((iw+31)/32)*32' -pix_fmt nv12 -qp 2 -r 30 -c:v cedrus264 -an -f mpegts udp://192.168.55.100:1234
50% PID CPU, bitrate=14882.9kbits, 30fps



Cubieboard 1 (A10)

./ffmpeg -f v4l2 -s 510x400 -i /dev/video0 -filter:v 'pad=trunc((iw+31)/32)*32' -pix_fmt nv12 -qp 20 -r 30 -c:v cedrus264 -an -f mpegts udp://192.168.55.100:1234
53% PID CPU, bitrate=5297.6kbits, 30fps

./ffmpeg -f v4l2 -s 460x380 -i /dev/video0 -filter:v 'pad=trunc((iw+31)/32)*32' -pix_fmt nv12 -qp 2 -r 30 -c:v cedrus264 -an -f mpegts udp://192.168.55.100:1234
60% PID CPUI, bitrate=16797.8kbits, 30fps


What I noticed is that although the webcams support up to 1280x720 resolutions, anything beyond 510x400 (A20) / 460x380 (A10) makes ffmpeg freeze.

If I stay within those resolutions, it's ok to lower the qp parameter and go for a better quality output, at the expense of CPU (slightly) and bandwidth (considerably).
with a qp of 2, I get really high bitrate and the LAN client on my PC manages to play the stream but with stutters, although ffmpeg doesn't freeze on cubie.

Has anyone else using webcams been able to go for 640x480 or above? Are there any parameters I should adjust on my ffmpeg command lines to achieve this?

Thanks in advance!

rkthebest

hi alcantor,

is it possible to cross compile your source?
as i am using custom image made by buildroot and i cannot compile on CB2.

kindly suggest.

rkthebest

hey,

i was able to cross compile it and works well and stream over UDP stream but i wasnt able to get the sound.
using cedrus encoder.

stulluk

Firstly, thank you very much for this extremely useful work.

I managed to have an RTSP server, with FFMPEG hardware encoding by using HI253, Logitech c510 webcam and OV5640 camera modules.

Did anybody manage to have a resolution above 640x480 ?

I am also getting extremely high bitrate when encoding with cedrus. Even I use 640x480@25fps, with qp=30, I still get over 1.5Mbps...

My kernel version is 3.4.79+

My command to do this:

ffmpeg -f v4l2 -video_size 640x480 -i /dev/video0 -pix_fmt nv12 -r 25 -maxrate 1000k -b:v 500k -c:v cedrus264 -f mpegts - | cvlc - --sout "#:rtp{sdp=rtsp://:8554/}"

This results:


root@i3-55ad ~ # ffmpeg -f video4linux2 -i /dev/video0 -s 640x480 -r 30 -an -g 1 -pix_fmt nv12 -vcodec cedrus264 -qp 30  -f rtp rtp://192.168.2.115:5000
ffmpeg version N-65839-g156858b Copyright (c) 2000-2014 the FFmpeg developers
  built on Dec 29 2014 16:17:06 with gcc 4.6 (Debian 4.6.3-14)
  configuration: --prefix=/usr --enable-nonfree --enable-gpl --enable-version3 --enable-vdpau --enable-libx264 --enable-libmp3lame --enable-libpulse --enable-libv4l2 --enable-libtheora --enable-libvorbis --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc
  libavutil      54.  6.100 / 54.  6.100
  libavcodec     56.  0.101 / 56.  0.101
  libavformat    56.  2.100 / 56.  2.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.102 /  5.  0.102
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
<6>[CSI][OV5640]disalbe oe!
<6>[CSI]sensor initial success when csi open!
<6>[CSI_ERR]buffer count is invalid, set to 5
<6>[CSI]buffer_setup, buffer count=5, size=460800
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 1420211085.007539, bitrate: 110592 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 110592 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
[VE SUNXI] VE version 0x1623 opened.
Output #0, rtp, to 'rtp://192.168.2.115:5000':
  Metadata:
    encoder         : Lavf56.2.100
    Stream #0:0: Video: h264 (cedrus264), nv12, 640x480, q=2-31, 200 kb/s, 30 fps, 90k tbn, 30 tbc
    Metadata:
      encoder         : Lavc56.0.101 cedrus264
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (cedrus264))
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.2.115
t=0 0
a=tool:libavformat 56.2.100
m=video 5000 RTP/AVP 96
b=AS:200
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1

Press [q] to stop, [?] for help
frame= 1314 fps= 30 q=30.0 Lsize=   26066kB time=00:00:43.80 bitrate=4875.3kbits/s dup=656 drop=0
video:25807kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.003997%
<6>[CSI][OV5640]disalbe oe!
^C
root@i3-55ad ~ #


As you see, the bitrate is extremely high.. Did anybody experience this?

pseudoruprecht

Thanks alcantor!

I'm using this on my Cubietruck with Cubieez. So far so good. Anything I could test?

biomecanoid

Hello,

I realize that this is an old topic, but this is one of the most relevant i could find.

I have installed mediatomb and it works far better than the miniDLNA i had before.

Whenever i triy to playback movies with DTS on my Thomson UHD TV i get and error message "audio is not supported".

Can anyone help me transcode only the audio part on the MKV from DTS to AC3 ? the video is playing OK but Thomson obviously doesn't support DTS audio.


i just tried this script:

#!/bin/bash

FFMPEG_PATH="/usr/bin/ffmpeg"
INPUT="$1"
OUTPUT="$2"
VIDEO_CODEC="mpeg2video"
VIDEO_BITRATE="4096k"
VIDEO_FRAMERATE="25"
AUDIO_CODEC="mp2"
AUDIO_BITRATE="192k"
AUDIO_SAMPLERATE="44100"
AUDIO_CHANNELS="2"
FORMAT="dvd"

exec "${FFMPEG_PATH}" -i "${INPUT}" -vcodec ${VIDEO_CODEC} -b ${VIDEO_BITRATE} \
-r ${VIDEO_FRAMERATE} -acodec ${AUDIO_CODEC} -ab ${AUDIO_BITRATE} -ar ${AUDIO_SAMPLERATE} \
-ac ${AUDIO_CHANNELS} -f ${FORMAT} - > "${OUTPUT}"

And it works fine just my NAS is too slow for the task.
Another drawback of the script is that is transcodes all MKV files regardless if they have DTS audio or not.

My TV can playback the video but not the DTS audio. So i want a script that will leave the video as it is and transcode only the DTS audio to AC3.

Then i think the NAS will be able to cope with the load since it will transcode only the audio and not the video as well.

Any ideas ?


Thanks