Tdi-Me
Posts: 38
Joined: Fri May 05, 2017 8:11 pm

Mpeg2 hardware decoding?

Fri Oct 06, 2017 1:49 pm

I have a rpi3 and i bought the license for mpeg2 decoding. I have verified that it is installed correctly but i am trying to use ffmpeg with hardware decoding and i think i am using the correct command but the performance is not much different than software decoding.

Code: Select all

/media/emby/ffmpeg-stuff/FFmpeg/ffmpeg -fflags +igndts -c:v mpeg2_mmal -i "http://127.0.0.1:8096/LiveTv/LiveStreamFiles/33d6a801fda343d8ad20032ad127b83f/stream.ts" -map_metadata -1 -map_chapters -1 -threads 0 -sn -codec:v:0 h264_omx -b:v 5000000 -maxrate 5000000 -bufsize 10000000 -force_key_frames "expr:gte(t,n_forced*3)" -vf "yadif=0:-1:0,scale=trunc(min(max(iw\,ih*dar)\,1920)/2)*2:trunc(ow/dar/2)*2" -flags -global_header -vsync cfr -codec:a:0 aac -strict experimental -ac 6 -ab 192000 -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time 3 -individual_header_trailer 0 -segment_format mpegts -segment_list_entry_prefix "hls/068a9456c2ce056b2e1e1e6b7c5cb0b2/" -segment_list_type m3u8 -segment_start_number 0 -segment_list "/emby/emby-paths/transcode-temp/transcoding-temp/068a9456c2ce056b2e1e1e6b7c5cb0b2.m3u8" -y "/emby/emby-paths/transcode-temp/transcoding-temp/068a9456c2ce056b2e1e1e6b7c5cb0b2%d.ts"

Code: Select all

frame= 38 fps= 23 q=-0.0 size=N/A time=00:00:01.16 bitrate=N/A dup=34 drop=0 speed=0.72x frame= 47 fps= 22 q=-0.0 size=N/A time=00:00:01.46 bitrate=N/A dup=36 drop=0 speed=0.685x frame=
52 fps= 20 q=-0.0 size=N/A time=00:00:01.63 bitrate=N/A dup=37 drop=0 speed=0.613x frame= 60 fps= 19 q=-0.0 size=N/A time=00:00:01.90 bitrate=N/A dup=38 drop=0 speed=0.597x frame= 65 fps= 18 q=-0.0 size=N/A time=00:00:02.06 bitrate=N/A dup=39 drop=0 speed=0.56x
frame= 75 fps= 18 q=-0.0 size=N/A time=00:00:02.40 bitrate=N/A dup=41 drop=0 speed=0.572x frame= 80 fps= 17 q=-0.0 size=N/A time=00:00:02.56 bitrate=N/A dup=42 drop=0 speed=0.547x

Code: Select all

/media/emby/ffmpeg-stuff/FFmpeg/ffmpeg -fflags +igndts -i "http://127.0.0.1:8096/LiveTv/LiveStreamFiles/66f70efc2799416eb57a1fdba3fb51e3/stream.ts" -map_metadata -1 -map_chapters -1 -threads 0 -sn -codec:v:0 h264_omx -b:v 5000000 -maxrate 5000000 -bufsize 10000000 -force_key_frames "expr:gte(t,n_forced*3)" -vf "yadif=0:-1:0,scale=trunc(min(max(iw\,ih*dar)\,1920)/2)*2:trunc(ow/dar/2)*2" -flags -global_header -vsync cfr -codec:a:0 aac -strict experimental -ac 6 -ab 192000 -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time 3 -individual_header_trailer 0 -segment_format mpegts -segment_list_entry_prefix "hls/88886cb8ad432f7078f78b278ebe4217/" -segment_list_type m3u8 -segment_start_number 0 -segment_list "/emby/emby-paths/transcode-temp/transcoding-temp/88886cb8ad432f7078f78b278ebe4217.m3u8" -y "/emby/emby-paths/transcode-temp/transcoding-temp/88886cb8ad432f7078f78b278ebe4217%d.ts"

Code: Select all

