Plugin: MP2Extended (1 Viewer)

henso

Development Group
  • Team MediaPortal
  • February 16, 2012
    2,341
    832
    Home Country
    Denmark Denmark
    The image decoder of ffprobe/ffmpeg cannot handle non-ascii characters. Video and sound seem to work though. I don't think we can fix this in MP2, any ideas?
     

    johanj

    MP Donator
  • Premium Supporter
  • January 31, 2009
    781
    398
    47
    Home Country
    Sweden Sweden
    What is made differently in MPExt for MP1? I can browse those images(that are named with åäö or has åäö in folder path) there.
     

    Attachments

    • image.png
      image.png
      4.9 MB

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    I don't think MP1 uses ffprobe/ffmpeg (somebody correct me if I'm wrong).
    In fact it does:

    Code:
    public static Stream ExtractImage(MediaSource source, long position, int? maxWidth, int? maxHeight, string borders, string format)
            {
                if (!source.Exists)
                {
                    Log.Warn("ExtractImage: Source {0} (resolved to path {1}) doesn't exists", source.GetDebugName(), source.GetPath());
                    WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                    return Stream.Null;
                }
    
                if (!source.SupportsDirectAccess)
                {
                    Log.Warn("ExtractImage: Extracting images from remote sources isn't supported yet", source.MediaType, source.Id);
                    WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotImplemented);
                    return Stream.Null;
                }
    
                // get temporary filename
                string filename = String.Format("extract_{0}_{1}.jpg", source.GetUniqueIdentifier(), position);
                string tempFile = cache.GetPath(filename);
    
                // maybe it exists in cache, return that then
                if (cache.Contains(filename))
                {
                    // if source is newer, cached image needs to be recreated
                    if (source.GetFileInfo().LastModifiedTime > cache.GetLastModifiedTime(tempFile))
                    {
                        cache.Invalidate(filename);
                    }
                    else
                    {
                        return StreamPostprocessedImage(new ImageMediaSource(tempFile), maxWidth, maxHeight, borders, format);
                    }
                }
    
                // We need to impersonate to access the network drive and check if the thumbnail already exists. However, because
                // impersonation is lost when starting a process, we can't start ffmpeg from in here. We need to check whether the
                // file is accessible from outside the impersonation context again, and start the ffmpeg process as a different user
                // if that is the case.
                string fullPath;
                using (var context = source.CreateNetworkContext())
                {
                    fullPath = context.RewritePath(source.GetPath());
    
                    // stream a pre-existing thumbnail, if possible
                    if (source.MediaType == WebMediaType.Recording && Path.GetExtension(fullPath).ToLower() == ".ts")
                    {
                        var thumbnailFileInfo = new FileInfo(Path.ChangeExtension(fullPath, ".jpg"));
                        if (thumbnailFileInfo.Exists && thumbnailFileInfo.Length > 0)
                            return StreamPostprocessedImage(new ImageMediaSource(thumbnailFileInfo.FullName), maxWidth, maxHeight, borders, format);
                    }
                }
    
                // finally, extract the image with ffmpeg if everything else has failed
                bool extractResult = ExecuteFFMpegExtraction(source, fullPath, position, tempFile);
                if (!extractResult)
                {
                    WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError);
                    return Stream.Null;
                }
    
                return StreamPostprocessedImage(new ImageMediaSource(tempFile), maxWidth, maxHeight, borders, format);
            }
    
            private static bool ExecuteFFMpegExtraction(MediaSource source, string path, long position, string tempFile)
            {
                var info = new ProcessStartInfo();
                info.Arguments = String.Format("-ss {0} -i \"{1}\" -vframes 1 -vf \"yadif,scale=ih*dar:ih\" -f image2 \"{2}\"", position, path, tempFile);
                info.FileName = Configuration.StreamingProfiles.FFMpegPath;
                info.CreateNoWindow = true;
                info.UseShellExecute = false;
                info.RedirectStandardError = Log.IsEnabled(LogLevel.Trace);
                info.RedirectStandardOutput = Log.IsEnabled(LogLevel.Trace);
    
                TranscoderProcess proc = new TranscoderProcess();
                proc.StartInfo = info;
                if (source.NeedsImpersonation)
                    proc.StartAsUser(Configuration.Services.NetworkImpersonation.Domain, Configuration.Services.NetworkImpersonation.Username, Configuration.Services.NetworkImpersonation.GetPassword());
                else
                    proc.Start();
    
                if (Log.IsEnabled(LogLevel.Trace))
                {
                    Log.Trace("ExtractImage: executing path={0} arguments={1}", info.FileName, info.Arguments);
                    StreamCopy.AsyncStreamRead(proc.StandardError, l => Log.Trace("ExtractImage: stderr: {0}", l));
                    StreamCopy.AsyncStreamRead(proc.StandardOutput, l => Log.Trace("ExtractImage: stdout: {0}", l));
                }
                proc.WaitForExit();
    
                if (!File.Exists(tempFile))
                {
                    Log.Warn("Failed to extract image from {0} with {1} {2}", source.GetDebugName(), info.FileName, info.Arguments);
                    return false;
                }
    
                return true;
            }
     

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    Haha, it's easier said than done. It's a Macbook Pro(with Win 10 as VM) that don't have a network port.
    Hehe, sounds like a Apple Fan^^ I don't know why Apple safes in the IO, I mean I also have a ultra Slim Samsung Ultrabook and you can just pop a LAN Port out so that it fits into the slim design...
    But bringing this adapter home is probably a good idea :D

    Reimport of Movies went fine.
    So Everything is working except the MediaInfo?
    I've attached a new version where I tried to add some more checks to GetMediaInfo. I couldn't reproduce it so maybe you can retry? No Reimport needed :D So should be a quick one^^

    but the video do not play when using the streaming url in video player in MPiV.
    This is the Exception:
    [2015-11-01 15:40:01,227] [21749111] [15 ] [ERROR] - MainRequestHandler: Exception:
    System.InvalidCastException: Unable to cast object of type 'MediaPortal.Extensions.ResourceProviders.NetworkNeighborhoodResourceProvider.NetworkNeighborhoodResourceAccessor' to type 'MediaPortal.Common.ResourceAccess.INetworkResourceAccessor'.
    at MediaPortal.Plugins.Transcoding.Service.Transcoders.FFMpeg.FFMpegCommandline.AddInputOptions(FFMpegTranscodeData& data) in d:\TeamCity\buildAgent\work\7c012272298dd9c7\MediaPortal\Incubator\TranscodingService\Transcoders\FFMpeg\FFMpegCommandline.cs:line 162
    at MediaPortal.Plugins.Transcoding.Service.Transcoders.FFMpeg.FFMpegCommandline.InitTranscodingParameters(IResourceAccessor sourceFile, FFMpegTranscodeData& data) in d:\TeamCity\buildAgent\work\7c012272298dd9c7\MediaPortal\Incubator\TranscodingService\Transcoders\FFMpeg\FFMpegCommandline.cs:line 154
    at MediaPortal.Plugins.Transcoding.Service.Transcoders.FFMpeg.FFMpegCommandline.ExtractSubtitleFile(VideoTranscoding video, SubtitleStream subtitle, String subtitleEncoding, String targetFilePath) in d:\TeamCity\buildAgent\work\7c012272298dd9c7\MediaPortal\Incubator\TranscodingService\Transcoders\FFMpeg\FFMpegCommandline.cs:line 273
    at MediaPortal.Plugins.Transcoding.Service.MediaConverter.GetSubtitle(VideoTranscoding video) in d:\TeamCity\buildAgent\work\7c012272298dd9c7\MediaPortal\Incubator\TranscodingService\MediaConverter.cs:line 1030
    at MediaPortal.Plugins.Transcoding.Service.MediaConverter.TranscodeVideoFile(VideoTranscoding video, Double timeStart, Double timeDuration, Boolean waitForBuffer) in d:\TeamCity\buildAgent\work\7c012272298dd9c7\MediaPortal\Incubator\TranscodingService\MediaConverter.cs:line 1289
    at MediaPortal.Plugins.Transcoding.Service.MediaConverter.GetMediaStream(BaseTranscoding transcodingInfo, Double timeStart, Double timeDuration, Boolean waitForBuffer) in d:\TeamCity\buildAgent\work\7c012272298dd9c7\MediaPortal\Incubator\TranscodingService\MediaConverter.cs:line 1225
    at MediaPortal.Plugins.MP2Extended.ResourceAccess.WSS.stream.Control.RetrieveStream.Process(IHttpRequest request, IHttpResponse response, IHttpSession session) in m:\Programmieren\C#\MediaPortal 2\MediaPortal\Incubator\MP2Extended\ResourceAccess\WSS\stream\Control\RetrieveStream.cs:line 216
    at MediaPortal.Plugins.MP2Extended.ResourceAccess.WSS.StreamingServiceStreamHandler.Process(IHttpRequest request, IHttpResponse response, IHttpSession session) in m:\Programmieren\C#\MediaPortal 2\MediaPortal\Incubator\MP2Extended\ResourceAccess\WSS\StreamingServiceStreamHandler.cs:line 54
    at MediaPortal.Plugins.MP2Extended.ResourceAccess.StreamingServiceHandler.Process(IHttpRequest request, IHttpResponse response, IHttpSession session) in m:\Programmieren\C#\MediaPortal 2\MediaPortal\Incubator\MP2Extended\ResourceAccess\StreamingServiceHandler.cs:line 35
    at MediaPortal.Plugins.MP2Extended.ResourceAccess.MainRequestHandler.Process(IHttpRequest request, IHttpResponse response, IHttpSession session) in m:\Programmieren\C#\MediaPortal 2\MediaPortal\Incubator\MP2Extended\ResourceAccess\MainRequestHandler.cs:line 139
    @henso looks also like a small Bug in the TranscodingService :)
     

    Attachments

    • MP2Extended.rar
      1.3 MB

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    Ah and if you would like to try streaming you must use a local file for now. Because of the InvalidCastException mentioned above streaming of files which are on a network share is not possible right now :)
     

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    @henso
    I guess it must bet something like this (from SlimTv):
    Code:
    else if (mediaItemAccessor is INetworkResourceAccessor)
          {
            using (var nra = (INetworkResourceAccessor)mediaItemAccessor.Clone())
            {
              info.Metadata.Source = nra;
            }
            info.Metadata.Size = 0;
          }
    What do you think?
     

    henso

    Development Group
  • Team MediaPortal
  • February 16, 2012
    2,341
    832
    Home Country
    Denmark Denmark
    In fact it does
    OK, but the input is a video file, correct? Video and audio files have no problem.

    For images a bug report was posted 4 years ago (https://trac.ffmpeg.org/ticket/819), so I don't think we will see it fixed anytime soon.
    There is the possibility to use short file names but if I recall correctly this will not work with network paths.
     

    johanj

    MP Donator
  • Premium Supporter
  • January 31, 2009
    781
    398
    47
    Home Country
    Sweden Sweden
    Much better, got quite a lot of mediainfo now. It's hard to tell if all is there but I guess audio/subs are not fully correct. Some exceptions in server log.
     

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    Much better, got quite a lot of mediainfo now. It's hard to tell if all is there but I guess audio/subs are not fully correct. Some exceptions in server log.
    Thanks! Another try. Line 60 is a nasty one :D

    OK, but the input is a video file, correct? Video and audio files have no problem.
    ah my bad. I thought it is a general problem...

    For images a bug report was posted 4 years ago (https://trac.ffmpeg.org/ticket/819), so I don't think we will see it fixed anytime soon.
    There is the possibility to use short file names but if I recall correctly this will not work with network paths.
    Hmm, don't really know how to proceed.
    FFMPeg does support byte streams a input, right? Or Named Pipes or soemthing like that? This could be a dirty way to pump the data into it (atleast for images). What do you think?
     

    Attachments

    • MP2Extended.rar
      1.3 MB

    Users who are viewing this thread

    Top Bottom