Project

General

Profile

TVHeadend Raspberry Pi and Transcoding

Added by lord slash about 10 years ago

Hi guys, I've setup a TVHeadend back end with my raspberry pi and raspbian, where I stream the italian tv to my home in Germany. The system works perfectly during the day, but in the evening the DSL bandwidth is not enough (I need around 4000kbps and I have 3000kbps).

Therefore I would like to try the TVHeadend transcoding option. According to this: https://tvheadend.org/boards/4/topics/13635?r=13637 I should compile after enabling the transcoding in the configuration file src/plumbing/transcoding.c The problem is that in this file there is no uint32_t transcoding_enabled at all. I tried a ./configure --enable-libffmpeg_static and then make and make install, but in the TVHeadend transcoding option is not there :(

What happened to the uint32_t transcoding_enabled ?? How should I compile in order to get transcoding work on my pi? By the way, I have TVHeadend 3.9.1879. Thanks in advance for the help!


Replies (160)

RE: TVHeadend Raspberry Pi and Transcoding - Added by Alexander Meinke almost 8 years ago

EDIT: The table has three columns separated by space.

Here is the output of ffmpeg-3.2 configure script for:
--list-decoders:
aac atrac1 escape130
aac_at atrac3 evrc
aac_fixed atrac3p exr
aac_latm aura ffv1
aasc aura2 ffvhuff
ac3 avrn ffwavesynth
ac3_at avrp fic
ac3_fixed avs flac
adpcm_4xm avui flashsv
adpcm_adx ayuv flashsv2
adpcm_afc bethsoftvid flic
adpcm_aica bfi flv
adpcm_ct bink fourxm
adpcm_dtk binkaudio_dct fraps
adpcm_ea binkaudio_rdft frwu
adpcm_ea_maxis_xa bintext g2m
adpcm_ea_r1 bmp g723_1
adpcm_ea_r2 bmv_audio g729
adpcm_ea_r3 bmv_video gif
adpcm_ea_xas brender_pix gsm
adpcm_g722 c93 gsm_ms
adpcm_g726 cavs gsm_ms_at
adpcm_g726le ccaption h261
adpcm_ima_amv cdgraphics h263
adpcm_ima_apc cdxl h263_cuvid
adpcm_ima_dat4 cfhd h263i
adpcm_ima_dk3 cinepak h263p
adpcm_ima_dk4 cljr h264
adpcm_ima_ea_eacs cllc h264_crystalhd
adpcm_ima_ea_sead comfortnoise h264_cuvid
adpcm_ima_iss cook h264_mediacodec
adpcm_ima_oki cpia h264_mmal
adpcm_ima_qt cscd h264_qsv
adpcm_ima_qt_at cyuv h264_vda
adpcm_ima_rad dca h264_vdpau
adpcm_ima_smjpeg dds hap
adpcm_ima_wav dfa hevc
adpcm_ima_ws dirac hevc_cuvid
adpcm_ms dnxhd hevc_mediacodec
adpcm_mtaf dpx hevc_qsv
adpcm_psx dsd_lsbf hnm4_video
adpcm_sbpro_2 dsd_lsbf_planar hq_hqa
adpcm_sbpro_3 dsd_msbf hqx
adpcm_sbpro_4 dsd_msbf_planar huffyuv
adpcm_swf dsicinaudio iac
adpcm_thp dsicinvideo idcin
adpcm_thp_le dss_sp idf
adpcm_vima dst iff_ilbm
adpcm_xa dvaudio ilbc_at
adpcm_yamaha dvbsub imc
aic dvdsub indeo2
alac dvvideo indeo3
alac_at dxa indeo4
alias_pix dxtory indeo5
als dxv interplay_acm
amr_nb_at eac3 interplay_dpcm
amrnb eac3_at interplay_video
amrwb eacmv jacosub
amv eamad jpeg2000
anm eatgq jpegls
ansi eatgv jv
ape eatqi kgv1
apng eightbps kmvc
ass eightsvx_exp lagarith
asv1 eightsvx_fib libcelt
asv2 escape124 libfdk_aac
libgsm msmpeg4v2 qdm2_at
libgsm_ms msmpeg4v3 qdmc_at
libilbc msrle qdraw
libopencore_amrnb mss1 qpeg
libopencore_amrwb mss2 qtrle
libopenh264 msvideo1 r10k
libopenjpeg mszh r210
libopus mts2 ra_144
libschroedinger mvc1 ra_288
libspeex mvc2 ralf
libvorbis mxpeg rawvideo
libvpx_vp8 nellymoser realtext
libvpx_vp9 nuv rl2
libzvbi_teletext on2avc roq
loco opus roq_dpcm
m101 paf_audio rpza
mace3 paf_video rscc
mace6 pam rv10
magicyuv pbm rv20
mdec pcm_alaw rv30
metasound pcm_alaw_at rv40
microdvd pcm_bluray s302m
mimic pcm_dvd sami
mjpeg pcm_f32be sanm
mjpeg_cuvid pcm_f32le screenpresso
mjpegb pcm_f64be sdx2_dpcm
mlp pcm_f64le sgi
mmvideo pcm_lxf sgirle
motionpixels pcm_mulaw sheervideo
movtext pcm_mulaw_at shorten
mp1 pcm_s16be sipr
mp1_at pcm_s16be_planar smackaud
mp1float pcm_s16le smacker
mp2 pcm_s16le_planar smc
mp2_at pcm_s24be smvjpeg
mp2float pcm_s24daud snow
mp3 pcm_s24le sol_dpcm
mp3_at pcm_s24le_planar sonic
mp3adu pcm_s32be sp5x
mp3adufloat pcm_s32le srt
mp3float pcm_s32le_planar ssa
mp3on4 pcm_s64be stl
mp3on4float pcm_s64le subrip
mpc7 pcm_s8 subviewer
mpc8 pcm_s8_planar subviewer1
mpeg1_cuvid pcm_u16be sunrast
mpeg1_vdpau pcm_u16le svq1
mpeg1video pcm_u24be svq3
mpeg2_crystalhd pcm_u24le tak
mpeg2_cuvid pcm_u32be targa
mpeg2_mmal pcm_u32le targa_y216
mpeg2_qsv pcm_u8 tdsc
mpeg2video pcm_zork text
mpeg4 pcx theora
mpeg4_crystalhd pgm thp
mpeg4_cuvid pgmyuv tiertexseqvideo
mpeg4_mediacodec pgssub tiff
mpeg4_mmal pictor tmv
mpeg4_vdpau pjs truehd
mpeg_vdpau png truemotion1
mpeg_xvmc ppm truemotion2
mpegvideo prores truemotion2rt
mpl2 prores_lgpl truespeech
msa1 ptx tscc
msmpeg4_crystalhd qcelp tscc2
msmpeg4v1 qdm2 tta
twinvq vp5 wmv3_crystalhd
txd vp6 wmv3_vdpau
ulti vp6a wmv3image
utvideo vp6f wnv1
v210 vp7 ws_snd1
v210x vp8 xan_dpcm
v308 vp8_cuvid xan_wc3
v408 vp8_mediacodec xan_wc4
v410 vp9 xbin
vb vp9_cuvid xbm
vble vp9_mediacodec xface
vc1 vplayer xl
vc1_crystalhd vqa xma1
vc1_cuvid wavpack xma2
vc1_mmal webp xsub
vc1_qsv webvtt xwd
vc1_vdpau wmalossless y41p
vc1image wmapro ylc
vcr1 wmav1 yop
vmdaudio wmav2 yuv4
vmdvideo wmavoice zero12v
vmnc wmv1 zerocodec
vorbis wmv2 zlib
vp3 wmv3 zmbv