frame= 43 fps= 35 q=-0.0 size=N/A time=00:00:01.33 bitrate=N/A dup=41 drop=0 speed=1.07x frame= 51 fps= 29 q=-0.0 size=N/A time=00:00:01.60 bitrate=N/A dup=41 drop=0 speed=0.905x frame=
55 fps= 24 q=-0.0 size=N/A time=00:00:01.73 bitrate=N/A dup=41 drop=0 speed=0.75x frame= 65 fps= 23 q=-0.0 size=N/A time=00:00:02.06 bitrate=N/A dup=41 drop=0 speed=0.732x frame= 71 fps= 21 q=-0.0 size=N/A time=00:00:02.26 bitrate=N/A dup=41 drop=0 speed=0.675x
frame= 79 fps= 20 q=-0.0 size=N/A time=00:00:02.53 bitrate=N/A dup=41 drop=0 speed=0.654x frame= 86 fps= 20 q=-0.0 size=N/A time=00:00:02.76 bitrate=N/A dup=41 drop=0 speed=0.632x frame=
91 fps= 19 q=-0.0 size=N/A time=00:00:02.93 bitrate=N/A dup=41 drop=0 speed=0.599x frame= 97 fps= 18 q=-0.0 size=N/A time=00:00:03.13 bitrate=N/A dup=41 drop=0 speed=0.578x frame= 107 fps= 18 q=-0.0 size=N/A time=00:00:03.47 bitrate=N/A dup=41 drop=0 speed=0.584x
frame= 114 fps= 18 q=-0.0 size=N/A time=00:00:03.70 bitrate=N/A dup=41 drop=0 speed=0.571x
Am i doing something wrong here?
Last edited by Tdi-Me on Fri Oct 06, 2017 2:17 pm, edited 1 time in total.

User avatar
topguy
Posts: 6491
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 2:06 pm

You should probably add some [ code ][ /code ] tags around your commands. You have a few emojis messing it up.

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

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 4:01 pm

What resolution and frame rate is your source?
MPEG2 decode and H264 encode use the same hardware block. The Pi3's ARM cores are more than capable of MPEG2 SD decode in real time, and in some ways doing so is freeing up the hardware codec block to dedicate resources to the encoding.
Seeing as you're getting about half realtime I'm guessing you're on HD (is there a resize in there?), so sharing one block designed for 1080P30 (encode OR decode) sounds about right. The ARMs are likely to struggle with HD, but s/w decode still leaves the hardware block available for the encode. What numbers do you get out of "top" for s/w decode?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Tdi-Me
Posts: 38
Joined: Fri May 05, 2017 8:11 pm

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 4:44 pm

This is actually streaming live tv from my hdhomerun prime. The channel itself is a SD channel, not sure what resolution it would be. Watching the channel with HW decoding turned on my cpu for ffmpeg is:
1581 root 20 0 184672 31968 11908 R 116.8 3.6 0:07.10 ffmpeg

with software decoding for mpeg2 turned off ( hardware mp4 turned on still )
1856 root 20 0 205484 28984 12184 R 117.2 3.2 0:18.67 ffmpeg

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

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 5:03 pm

OK, at SD resolutions you should get some gain with hardware MPEG2 decode, although there is some extra overhead with shifting image data around.
I'm assuming that your video isn't interlaced, otherwise you may find a deinterlacer getting dropped in.

At the moment you've got so much on that command line that I can't see anything that is going on. Strip it down to a simple case from a file to a file. Just work on the video initially, drop (or copy) the audio - AAC encoding will take a chunk of CPU. Enable more logging to confirm the codec being used.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Tdi-Me
Posts: 38
Joined: Fri May 05, 2017 8:11 pm

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 5:23 pm

Ok, i have a tv show i recorded that is saved as a .ts i can convert.
I am primarily using emby for this so a great deal of the commands i dont have control over.
I had just expected playback to run a bit smoother with hardware acceleration. For live tv its still not great, it pauses here and there trying to keep up.
with this command:

Code: Select all

 sudo ./ffmpeg -c:v mpeg2_mmal -i The\ Big\ Bang\ Theory\ S11E02\ The\ Retraction\ Reaction-1.ts -codec:v:0 h264_omx out.mp4
my cpu is:
7272 root 20 0 175068 24356 11432 S 89.1 2.7 0:20.88 ffmpeg
and i am seeing:

Code: Select all

[mpeg2_mmal @ 0x30bc790] Changing output format.
[h264_omx @ 0x324c7c0] Using OMX.broadcom.video_encode:32:22.77 bitrate=  -0.0kbits/s speed=N/A
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf57.82.102
    Stream #0:0: Video: h264 (h264_omx) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 29.97 fps, 30k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc57.106.104 h264_omx
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1(side), fltp, 341 kb/s
    Metadata:
      encoder         : Lavc57.106.104 aac
