dahat
Posts: 3
Joined: Thu Jul 06, 2017 3:13 am

Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead.

Thu Jul 06, 2017 3:28 am

I am going mad trying to make this work on the Pi and am hoping someone can tell what I am doing wrong.

I am attempting to get FFmpeg to run on my Pi3 to consume an MPEG2 video stream from my HD Homerun (networked digital television tuner)

In order to make things more efficient, I purchased an mpeg2 decoder key and have set it up on the Pi3, and on the device running “vcgencmd codec_enabled MPG2” returns “MPG2=enabled”.

After cloning the FFmpeg Github branch, I did the following configure:

Code: Select all

sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --enable-mmal --enable-omx --enable-omx-rpi
After a 30 minute build & install, I run the following to consume a live tv stream and convert it to something streamable:

Code: Select all

ffmpeg -i http://192.168.1.29:5004/auto/v48 -threads 2 -flags -global_header -fflags +genpts -map v:0 -map a:0 -hls_time 3 -hls_wrap 30 "/home/pi/videoout/stream.m3u8" -c:a libfaac -b:a 32k -ac 2 -c:v h264_omx -preset veryfast -tune zerolatency -s 320x180 -b:v 256k -bufsize 2M
With the exception of the output path and the output video codec (also used libx264) it works just fine on my Windows desktop PC, but on the PI it seems to struggle.

Very quickly on the Pi the FPS drops and the time increasingly falls behind and not long later behinds to report errors:
frame= 1084 fps=8.3 q=29.0 size=N/A time=00:00:35.22 bitrate=N/A dup=452 drop=0 [ac3 @ 0x1d1ade0] frame sync error
Error while decoding stream #0:1: Invalid data found when processing input
frame= 1104 fps=8.3 q=29.0 size=N/A time=00:00:35.22 bitrate=N/A dup=470 drop=0 [mpeg2video @ 0x1d176a0] 00 motion_type at 18 23
[mpeg2video @ 0x1d176a0] ac-tex damaged at 23 16
[mpeg2video @ 0x1d176a0] slice mismatch
[mpeg2video @ 0x1d176a0] Warning MVs not available
[mpeg2video @ 0x1d176a0] concealing 1056 DC, 1056 AC, 1056 MV errors in B frame
[mpegts @ 0x1d13470] PES packet size mismatch
frame= 1120 fps=8.4 q=29.0 size=N/A time=00:00:35.73 bitrate=N/A dup=482 drop=0 [ac3 @ 0x1d1ade0] expacc 127 is out-of-range
[ac3 @ 0x1d1ade0] error decoding the audio block
[ac3 @ 0x1d1ade0] frame sync error
Error while decoding stream #0:1: Invalid data found when processing input
[mpeg2video @ 0x1d176a0] ac-tex damaged at 29 7
[mpeg2video @ 0x1d176a0] ac-tex damaged at 41 3
[mpeg2video @ 0x1d176a0] ac-tex damaged at 15 10
[mpeg2video @ 0x1d176a0] 00 motion_type at 19 11
[mpeg2video @ 0x1d176a0] Warning MVs not available
[mpeg2video @ 0x1d176a0] concealing 1188 DC, 1188 AC, 1188 MV errors in P frame
The resulting video files often end up with quite a bit of macroblocking and are far smaller than their PC equivalents.

I’ve upped video memory to 256mb to give the GPU decoding some room, all devices are on ethernet, I’ve tried few other configure incantations and rebuilds, including:

Code: Select all

sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-nonfree --enable-mmal --enable-omx --enable-omx-rpi --enable-decoder=h264_mmal --enable-decoder=mpeg2_mmal --enable-encoder=h264_omx --enable-encoder=h264_omx
I am at a loss as to why this isn’t working on the PI. Am I not properly configuring the build? Am I not properly invoking the hw mpeg2 decoder? Am I not using the hw h264 encoder?

fruitoftheloom
Posts: 16600
Joined: Tue Mar 25, 2014 12:40 pm

Re: Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead.

Thu Jul 06, 2017 5:43 am

arch=armel

Raspbian Jessie with Desktop is ARMHF

https://wiki.debian.org/ffmpeg
Adieu

User avatar
Imperf3kt
Posts: 903
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead.

Thu Jul 06, 2017 5:48 am

Looks to me like you're running out of memory.
I ran into this same issue once on Windows 7 while transcoding an mpeg2 transport stream to AVC/h.264
During the encoding process, I somehow exceeded the 4GB limit of the 32bit application I was using.