--list-encoders:
a64multi libkvazaar pcm_s64le
a64multi5 libmp3lame pcm_s8
aac libopencore_amrnb pcm_s8_planar
aac_at libopenh264 pcm_u16be
ac3 libopenjpeg pcm_u16le
ac3_fixed libopus pcm_u24be
adpcm_adx libschroedinger pcm_u24le
adpcm_g722 libshine pcm_u32be
adpcm_g726 libspeex pcm_u32le
adpcm_ima_qt libtheora pcm_u8
adpcm_ima_wav libtwolame pcx
adpcm_ms libvo_amrwbenc pgm
adpcm_swf libvorbis pgmyuv
adpcm_yamaha libvpx_vp8 png
alac libvpx_vp9 ppm
alac_at libwavpack prores
alias_pix libwebp prores_aw
amv libwebp_anim prores_ks
apng libx262 qtrle
ass libx264 r10k
asv1 libx264rgb r210
asv2 libx265 ra_144
avrp libxavs rawvideo
avui libxvid roq
ayuv ljpeg roq_dpcm
bmp mjpeg rv10
cinepak mjpeg_vaapi rv20
cljr mlp s302m
comfortnoise movtext sgi
dca mp2 snow
dnxhd mp2fixed sonic
dpx mpeg1video sonic_ls
dvbsub mpeg2_qsv srt
dvdsub mpeg2video ssa
dvvideo mpeg4 subrip
eac3 msmpeg4v2 sunrast
ffv1 msmpeg4v3 svq1
ffvhuff msvideo1 targa
flac nellymoser text
flashsv nvenc tiff
flashsv2 nvenc_h264 truehd
flv nvenc_hevc tta
g723_1 pam utvideo
gif pbm v210
h261 pcm_alaw v308
h263 pcm_alaw_at v408
h263p pcm_f32be v410
h264_nvenc pcm_f32le vc2
h264_omx pcm_f64be vorbis
h264_qsv pcm_f64le wavpack
h264_vaapi pcm_mulaw webvtt
h264_videotoolbox pcm_mulaw_at wmav1
hap pcm_s16be wmav2
hevc_nvenc pcm_s16be_planar wmv1
hevc_qsv pcm_s16le wmv2
hevc_vaapi pcm_s16le_planar wrapped_avframe
huffyuv pcm_s24be xbm
ilbc_at pcm_s24daud xface
jpeg2000 pcm_s24le xsub
jpegls pcm_s24le_planar xwd
libfdk_aac pcm_s32be y41p
libgsm pcm_s32le yuv4
libgsm_ms pcm_s32le_planar zlib
libilbc pcm_s64be zmbv

--list-hwaccels:
h263_cuvid hevc_vdpau mpeg4_videotoolbox
h263_vaapi mjpeg_cuvid vc1_cuvid
h263_videotoolbox mpeg1_cuvid vc1_d3d11va
h264_cuvid mpeg1_vdpau vc1_dxva2
h264_d3d11va mpeg1_videotoolbox vc1_mmal
h264_dxva2 mpeg1_xvmc vc1_qsv
h264_mediacodec mpeg2_cuvid vc1_vaapi
h264_mmal mpeg2_d3d11va vc1_vdpau
h264_qsv mpeg2_dxva2 vp8_cuvid
h264_vaapi mpeg2_mmal vp8_mediacodec
h264_vda mpeg2_qsv vp9_cuvid
h264_vda_old mpeg2_vaapi vp9_d3d11va
h264_vdpau mpeg2_vdpau vp9_dxva2
h264_videotoolbox mpeg2_videotoolbox vp9_mediacodec
hevc_cuvid mpeg2_xvmc vp9_vaapi
hevc_d3d11va mpeg4_cuvid wmv3_d3d11va
hevc_dxva2 mpeg4_mediacodec wmv3_dxva2
hevc_mediacodec mpeg4_mmal wmv3_vaapi
hevc_qsv mpeg4_vaapi wmv3_vdpau
hevc_vaapi mpeg4_vdpau

At the moment I cannot get the list of built ffmpeg. Looks like the programs are not built by tvheadend as was with external ffmpeg on archlinux.

RE: TVHeadend Raspberry Pi and Transcoding - Added by Alexander Meinke almost 8 years ago

That's the log output why I disabled the high profile:

