Comskip Support Forum

Comskip is a free commercial detector, browse the forum for more information
It is currently Wed Nov 22, 2017 7:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Mon May 29, 2017 9:09 pm 
Offline

Joined: Mon May 29, 2017 8:45 pm
Posts: 3
Comskip should have the option to use mpeg2_mmal decoder on a Raspberry Pi.

For myself, I made the following change to the source code ...

Code:
 mpeg2dec.c
Old
      codec = avcodec_find_decoder(codecCtx->codec_id);

New
        if (codecCtx->codec_id == AV_CODEC_ID_MPEG2VIDEO)
        {
          codec = avcodec_find_decoder_by_name("mpeg2_mmal");
        }
        else
        {
            codec = avcodec_find_decoder(codecCtx->codec_id);
        }


Obviously, if this were implemented it would need to be an option switched on/off by build configuration and/or command line switch and/or comskip.ini settings.

I have done some testing, and it seems to be working well for me so far.


Top
 Profile  
Reply with quote  
PostPosted: Tue May 30, 2017 8:12 am 
Offline
Site Admin

Joined: Sun Aug 21, 2005 3:49 pm
Posts: 3098
Good suggestion. Will add


Top
 Profile  
Reply with quote  
PostPosted: Tue May 30, 2017 10:21 am 
Offline

Joined: Tue May 30, 2017 9:36 am
Posts: 4
May I suggest the addition as follows?

Code:
    if (codecCtx->codec_id == AV_CODEC_ID_MPEG2VIDEO)
    {
       codec = avcodec_find_decoder_by_name("mpeg2_mmal");
    }
    else if (codecCtx->codec_id == AV_CODEC_ID_H264)
    {
       codec = avcodec_find_decoder_by_name("h264_mmal");
    }
    else
    {
      codec = avcodec_find_decoder(codecCtx->codec_id);
}


Unfortunately it seems ffmpeg doesn't recognize the RPi's VPU as hardware decoder, so you would need an additional switch.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 31, 2017 9:02 am 
Offline
Site Admin

Joined: Sun Aug 21, 2005 3:49 pm
Posts: 3098
if the mmal codec is unique for raspberry why not search for it and when it fails do the normal find decoder?


Top
 Profile  
Reply with quote  
PostPosted: Wed May 31, 2017 11:35 am 
Offline

Joined: Tue May 30, 2017 9:36 am
Posts: 4
That might be a possible way. I'll give it a try and send you a pull request if it works.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 31, 2017 6:25 pm 
Offline

Joined: Mon May 29, 2017 8:45 pm
Posts: 3
Even if the mmal codecs are present, it may not always be correct to use them on all Raspberry Pis

It may be possible that there is no MPEG-2 licence. I've not tested, but I'm pretty sure mpeg2_mmal won't work in this case.

If there is not enough memory allocated to the GPU, using the mpeg2_mmal codec can cause failures. The (not very helpful) message "Empty input" is what I encountered. (The default of gpu_mem=64 is not enough).

My simple hard-coded hack is good enough for me where I know what my hardware/config is, but a generalized implementation needs to be more careful. Especially since it may not be obvious to the user what has caused the problem based on error the messages.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 01, 2017 8:04 am 
Offline
Site Admin

Joined: Sun Aug 21, 2005 3:49 pm
Posts: 3098
Clear
But why not use the already available switch and ini setting to enable/disable the HW decoding using the hardware_decode boolean?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 02, 2017 12:32 am 
Offline

Joined: Tue May 30, 2017 9:36 am
Posts: 4
Generally agree.
It should be obvious that you can't hardware decode on a device that has a locked decoder.

The issue with not enough memory on the other hand should tested. I've read from people in the RPi forums who claim to run the hw decoder on just 64 MB video memory. That may or may not be true though.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 02, 2017 7:11 am 
Offline
Site Admin

Joined: Sun Aug 21, 2005 3:49 pm
Posts: 3098
If you can enable/disable the HW decoder everything should be covered?
Enable it, see if speed improves, if not, disable.
Or are there multiple HW decoders on the Pi?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 02, 2017 9:07 am 
Offline

Joined: Mon May 29, 2017 8:45 pm
Posts: 3
IfThenERROR wrote:
Generally agree.
It should be obvious that you can't hardware decode on a device that has a locked decoder.

The issue with not enough memory on the other hand should tested. I've read from people in the RPi forums who claim to run the hw decoder on just 64 MB video memory. That may or may not be true though.


It can depend on the video being decoded. SD MPEG2 (720x480) hw decodes in the default 64MB.

erik wrote:
Or are there multiple HW decoders on the Pi?


mmal is the only one I think ... certainly the only one supported by ffmpeg ... https://trac.ffmpeg.org/wiki/HWAccelIntro


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 02, 2017 10:43 am 
Offline

Joined: Tue May 30, 2017 9:36 am
Posts: 4
ObvB wrote:
mmal is the only one I think


Actually mmal is the VPU hardware on the RPi, but it supports 4 decoders: mpeg2, mpeg4, h.264 and vc1. All are supported in ffmpeg.

As I wrote in the OSMC forum they are all pretty easy to enable for the ffmpeg command line interface, but obviously not so easy to correctly call from a program like the mpeg2dec.

The bad thing about the decoders is, they may very well differ in the state of activation. h.264 is always unlocked, mpeg2 and vc1 each need an additional license to be purchased and are locked by default. Not sure about mpeg4. So there are at least 4 possible combinations of available decoders on the RPi.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 02, 2017 11:02 am 
Offline
Site Admin

Joined: Sun Aug 21, 2005 3:49 pm
Posts: 3098
In comskip you should allow someone to enable the HW decoder, test if it works and if its faster and if happy, leave enabled.
Don't try to solve all configuration problems


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group