I can't remember what caused the bottleneck though, but it was scripting related.
Stephen Hawking, rest in peace.
8 January 1942 – 14 March 2018

gkreidl
Posts: 5591
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead.

Thu Jul 06, 2017 7:46 am

Perhaps the HW decoder is not used for MPEG encoding at all.

I've never tried to achieve this with FFmpeg. I use a solution based on gstreamer and the gstreamer-omx module. You might try my transcoder3 package: viewtopic.php?f=38&t=123876

Output is an MKV packaged stream on a HTTP server.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

dahat
Posts: 3
Joined: Thu Jul 06, 2017 3:13 am

Re: Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead

Mon Jul 10, 2017 5:28 am

Thanks for the input all, alas I am still fighting this oddity.

fruitoftheloom:

Interesting catch. Tried both configures with armhf instead and had the same result as before.

Imperf3kt:

My theory is that the eventual errors happen because memory is filled up… however that doesn’t explain why it can’t keep up in real time, or why top is reporting nearly 200% CPU usage for the process when it’s running... still two more cores to use.

Gkreidl:
Unfortunately I’m kind of tied to FFmpeg as the project I’ve got uses it for the transcoding and works just fine on Windows today.



After some additional troubleshooting, I am reaching maddening levels of bizarreness.

I tried to eliminate as many external factors as I could, so switched from using my tv tuner, to a VOB from a DVD (both being mpeg2) and would do the following:

ffmpeg -i VTS_01_2.VOB -c:a copy -c:v h264_omx -b:v 256k -hls_time 3 -hls_wrap 30 "/media/usb1/foo.m3u8"

This was rather performant… however the moment I stopped simply copying the audio and specified a different codec, things would slow down again… regardless of which audio codec I chose.

At this point one might say “just accept the audio which comes through, AC3 on an OTA/cable broadcast isn’t too big”… which is true, though with the h264_omx encoder, all but the first HLS video parts is black. Only it has visible video. This happens for any length for each file. And when I switch back to libx264, things are too slow to keep up with the live broadcast.

dahat
Posts: 3
Joined: Thu Jul 06, 2017 3:13 am

Re: Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead.

Fri Aug 11, 2017 6:59 am

I hate to do a bump... but... bump.

This shouldn't be so hard... should it? I've got an active MPEG2 decoder license configured. The HW & SW supposedly support h264 encoding... and yet I either end up with black video or quickly running out of buffer due to low speed.

Is there another place I should be asking?

Perhaps I should hope that my second bounty on StackOverflow can get an answer: https://stackoverflow.com/questions/450 ... thing-down

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5138
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead.

Fri Aug 11, 2017 1:06 pm

My theory is that the eventual errors happen because memory is filled up… however that doesn’t explain why it can’t keep up in real time, or why top is reporting nearly 200% CPU usage for the process when it’s running... still two more cores to use.
You've put "-threads 2" on the command line. There's no way to split a thread between multiple cores, therefore it will only max out 2 cores. Put "-threads 4" and I've got up to 350%.

Having built libx264 and ffmpeg myself following your instructions, grabbed a random MPEG2 file and fed it into your command line, it appears that you are doing absolutely everything in software on the ARM. That will be slow (painfully so on a Pi1).

omxplayer for me is quite happy playing the file, so tere's no issue of the codec not being enabled.

Amend your command line to include "-c:v mpeg2_mmal" BEFORE the -i specifying the input, and it will use the hardware MPEG2 decoder.
Likewise you have specified the encoder AFTER your output filename, therefore it is ignored. It must be before - that is the way that ffmpeg's command line parsing works.

Code: Select all

ffmpeg -c:v mpeg2_mmal -i in.mpg -threads 4 -flags -global_header -fflags +genpts -map v:0 -hls_time 3 -hls_wrap 30 -c:v h264_omx -preset veryfast -tune zerolatency -s 320x180 -b:v 256k -bufsize 2M out.mp4
Where in.mpg is a 720x480 MPEG2 stream has run through quite happily using hw decode and encode at 48fps. Remove the resize to 320x180 and it is over 100fps! top is reporting about 60% of one core utilised on the ARM.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

e1ioan
Posts: 1
Joined: Mon Feb 12, 2018 9:41 pm

Re: Pi3 + FFmpeg = HD Homerun transcoder? Sadness instead.

Mon Feb 12, 2018 9:43 pm

Hi,
Were you able to do this?

Thanks.

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 11 guests