Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading MP4 via FFMpeg results in DelegateFailed. #312

Closed
2 tasks done
michaelkrog opened this issue Sep 17, 2018 · 17 comments
Closed
2 tasks done

Reading MP4 via FFMpeg results in DelegateFailed. #312

michaelkrog opened this issue Sep 17, 2018 · 17 comments

Comments

@michaelkrog
Copy link

michaelkrog commented Sep 17, 2018

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am using the latest version of Magick.NET

Question

How should I read an image from an MP4 file?

I tried to look for answers and the best result I have come to is this:

using (var image = new MagickImage(input, new MagickReadSettings { Format = MagickFormat.Mp4 }))
{
    image.Resize(.........
}

But the result I get is this:

ImageMagick.MagickDelegateErrorException: DelegateFailed `'ffmpeg' -nostdin -v -1 -vframes %S -i '%i' -vcodec pam -an -f rawvideo -y '%u.pam' 2> '%Z'' @ error/delegate.c/InvokeDelegate/1844
   at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result)
   at ImageMagick.MagickImage.NativeMagickImage.ReadStream(MagickSettings settings, ReadWriteStreamDelegate reader, SeekStreamDelegate seeker, TellStreamDelegate teller)
   at ImageMagick.MagickImage.Read(Stream stream, MagickReadSettings readSettings, Boolean ping)
.......

If I run the command line directly in a terminal, then I get this:

$ ffmpeg  -vframes 1 -i input.mp4 -vcodec pam -an -f rawvideo -y out.png

Option vframes (set the number of video frames to output) cannot be applied to input url /Users/michael/Downloads/502017872_D_cnt_1_r240P.mp4 -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
@dlemstra
Copy link
Owner

It looks like you are using the default build in configuration under Linux and I think we need to update the delegate.c file with the latest configuration. This will also require a new Magick.NET release. I will delay the release until this has been resolved inside ImageMagick.

@michaelkrog
Copy link
Author

Thanx.

I am on Mac os using Magick.Net 7.7.0 with FFMpeg 4.0.2 installed.

@dlemstra
Copy link
Owner

I just published Magick.NET 7.8.0.0 that includes a fix for your issue.

@michaelkrog
Copy link
Author

That is awesome.. I will test it tomorrow..

@michaelkrog
Copy link
Author

Hi..
It still didnt work. I will dig into details about the error within the next few days, and get back to you..

@dlemstra
Copy link
Owner

You probably need to install avconv instead of ffmpeg because that seems to be the default now.

@michaelkrog
Copy link
Author

I did try to install avconv via brew install libav but to no avail.

This is the exception in get in C#:

 An unhandled exception has occurred while executing the request.
ImageMagick.MagickDelegateErrorException: DelegateFailed `'avconv' -nostdin -v -1 -i '%i' -vframes %S -vcodec pam -an -f rawvideo -y '%u.pam' 2> '%u'' @ error/delegate.c/InvokeDelegate/1860
   at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result)
   at ImageMagick.MagickImage.NativeMagickImage.ReadStream(MagickSettings settings, ReadWriteStreamDelegate reader, SeekStreamDelegate seeker, TellStreamDelegate teller)
   at ImageMagick.MagickImage.Read(Stream stream, MagickReadSettings readSettings, Boolean ping)
   at Server.Util.Thumbnail.FromMP4(Stream input, Stream output, ImageSizeRequest sizeRequest) in /Users/michael/Development/Meps/Synapsys/Server/Util/Thumbnail.cs:line 47
   at Server.Services.BlobService.GetBlobAsImage(String containerName, String id, ImageSizeRequest sizeRequest) in /Users/michael/Development/Meps/Synapsys/Server/Services/BlobService.cs:line 83
   at Server.Services.BlobService.GetBlob(String containerName, String filename) in /Users/michael/Development/Meps/Synapsys/Server/Services/BlobService.cs:line 45
   at Server.Controllers.ItemController.FindNoteMediaFile(String itemId, String noteId, String filename) in /Users/michael/Development/Meps/Synapsys/Server/Controllers/Rest/ItemController.cs:line 100
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Synapsys.Startup.<>c.<<Configure>b__5_0>d.MoveNext() in /Users/michael/Development/Meps/Synapsys/Server/Startup.cs:line 90
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error: An unhandled exception has occurred while executing the request.