...
2017-01-03 17:13:45.133 libav: Undefined constant or missing '(' in 'high'
2017-01-03 17:13:45.133 libav: Unable to parse option value "high"
2017-01-03 17:13:45.133 libav: Error setting option profile to value high.
2017-01-03 17:13:45.133 transcode: 0004: Unable to open h264_omx encoder
...

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Look at this:

--list-decoders:
.............
h264_mmal
mpeg2_mmal
.............

I suspect this could be the problem. Do you have time for a test?
Assuming that you have a good h264_omx tvheadend setup, go in

src/plumbing/transcoding.c

and change this code

/** *
*/
static AVCodec *
transcoder_get_decoder(transcoder_t *t, streaming_component_type_t ty) {
enum AVCodecID codec_id;
AVCodec *codec;

/* the MP4A and AAC packet format is same, reduce to one type */
if (ty == SCT_MP4A)
ty = SCT_AAC;
codec_id = streaming_component_type2codec_id(ty);
if (codec_id == AV_CODEC_ID_NONE) {
tvherror(LS_TRANSCODE, "%04X: Unsupported input codec %s",
shortid(t), streaming_component_type2txt(ty));
return NULL;
}
codec = avcodec_find_decoder(codec_id);
if (!codec) {
tvherror(LS_TRANSCODE, "%04X: Unable to find %s decoder",
shortid(t), streaming_component_type2txt(ty));
return NULL;
}
tvhtrace(LS_TRANSCODE, "%04X: Using decoder %s", shortid(t), codec->name);
return codec;
}

to

/** *
*/
static AVCodec *
transcoder_get_decoder(transcoder_t *t, streaming_component_type_t ty) {
enum AVCodecID codec_id;
AVCodec *codec;

/* the MP4A and AAC packet format is same, reduce to one type */
if (ty == SCT_MP4A)
ty = SCT_AAC;
codec_id = streaming_component_type2codec_id(ty);
if (codec_id == AV_CODEC_ID_NONE) {
tvherror(LS_TRANSCODE, "%04X: Unsupported input codec %s",
shortid(t), streaming_component_type2txt(ty));
return NULL;
}
codec = avcodec_find_decoder_by_name("mpeg2_mmal"); // (or "h264_mmal")
if (!codec) {
tvherror(LS_TRANSCODE, "%04X: Unable to find %s decoder",
shortid(t), streaming_component_type2txt(ty));
return NULL;
}
tvhtrace(LS_TRANSCODE, "%04X: Using decoder %s", shortid(t), codec->name);
return codec;
}

the codec depends on the source you are going to transcode. It's a quick and dirty test. please consider also that if you want to transcode mpeg2, you need the license, otherwise the hardware deconding will not work
Bye

RE: TVHeadend Raspberry Pi and Transcoding - Added by Alexander Meinke almost 8 years ago

Sorry, I'am on holidays and do not have dvb-t here. I could test it in two to three days. Hope you can wait. Maybe Morten can test it earlier as he is ready for test :).

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

No problem.
My Rpi3 should arrive tomorrow, in a couple of days I should be ready also.
Bye

RE: TVHeadend Raspberry Pi and Transcoding - Added by Morten Gade Sørensen almost 8 years ago

I tried compiling with your suggestion:

codec = avcodec_find_decoder_by_name("h264_mmal");

But get the following errors in the log when tuning in to a channel using the stream profile:

libav: Did not get output frame from MMAL.
transcode: 0002: Unable to decode video (-1313558101, Unknown error occurred)
libav: MMAL error 2 on control port
libav: MMAL error 2 on control port
libav: MMAL error 2 on control port
libav: MMAL error 2 on control port
libav: MMAL error 2 on control port

RE: TVHeadend Raspberry Pi and Transcoding - Added by Morten Gade Sørensen almost 8 years ago

I reverted the change and recompiled. I can tune in to the channel, but the video stutters (I'm unsure if the encoder obeys the requested bitrate).
FWIW here's the output of the log:

subscription: 0007: "HTTP" subscribing on channel "Test Channel", weight: 100, adapter: "Silicon Labs Si2168 : DVB-C #0", network: "Provider", mux: "594MHz", provider: "Provider", service: "Test Channel", profile="webtv-h264_omx-aac-mpegts", hostname="127.0.0.1", username="tvh", client="VLC/2.2.4 LibVLC/2.2.4" 
transcode: 0002: 1:H264 1280x720 ==> H264 1280x720 (h264_omx)
transcode: 0002: 2:MPEG2AUDIO ==> Passthrough
transcode: 0002: 3:TELETEXT ==> Filtered
transcode: 0002: 4:AC3 ==> Passthrough
libav: mmco: unref short failure
transcode: 0002: Using preset hq
libav: Using OMX.broadcom.video_encode
libav: mmco: unref short failure
libav: Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
libav: Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
libav: Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
mpegts: too much queued input data (over 50MB), discarding new
mpegts: too much queued input data (over 50MB), discarding new
mpegts: too much queued input data (over 50MB), discarding new
webui: Stop streaming /stream/channel/4352b93d1a73a72eacb6354b3ef4d7c7?ticket=1659F49F1B2E55E6F9FA7491E57D2ABA69ACECBF, muxer reported errors
subscription: 0007: "HTTP" unsubscribing from "Test Channel", hostname="127.0.0.1", username="tvh", client="VLC/2.2.4 LibVLC/2.2.4" 

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Hi
I have received the Rpi3 and built the tvheadend
However I'm still having a problem with finding the h264_omx profile in the guy
I have compiled with:

./configure --disable-libx264 --disable-libx265 --disable-libx265_static --disable-libvpx --prefix=/usr --disable-libvpx_static --disable-bintray_cache --enable-hdhomerun_client --enable-ffmpeg --enable-ffmpeg_static

Now I corretly see that libx264 and libx265 are not available, but there is no h264_omx profile
But now I have a question: are you compiling the MASTER branch or the "codecs" branch?

RE: TVHeadend Raspberry Pi and Transcoding - Added by Joseph ZACHARIE almost 8 years ago

Hi,

install libomxil-bellagio-dev (Package)
install MMAL : https://github.com/raspberrypi/userland (to compile)
and follow this instruction :
https://tvheadend.org/boards/5/topics/13892?r=24251#message-24251

Regards

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

I did it except for:

install MMAL : https://github.com/raspberrypi/userland (to compile)

Shouldn't userland already be part of raspian? ffmpeg didn't complained about missing mmal

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

The HW seems to be ok. I have built a custom ffmpeg and tried an encoding:

pi@raspberrypi:~ $ ffmpeg -i dolbyaurora.vob -c:a copy -c:v h264_omx -b:v 128k test.mp4
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/usr --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx --enable-libx264 --enable-libx265 --enable-nonfree --enable-gpl
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mpeg, from 'dolbyaurora.vob':
  Duration: 00:00:34.98, start: 0.049756, bitrate: 5296 kb/s
    Stream #0:0[0x1bf]: Data: dvd_nav_packet
    Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:2[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
[h264_omx @ 0x2e032d0] Using OMX.broadcom.video_encode
[mp4 @ 0x2e020e0] track 1: codec frame size is not set
Output #0, mp4, to 'test.mp4':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (h264_omx) ([33][0][0][0] / 0x0021), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, 128 kb/s, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 h264_omx
    Stream #0:1: Audio: ac3 ([165][0][0][0] / 0x00A5), 48000 Hz, 5.1(side), 384 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg2video (native) -> h264 (h264_omx))
  Stream #0:2 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=   56 fps=0.0 q=-0.0 size=     127kB time=00:00:02.20 bitrate= 473.0kbits/
frame=  110 fps=110 q=-0.0 size=     273kB time=00:00:04.38 bitrate= 510.2kbits/
frame=  163 fps=108 q=-0.0 size=     406kB time=00:00:06.49 bitrate= 512.1kbits/
frame=  214 fps=106 q=-0.0 size=     530kB time=00:00:08.54 bitrate= 508.5kbits/
frame=  265 fps=105 q=-0.0 size=     658kB time=00:00:10.56 bitrate= 510.6kbits/
frame=  316 fps=105 q=-0.0 size=     788kB time=00:00:12.60 bitrate= 512.0kbits/
frame=  366 fps=104 q=-0.0 size=     914kB time=00:00:14.62 bitrate= 511.9kbits/
frame=  416 fps=103 q=-0.0 size=    1038kB time=00:00:16.60 bitrate= 512.2kbits/
frame=  467 fps=103 q=-0.0 size=    1165kB time=00:00:18.62 bitrate= 512.3kbits/
frame=  515 fps=102 q=-0.0 size=    1285kB time=00:00:20.54 bitrate= 512.6kbits/
frame=  565 fps=102 q=-0.0 size=    1411kB time=00:00:22.56 bitrate= 512.5kbits/
frame=  615 fps=102 q=-0.0 size=    1534kB time=00:00:24.57 bitrate= 511.5kbits/
frame=  667 fps=102 q=-0.0 size=    1664kB time=00:00:26.62 bitrate= 511.9kbits/
frame=  716 fps=101 q=-0.0 size=    1789kB time=00:00:28.60 bitrate= 512.2kbits/
frame=  767 fps=101 q=-0.0 size=    1916kB time=00:00:30.62 bitrate= 512.5kbits/
frame=  818 fps=101 q=-0.0 size=    2042kB time=00:00:32.70 bitrate= 511.5kbits/
frame=  872 fps=102 q=-0.0 size=    2176kB time=00:00:34.81 bitrate= 511.9kbits/
frame=  875 fps=102 q=-0.0 Lsize=    2203kB time=00:00:34.96 bitrate= 516.2kbits/

s speed=4.06x    
video:547kB audio:1640kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.768599%

HW accelerations is picked up and the speed is very good. the only thing is puzzling me is this:

pi@raspberrypi:~/ffmpeg-3.2.2 $ ffmpeg -hwaccels
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/usr --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx --enable-libx264 --enable-libx265 --enable-nonfree --enable-gpl
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Hardware acceleration methods:

Apparently hwaccels list is empty. Could be this causing the problem?

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

from tvheadend log

2017-01-09 19:04:49.490 [   INFO]:subscription: 007A: "192.168.182.243 [ menion
| Kodi Media Center ]" subscribing on channel "Rete4", weight: 100, adapter: "Sk
y IT Digital Key (green led) : DVB-T #0", network: "DVB-T Network", mux: "698MHz
", provider: "Mediaset", service: "Rete4", profile="omx", hostname="192.168.182.
243", username="menion", client="Kodi Media Center" 
2017-01-09 19:04:50.367 [  TRACE]:transcode: 0001: transcoder_calc_stream_count=
2 (video=1, audio=1, subtitle=0)
2017-01-09 19:04:50.367 [   INFO]:transcode: 0001: 2:TELETEXT ==> Filtered
2017-01-09 19:04:50.367 [  TRACE]:transcode: 0001: Using decoder mpeg2video
2017-01-09 19:04:50.367 [  ERROR]:transcode: 0001: Unable to find h264_omx encod
er
2017-01-09 19:04:50.367 [   INFO]:transcode: 0001: 3:MPEG2VIDEO ==> Passthrough
2017-01-09 19:04:50.367 [  TRACE]:transcode: 0001: Using decoder mp2

I have forced h264_omx in the stream. The string is passed correclty, but for some reason the libavcodec doesn' support it.
I don't understand

RE: TVHeadend Raspberry Pi and Transcoding - Added by Alexander Meinke almost 8 years ago

Hello Antonio,

I do the following to get h264_omx in tvheadend's stream profile tab:

1. git clone <tvheadend>
2. apply the following patches:

diff --git a/Makefile.ffmpeg b/Makefile.ffmpeg
index aa36eae..66ad3ba 100644
--- a/Makefile.ffmpeg
+++ b/Makefile.ffmpeg
@@ -581,7 +581,13 @@ $(LIB_ROOT)/$(FFMPEG)/.tvh_build: \
         $(foreach encoder,$(ENCODERS),--enable-encoder=$(encoder)) \
         $(foreach muxer,$(MUXERS),--enable-muxer=$(muxer)) \
         $(foreach bsf,$(BSFS),--enable-bsf=$(bsf)) \
-        $(foreach filter,$(FILTERS),--enable-filter=$(filter))
+        $(foreach filter,$(FILTERS),--enable-filter=$(filter)) \
+        --enable-nonfree \
+        --enable-mmal \
+        --enable-omx \
+        --enable-omx-rpi \
+        --enable-decoder=h264_mmal \
+        --enable-encoder=h264_omx
     DESTDIR=$(EBUILDIR) \
         $(MAKE) -C $(LIB_ROOT)/$(FFMPEG) install
     @touch $@

diff --git a/src/plumbing/transcoding.c b/src/plumbing/transcoding.c
index 1f2427b..4281b3b 100644
--- a/src/plumbing/transcoding.c
+++ b/src/plumbing/transcoding.c
@@ -1348,7 +1348,7 @@ transcoder_stream_video(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt)
       tvhinfo(LS_TRANSCODE, "%04X: Using preset %s", shortid(t), t->t_props.tp_vcodec_preset);

       // All modern devices should support "high" profile
-      av_dict_set(&opts, "profile", "high", 0);
+      //av_dict_set(&opts, "profile", "high", 0);

       if (t->t_props.tp_vbitrate < 64) {
         // encode with specified quality and optimize for low latency

3. Add Autobuild/jessie-armhf.sh with the following content:

AUTOBUILD_CONFIGURE_EXTRA="${AUTOBUILD_CONFIGURE_EXTRA:-} --arch=armhf --disable-libx265_static --disable-libx265 --disable-libvpx_static --disable-libvpx --disable-bintray_cache" 
DEBDIST=jessie
source Autobuild/debian.sh

4. Execute ./Autobuild.sh -t jessie-armhf from source repository
5. dpkg -i <tvheadend>.deb (The package will be placed outside the source repository)

Don't forget - as you already mentioned - to do distclean so ffmpeg will be rebuild.

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

ahhhh ok
I think I have put the ffmpeg switch in the wrong position (global ffmpeg configure options)
I will check this
Bye

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Ok
I have compiled tvheadend to use my self-built shared ffmpeg, I thinks it's way better to have full control of the ffmpeg/libavcodec capabilities
Now I get the h264_omx and I can reproduce the Joseph issue, CPU still overkilled
Looking at the logs I see

2017-01-09 20:34:38.899 [ INFO]:subscription: 000B: "192.168.182.243 [ menion | Kodi Media Center ]" subscribing on chann
el "Canale5", weight: 100, adapter: "Sky IT Digital Key (green led) : DVB-T #0", network: "DVB-T Network", mux: "698MHz", p
rovider: "Mediaset", service: "Canale5", profile="omx", hostname="192.168.182.243", username="menion", client="Kodi Media C
enter"
2017-01-09 20:34:39.383 [ TRACE]:transcode: 0001: transcoder_calc_stream_count=2 (video=1, audio=1, subtitle=0)
2017-01-09 20:34:39.383 [ TRACE]:transcode: 0001: Using decoder mpeg2video
2017-01-09 20:34:39.383 [ TRACE]:transcode: 0001: Using encoder h264_omx
2017-01-09 20:34:39.392 [ INFO]:transcode: 0001: 1:MPEG2VIDEO 720x576 > H264 720x576 (h264_omx)
2017-01-09 20:34:39.392 [ TRACE]:transcode: 0001: Using decoder mp2
2017-01-09 20:34:39.392 [ TRACE]:transcode: 0001: Using encoder aac
2017-01-09 20:34:39.394 [ INFO]:transcode: 0001: 2:MPEG2AUDIO > AAC (aac)
2017-01-09 20:34:39.487 [WARNING]:tsfix: The timediff for TELETEXT is big (3215664514), using current dts
2017-01-09 20:34:39.586 [ INFO]:transcode: 0001: Using preset faster
2017-01-09 20:34:39.608 [ INFO]:libav: Using OMX.broadcom.video_encode

The problem is the bold part, tvheadedn pickup mpeg2video decoder which is (as far as I understand), the software decoder of mpeg2

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

I have tried what I suggested and what Morten also tried
The path was too quick and dirty, because hardcoding mpeg2_mmal was forcing tvheadend to pickup mpeg2_mmal also for audio
So I made a "less" quick and dirty patch, but still I get the error:

2017-01-09 20:50:07.370 [ INFO]:subscription: 0007: "192.168.182.243 [ menion | Kodi Media Center ]" subscribing on chann
el "Canale5", weight: 100, adapter: "Sky IT Digital Key (green led) : DVB-T #0", network: "DVB-T Network", mux: "698MHz", p
rovider: "Mediaset", service: "Canale5", profile="omx", hostname="192.168.182.243", username="menion", client="Kodi Media C
enter"
2017-01-09 20:50:07.728 [ TRACE]:transcode: 0001: transcoder_calc_stream_count=2 (video=1, audio=1, subtitle=0)
2017-01-09 20:50:07.728 [ TRACE]:transcode: 0001: Using decoder mpeg2_mmal
2017-01-09 20:50:07.728 [ TRACE]:transcode: 0001: Using encoder h264_omx
2017-01-09 20:50:07.729 [ INFO]:transcode: 0001: 1:MPEG2VIDEO 720x576 > H264 720x576 (h264_omx)
2017-01-09 20:50:07.729 [ TRACE]:transcode: 0001: Using decoder mp2
2017-01-09 20:50:07.729 [ TRACE]:transcode: 0001: Using encoder aac
2017-01-09 20:50:07.731 [ INFO]:transcode: 0001: 2:MPEG2AUDIO > AAC (aac)
2017-01-09 20:50:07.887 [ ERROR]:transcode: 0001: Unable to decode video (0, Success)
2017-01-09 20:50:07.888 [WARNING]:tsfix: The timediff for TELETEXT is big (3215668114), using current dts
2017-01-09 20:50:07.888 [ ERROR]:transcode: 0001: Unable to decode video (0, Success)
2017-01-09 20:50:07.890 [ ERROR]:transcode: 0001: Unable to decode video (0, Success)
2017-01-09 20:50:07.890 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.890 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.891 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.891 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.891 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.891 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.892 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.892 [ ERROR]:libav: MMAL error 2 on control port
2017-01-09 20:50:07.892 [ ERROR]:libav: MMAL error 2 on control port

I have to find some info about this MMAL error or asking support from the libav-dev mailing list, even if that list is not so "supportive" for the moment.
Let's keep in touch

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Hi all
I have made some more performance test.
I'm using a record from DVB-T so we are 100% aligned with the video source we have to deal with, when transcoding with tvheadend and this are the results (all test with mp2 to aac transcoding):

1) native(sw) -> no deinterlace -> h264_omx

pi@raspberrypi:/media/tvrec $ ffmpeg -i Prova.ts -c:a aac -c:v h264_omx -sn -b:v 128k prova_sw_nodeinterlace.mkv
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/usr --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx --enable-libx264 --enable-libx265 --enable-nonfree --enable-gpl --enable-avresample
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mpeg2video @ 0x2def800] Invalid frame dimensions 0x0.
    Last message repeated 14 times
[mpegts @ 0x2deb2b0] PES packet size mismatch
    Last message repeated 2 times
Input #0, mpegts, from 'Prova.ts':
  Duration: 09:56:08.63, start: 117669.938122, bitrate: 6 kb/s
  Program 4005 
    Metadata:
      service_name    : Canale5
      service_provider: Mediaset
    Stream #0:0[0x64a]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x64b](ita): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:2[0x64c](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 128 kb/s
    Stream #0:3[0x653](ita,ita): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
[h264_omx @ 0x2e27e20] Using OMX.broadcom.video_encode
Output #0, matroska, to 'prova_sw_nodeinterlace.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (h264_omx) (H264 / 0x34363248), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, 128 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 h264_omx
    Stream #0:1(ita): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (mp2 (native) -> aac (native))
Press [q] to stop, [?] for help
[mpegts @ 0x2deb2b0] PES packet size mismatchme=00:00:38.28 bitrate= 258.3kbits/s speed=1.72x    
[mpeg2video @ 0x2e303a0] ac-tex damaged at 35 33
[mpeg2video @ 0x2e303a0] Warning MVs not available
[mpeg2video @ 0x2e303a0] concealing 135 DC, 135 AC, 135 MV errors in P frame
frame=  961 fps= 42 q=-0.0 Lsize=    1242kB time=00:00:39.24 bitrate= 259.2kbits/s speed=1.73x    
video:605kB audio:614kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.860181%
[aac @ 0x2e29450] Qavg: 777.114

2) native(sw) -> deinterlace -> h264_omx

pi@raspberrypi:/media/tvrec $ ffmpeg -i Prova.ts -vf yadif -c:a aac -c:v h264_omx -sn -b:v 128k prova_sw_deinterlace.mkv
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/usr --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx --enable-libx264 --enable-libx265 --enable-nonfree --enable-gpl --enable-avresample
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mpeg2video @ 0x239d780] Invalid frame dimensions 0x0.
    Last message repeated 14 times
[mpegts @ 0x23992d0] PES packet size mismatch
    Last message repeated 2 times
Input #0, mpegts, from 'Prova.ts':
  Duration: 09:56:08.63, start: 117669.938122, bitrate: 6 kb/s
  Program 4005 
    Metadata:
      service_name    : Canale5
      service_provider: Mediaset
    Stream #0:0[0x64a]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x64b](ita): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:2[0x64c](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 128 kb/s
    Stream #0:3[0x653](ita,ita): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
[h264_omx @ 0x2423e40] Using OMX.broadcom.video_encode
Output #0, matroska, to 'prova_sw_deinterlace.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (h264_omx) (H264 / 0x34363248), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, 128 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 h264_omx
    Stream #0:1(ita): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (mp2 (native) -> aac (native))
Press [q] to stop, [?] for help
[mpegts @ 0x23992d0] PES packet size mismatchme=00:00:38.88 bitrate= 258.0kbits/s speed=1.07x    
[mpeg2video @ 0x23a0c90] ac-tex damaged at 35 33
[mpeg2video @ 0x23a0c90] Warning MVs not available
[mpeg2video @ 0x23a0c90] concealing 135 DC, 135 AC, 135 MV errors in P frame
frame=  961 fps= 26 q=-0.0 Lsize=    1240kB time=00:00:39.24 bitrate= 258.9kbits/s speed=1.08x    
video:603kB audio:614kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.866869%
[aac @ 0x2425500] Qavg: 777.114

3) mpeg2_mmal(hw) -> no deinterlace -> h264_omx

pi@raspberrypi:/media/tvrec $ ffmpeg -vcodec mpeg2_mmal -i Prova.ts -c:a aac -c:v h264_omx -sn -b:v 128k prova2.mkv
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/usr --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx --enable-libx264 --enable-libx265 --enable-nonfree --enable-gpl --enable-avresample
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mpegts @ 0x153c2e0] PES packet size mismatch
    Last message repeated 2 times
Input #0, mpegts, from 'Prova.ts':
  Duration: 09:56:08.63, start: 117669.938122, bitrate: 6 kb/s
  Program 4005 
    Metadata:
      service_name    : Canale5
      service_provider: Mediaset
    Stream #0:0[0x64a]: Video: mpeg2video ([2][0][0][0] / 0x0002), yuv420p(top first), 320x240, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x64b](ita): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:2[0x64c](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 128 kb/s
    Stream #0:3[0x653](ita,ita): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
File 'prova2.mkv' already exists. Overwrite ? [y/N] y
[h264_omx @ 0x1695980] Using OMX.broadcom.video_encode
Output #0, matroska, to 'prova2.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (h264_omx) (H264 / 0x34363248), yuv420p, 320x240, q=2-31, 128 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 h264_omx
    Stream #0:1(ita): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (mpeg2_mmal) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (mp2 (native) -> aac (native))
Press [q] to stop, [?] for help
[mpeg2_mmal @ 0x15445e0] Changing output format.
Input stream #0:0 frame changed from size:320x240 fmt:yuv420p to size:720x576 fmt:yuv420p53x    
[mpegts @ 0x153c2e0] PES packet size mismatchme=00:00:38.84 bitrate= 258.0kbits/s speed=1.44x    
frame=  961 fps= 35 q=-0.0 Lsize=    1240kB time=00:00:39.24 bitrate= 258.9kbits/s speed=1.45x    
video:603kB audio:614kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.906249%
[aac @ 0x16bea00] Qavg: 777.114

4) mpeg2_mmal(hw) -> deinterlace -> h264_omx

pi@raspberrypi:/media/tvrec $ ffmpeg -vcodec mpeg2_mmal -i Prova.ts -vf yadif -c:a aac -c:v h264_omx -sn -b:v 128k prova2.mkv
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/usr --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx --enable-libx264 --enable-libx265 --enable-nonfree --enable-gpl --enable-avresample
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mpegts @ 0x185a300] PES packet size mismatch
    Last message repeated 2 times
Input #0, mpegts, from 'Prova.ts':
  Duration: 09:56:08.63, start: 117669.938122, bitrate: 6 kb/s
  Program 4005 
    Metadata:
      service_name    : Canale5
      service_provider: Mediaset
    Stream #0:0[0x64a]: Video: mpeg2video ([2][0][0][0] / 0x0002), yuv420p(top first), 320x240, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x64b](ita): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:2[0x64c](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 128 kb/s
    Stream #0:3[0x653](ita,ita): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
File 'prova2.mkv' already exists. Overwrite ? [y/N] y
[h264_omx @ 0x19b4440] Using OMX.broadcom.video_encode
Output #0, matroska, to 'prova2.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (h264_omx) (H264 / 0x34363248), yuv420p, 320x240, q=2-31, 128 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 h264_omx
    Stream #0:1(ita): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (mpeg2_mmal) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (mp2 (native) -> aac (native))
Press [q] to stop, [?] for help
[mpeg2_mmal @ 0x19ca8f0] Changing output format.
Input stream #0:0 frame changed from size:320x240 fmt:yuv420p to size:720x576 fmt:yuv420p48x    
[mpegts @ 0x185a300] PES packet size mismatchme=00:00:38.55 bitrate= 256.8kbits/s speed=0.987x    
frame=  961 fps= 24 q=-0.0 Lsize=    1240kB time=00:00:39.24 bitrate= 259.0kbits/s speed=0.989x    
video:603kB audio:614kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.905568%
[aac @ 0x19f05a0] Qavg: 777.114

So in summary

1) sw->hw no deinterlace: speed 1.73x
2) sw->hw deinterlace: speed 1.08x
3) hw->hw no deinterlace: speed 1.45x
4) hw->hw deinterlace: speed 0.97x

So, we can clearly see that the deinterlace put an huge impact on the performance, but also it seems that the hw decoding doesn't help. However looking better at the logs, you can see that the mpeg2_mmal seems to output a fixed 720x576 size despite of the input, that in this case is 320x240, so the encoder has more to do and also the output of the encoder is even scaled back to 320x240
So I have tried to put a scaling before the encoding:

5) mpeg2_mmal(hw) > deinterlace -> scale> h264_omx

pi@raspberrypi:/media/tvrec $ ffmpeg -vcodec mpeg2_mmal -i Prova.ts -vf yadif -vf scale=320:240 -c:a aac -c:v h264_omx -sn -b:v 128k prova_hw_deinterlace_scaled.mkv
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/usr --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx --enable-libx264 --enable-libx265 --enable-nonfree --enable-gpl --enable-avresample
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mpegts @ 0x31de310] PES packet size mismatch
    Last message repeated 2 times
Input #0, mpegts, from 'Prova.ts':
  Duration: 09:56:08.63, start: 117669.938122, bitrate: 6 kb/s
  Program 4005 
    Metadata:
      service_name    : Canale5
      service_provider: Mediaset
    Stream #0:0[0x64a]: Video: mpeg2video ([2][0][0][0] / 0x0002), yuv420p(top first), 320x240, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x64b](ita): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:2[0x64c](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 128 kb/s
    Stream #0:3[0x653](ita,ita): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
[h264_omx @ 0x3338450] Using OMX.broadcom.video_encode
Output #0, matroska, to 'prova_hw_deinterlace_scaled.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (h264_omx) (H264 / 0x34363248), yuv420p, 320x240, q=2-31, 128 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 h264_omx
    Stream #0:1(ita): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (mpeg2_mmal) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (mp2 (native) -> aac (native))
Press [q] to stop, [?] for help
[mpeg2_mmal @ 0x334e900] Changing output format.
Input stream #0:0 frame changed from size:320x240 fmt:yuv420p to size:720x576 fmt:yuv420p
[mpegts @ 0x31de310] PES packet size mismatchme=00:00:38.57 bitrate= 256.6kbits/s speed=1.48x    
frame=  961 fps= 36 q=-0.0 Lsize=    1240kB time=00:00:39.24 bitrate= 258.9kbits/s speed=1.48x    
video:603kB audio:614kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.906249%
[aac @ 0x33745a0] Qavg: 777.114

It's quite better now, this speed, 1.48x is possible that makes the math to fill a real time transcoding on Rpi3, even if there is little margin.
Still it needs to be understood why the MMAL error when attempting to use this encoder in tvheadend, I'm building a custom ffmpeg for trying to understand what the error ""2" means.

RE: TVHeadend Raspberry Pi and Transcoding - Added by Joseph ZACHARIE almost 8 years ago

Hi,

During my test, I've try to use a h264 source (From TVheadend et from a file).

The file was correclty compress with good performance.
From TVheadend they was some performance issue.

The MPG2 compression to h264_omx look like a software compression with your performance figures.

Try to compress direclty a .ts with ffmpeg to omx you will see the specificity of HW compression in the picture result.

Joseph

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Hi Joseph
No, I believe that with my testing, transcoding with tvheadend was actually using hardware h264_omx for encodinf and software mpeg2 decoding. In fact if I look at the CPU usage of my ffmpeg test case #2 (sw dec, hw enc plus deinterlace) and case #5 (hw dev, he enc plus deinterlace and resize) I get 156% and 98%. The 156% is the CPU usage we get also with tvheadend
According also to the Kodi recomandation for MPEG2 playback, Rpi3 cannot sustain a stable, realtime, mpeg2 decoding.
So for having a chance of success, we need to use the GPU for the decoding also, and we still hit the MMAL error.
I have just completed my test here and what I get is:

tvheadend logs

2017-01-10 15:17:12.424 [  ERROR]:libav: MMAL error 2(ENOSPC) on control port
2017-01-10 15:17:12.444 [  ERROR]:libav: MMAL error 2(ENOSPC) on control port
2017-01-10 15:17:12.464 [  ERROR]:libav: MMAL error 2(ENOSPC) on control port
2017-01-10 15:17:12.484 [  ERROR]:libav: MMAL error 2(ENOSPC) on control port

sudo vcdbg log msg

338795.311: alloc_compact_internal(space=3291328, in_low_region=0, mode=7) failed
338815.315: alloc_compact_internal(space=3291328, in_low_region=0, mode=7) failed
338835.322: alloc_compact_internal(space=3291328, in_low_region=0, mode=7) failed
338855.326: alloc_compact_internal(space=3291328, in_low_region=0, mode=7) failed
338875.317: alloc_compact_internal(space=3291328, in_low_region=0, mode=7) failed
338895.315: alloc_compact_internal(space=3291328, in_low_region=0, mode=7) failed

I think we may miss some initialization in libav when using mpeg2_mmal

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Hi
I have moved a little bit ahead. The MMAL 2 error was caused by the fact that mpeg2_mmal needs a valid width height in AVContex. Doing so, there is no error, the decoder kind of works (even if it return 0 but got_frame is 1). The problem is that the decoded video is weird, in the sense it drives h264_omx crazy (high Quantizer, no valid video out). Looking at the ffmpeg mmal init function, it seems that all the required parameters are initialized now, so I cannot understand what's the problem.
And the problem is that I cannot find anyone to support in this...

RE: TVHeadend Raspberry Pi and Transcoding - Added by Morten Gade Sørensen almost 8 years ago

Really great that you're doing progress Antonio. Please let me know if there is anything I can do to test...
Have you tried transcoding/transrating when the original/source codec is H.264 already (h264_mmal)? Do you get the same behavior?

Sincerely,
Morten

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

No I didn't. Actually a guy on the ffmpeg-user mailing list replied. Tvheadend use an old, deprecated api for decode/encode, he recommend to use the new ones, that actually are the ones ffmpeg utils use. The modification should not be difficult, I will look into that

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Hi all
I have made some more tests

1) mpeg2 -> decode (hw) -> deinterlace -> yuv (raw) output: 38fps avg / 40fps peak / 184% CPU
2) mpeg2 -> decode (sw> -> deinterlace -> yuv (raw) output: 35fps avg / 45fps peak / 184% CPU
3) yuv -> encode (hw) -> h264 output: : 70fps avg / 122fps peak / 25% CPU

So, this gives me a clearer picture on the process. As you can see the encoding performances are very very good, CPU usage is low and fps very high. The problem is with the decoding and deinterlacing. Here the things are quite strange, apparently there is no big difference between hw and sw decoding, but if you look at the differences between the average fps and peak fps I believe the problem here is the SD card write/read performance.
But this is not the point, the point is that the tvheadend transcoding engine is not pipelined. As far as I have seen in the code, it transcode in parallel audio/video/subtitles, BUT, the video transcoding itself is not parallel, it is serial. So, even if we accelerate to the hell, still the encoder waits resize, resize waits deinterlace, deinterlace waits decoder... This will endup no where.
So.... according to the number, it is possible to match realtime encoding on a Rpi3. Because, given 4 cores (to simplify I assume that the cores can run in parallel with no penalties and this is not the real case) with a new transcoding architecture we can run

CPU0: Audio encoding
CPU1: Video decoding
CPU2: Filtering
CPU3: TVHeadend core, subtitles, encoding control, etc...

But to do so we have to modify the TV Headend transcoder to run in multithread. In general you cannot just pick a core for your thread, Linux will handle it, but without being multithread, even if Linux will try to optimize the code on the available cores, we will not make it.
I should have the skills to do so, I have actually forked the tvheadend repo, the problem is the time... I have two baby twins and a full time job, I'm really not sure how fast I could get some result, probably after a Rpi10 is out wil 16 cores@4Ghz in a credit card size, able to transcode 10 channels in parallel on one core, smoking a cigarete on the others... :)
If anyone would join the task, let's discuss it

RE: TVHeadend Raspberry Pi and Transcoding - Added by Frank Schimmack almost 8 years ago

Hi all,
I am not an expert, so I am just thinking like a kind of "end user".
It is possible to watch DVDs (MPEG2) and deinterlaced on a raspi without high CPU load, or not?

So the Job: mpeg2 -> decode (hw) -> deinterlace -> yuv (raw) should be possible to do in my opinion. Perhaps I am missing something....

RE: TVHeadend Raspberry Pi and Transcoding - Added by Antonio S almost 8 years ago

Your question is out of topic here. Anyhow, TV Headend is not a player, it is a DVB streaming backend. Your question should be placed to the frontend (player) you use. For instance, Kodi on Rpi can perfectly decode mpeg2 streaming, assuming that the mpeg2 decoder license is available

(51-75/160)