frame= 1859 fps= 32 q=-0.0 Lsize=    4204kB time=00:01:01.99 bitrate= 555.5kbits/s dup=244 drop=0 speed=1.06x
video:1566kB audio:2584kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.303041%
without mpeg2_mmal:

Code: Select all

pi@raspberrypi:/media/emby/ffmpeg-stuff/FFmpeg $ sudo ./ffmpeg -i The\ Big\ Bang\ Theory\ S11E02\ The\ Retraction\ Reaction-1.ts -codec:v:0 h264_omx out.mp4

Code: Select all

  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (ac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_omx @ 0x34dd840] Using OMX.broadcom.video_encode
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf57.82.102
    Stream #0:0: Video: h264 (h264_omx) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 29.97 fps, 30k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc57.106.104 h264_omx
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1(side), fltp, 341 kb/s
    Metadata:
      encoder         : Lavc57.106.104 aac
frame=  243 fps= 30 q=-0.0 Lsize=     535kB time=00:00:08.07 bitrate= 543.2kbits/s dup=74 drop=0 speed=1.01x
video:198kB audio:329kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.587610%
Maybe i am missing something but these 2 look very similar to me performance wise, which is why i am wondering if i am doing something wrong, have it set up wrong or if something else is going on.

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

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 6:00 pm

You're still transcoding the audio from AC3 to aac. Stuff in -c:a copy (iirc) to make it just copy it instead.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Tdi-Me
Posts: 38
Joined: Fri May 05, 2017 8:11 pm

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 6:05 pm

holy crap thats a lot faster.
frame= 627 fps=147 q=-0.0 Lsize= 1532kB time=00:00:21.08 bitrate= 595.0kbits/s dup=151 drop=0 speed=4.96x
what audio format is ac3 though? I am completely unfamiliar with that.
O and cpu usage is only 50% so ya for mpeg2 playback without audio transcoding the pi can more than handle this with the hardware acceleration. I would have never guessed that audio transcoding is really what was knecapping the pi.

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

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 7:09 pm

Tdi-Me wrote:
Fri Oct 06, 2017 6:05 pm
holy crap thats a lot faster.
frame= 627 fps=147 q=-0.0 Lsize= 1532kB time=00:00:21.08 bitrate= 595.0kbits/s dup=151 drop=0 speed=4.96x
what audio format is ac3 though? I am completely unfamiliar with that.
O and cpu usage is only 50% so ya for mpeg2 playback without audio transcoding the pi can more than handle this with the hardware acceleration. I would have never guessed that audio transcoding is really what was knecapping the pi.
That would be Dolby AC3, aka Dolby Digital (typically 5.1 surround sound).
It's likely to be doing a surround down-mix too in order to do a stereo AAC encode, but that depends on exactly what was encoded in the AC3 stream.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Tdi-Me
Posts: 38
Joined: Fri May 05, 2017 8:11 pm

Re: Mpeg2 hardware decoding?

Fri Oct 06, 2017 8:13 pm

I thank you very much for your insight on this. I have been fiddling around with this for a while now trying to get my media server more optimized to at least have things run smoothly. Not really knowing what is causing such an issue but always seeing people say the rpi can decode very smoothly with hardware acceleration. So at least now i know what direction to look at. I am going to poke around with different audio codecs. My latest conversion is:

Code: Select all

    Stream #0:0[0x8c0]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x480 [SAR 8:9 DAR 4:3], Closed Captions, 29.97 fps, 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x8c1](eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x8c2](spa): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 192 kb/s
File 'out.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (ac3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[h264_omx @ 0x390bab0] Using OMX.broadcom.video_encode
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf57.82.102
    Stream #0:0: Video: h264 (h264_omx) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 29.97 fps, 30k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc57.106.104 h264_omx
    Stream #0:1(eng): Audio: mp3 (libmp3lame) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp
    Metadata:
      encoder         : Lavc57.106.104 libmp3lame
frame=  223 fps= 84 q=-0.0 Lsize=     294kB time=00:00:07.40 bitrate= 325.1kbits/s dup=70 drop=0 speed= 2.8x
Not a breakneck speed but anything over 1 would be just fine for watching live tv. So once again thank you very much!

Return to “Graphics programming”