But running it from CLI seems to work:

$ avconv -i nwtsv_D_430_r480P.mp4 -vframes 1 -vcodec pam -an -f rawvideo screenshot.png
avconv version 12.3, Copyright (c) 2000-2018 the Libav developers
  built on Feb 13 2018 11:17:07 with Apple LLVM version 9.0.0 (clang-900.0.39.2)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ffdc2808600] overread end of atom 'colr' by 1 bytes
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ffdc2808600] max_analyze_duration 5000000 reached
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'nwtsv_D_430_r480P.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2018-06-18 12:09:41
    title           : Introduktion til Johannes
    artist          : Watch Tower Bible and Tract Society of PA
    album           : Introduktionsfilm til bibelbøger
    track           : 43
    copyright       : © 2017 Watch Tower Bible and Tract Society of Pennsylvania          Danish
  Duration: 00:04:50.48, start: 0.000000, bitrate: 1138 kb/s
    Stream #0:0(eng): Audio: aac (LC) [mp4a / 0x6134706D]
      44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2018-06-18 12:09:41
      handler_name    : Core Media Audio
    Stream #0:1(und): Video: h264 (Baseline) [avc1 / 0x31637661]
      yuv420p, tv, smpte170m/smpte170m/bt709
      854x480 [PAR 1:1 DAR 427:240], 1002 kb/s, PAR 1:1 DAR 427:240
      29.97 fps, 30k tbn (default)
    Metadata:
      creation_time   : 2018-06-18 12:09:41
      handler_name    : Core Media Video
    Stream #0:2: Video: png
      bgra, pc, 600x600
      90k tbn
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> pam (native))
Press ctrl-c to stop encoding
Output #0, rawvideo, to 'screenshot.png':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2018-06-18 12:09:41
    title           : Introduktion til Johannes
    artist          : Watch Tower Bible and Tract Society of PA
    album           : Introduktionsfilm til bibelbøger
    track           : 43
    copyright       : © 2017 Watch Tower Bible and Tract Society of Pennsylvania          Danish
    encoder         : Lavf57.7.2
    Stream #0:0(und): Video: pam
      rgb24, 854x480 [PAR 1:1 DAR 427:240], q=2-31, 200 kb/s, PAR 1:1 DAR 427:240
      30k tbn (default)
    Metadata:
      creation_time   : 2018-06-18 12:09:41
      handler_name    : Core Media Video
      encoder         : Lavc57.25.0 pam
frame=    1 fps=  0 q=-0.0 Lsize=    1201kB time=10000000000.00 bitrate=   0.0kbits/s    
video:1201kB audio:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

@michaelkrog
Copy link
Author

@dlemstra I never managed to get it to work via Magick.NET even though it works fine from the CLI. Is there any way I can dig up more details for this issue?

@dlemstra
Copy link
Owner

The problem is that we don't have an error message here. It looks like error messages are directed to the a file but I am not sure why we don't get those. I don't own a MAC so I cannot test this myself easily. Have you tried executing this:

'avconv' -nostdin -v -1 -i 'nwtsv_D_430_r480P.mp4' -vframes 1 -vcodec pam -an -f rawvideo -y 'out.pam'` 2> out

@michaelkrog
Copy link
Author

Ahaaa...

$ 'avconv' -nostdin -v -1 -i 'nwtsv_D_430_r480P.mp4' -vframes 1 -vcodec pam -an -f rawvideo -y 'out.pam' 
avconv version 12.3, Copyright (c) 2000-2018 the Libav developers
  built on Feb 13 2018 11:17:07 with Apple LLVM version 9.0.0 (clang-900.0.39.2)
Unrecognized option 'nostdin'.
Error splitting the argument list: Option not found

@dlemstra
Copy link
Owner

Could you research for me what happened with the nostdin option?

@michaelkrog
Copy link
Author

Okay. I am unsure if I know precisely what nostdin is for, but I understand it to be a flag forcing it to require nothing from standard in.

Looking into the docs of libav, it seems to me like it does not require anything from stdin and should work without any similar flag.

@dlemstra
Copy link
Owner

Thanks for looking into this. I think it might be better to remove that flag. Does the command that I gave you earlier work without the -nostdin?

@michaelkrog
Copy link
Author

Sorry for taking so long. (Only working on this project twice a week).
I can confirm it works without it.

Original command:

$ 'avconv' -nostdin -v -1 -i 'nwtsv_D_430_r480P.mp4' -vframes 1 -vcodec pam -an -f rawvideo -y 'out.pam'
avconv version 12.3, Copyright (c) 2000-2018 the Libav developers
  built on Feb 13 2018 11:17:07 with Apple LLVM version 9.0.0 (clang-900.0.39.2)
Unrecognized option 'nostdin'.
Error splitting the argument list: Option not found

Without -stdin:

$ 'avconv' -v -1 -i 'nwtsv_D_430_r480P.mp4' -vframes 1 -vcodec pam -an -f rawvideo -y 'out.pam' 
$

Without -stdin and increased verbosity:

$ 'avconv' -i 'nwtsv_D_430_r480P.mp4' -vframes 1 -vcodec pam -an -f rawvideo -y 'out.pam' 
avconv version 12.3, Copyright (c) 2000-2018 the Libav developers
  built on Feb 13 2018 11:17:07 with Apple LLVM version 9.0.0 (clang-900.0.39.2)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc5dd801200] overread end of atom 'colr' by 1 bytes
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc5dd801200] max_analyze_duration 5000000 reached
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'nwtsv_D_430_r480P.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2018-06-18 12:09:41
    title           : Introduktion til Johannes
    artist          : Watch Tower Bible and Tract Society of PA
    album           : Introduktionsfilm til bibelbøger
    track           : 43
    copyright       : © 2017 Watch Tower Bible and Tract Society of Pennsylvania          Danish
  Duration: 00:04:50.48, start: 0.000000, bitrate: 1138 kb/s
    Stream #0:0(eng): Audio: aac (LC) [mp4a / 0x6134706D]
      44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2018-06-18 12:09:41
      handler_name    : Core Media Audio
    Stream #0:1(und): Video: h264 (Baseline) [avc1 / 0x31637661]
      yuv420p, tv, smpte170m/smpte170m/bt709
      854x480 [PAR 1:1 DAR 427:240], 1002 kb/s, PAR 1:1 DAR 427:240
      29.97 fps, 30k tbn (default)
    Metadata:
      creation_time   : 2018-06-18 12:09:41
      handler_name    : Core Media Video
    Stream #0:2: Video: png
      bgra, pc, 600x600
      90k tbn
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> pam (native))
Press ctrl-c to stop encoding
Output #0, rawvideo, to 'out.pam':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2018-06-18 12:09:41
    title           : Introduktion til Johannes
    artist          : Watch Tower Bible and Tract Society of PA
    album           : Introduktionsfilm til bibelbøger
    track           : 43
    copyright       : © 2017 Watch Tower Bible and Tract Society of Pennsylvania          Danish
    encoder         : Lavf57.7.2
    Stream #0:0(und): Video: pam
      rgb24, 854x480 [PAR 1:1 DAR 427:240], q=2-31, 200 kb/s, PAR 1:1 DAR 427:240
      30k tbn (default)
    Metadata:
      creation_time   : 2018-06-18 12:09:41
      handler_name    : Core Media Video
      encoder         : Lavc57.25.0 pam
frame=    1 fps=  0 q=-0.0 Lsize=    1201kB time=10000000000.00 bitrate=   0.0kbits/s    
video:1201kB audio:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

@dlemstra
Copy link
Owner

Decided to remove the option in the ImageMagick library. This should be resolved in the next release.

@dlemstra
Copy link
Owner

@michaelkrog Can you give it another try with the latest release?

@michaelkrog
Copy link
Author

michaelkrog commented Nov 28, 2018

It works! :)

Now my next issue is how to get a specific frame. (The first frame is almost always black in a pro video).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants