Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

H264 recording issues #762

@bijington

Description

@bijington

I have a Lenovo tablet with both a front and rear facing camera.

In my application I allow the user to choose from 3 different quality settings:
High - Largest resolution
Medium - Middle resolution
Low - Lowest resolution

Recording code:

private void StartRecording()
{
    int framesPerSecond = Math.Min(this.videoSource.VideoResolution.MaximumFrameRate, 10);
    int gopSize = 12;
    int bitRate = ((this.videoSource.VideoResolution.FrameSize.Width * 
    this.videoSource.VideoResolution.FrameSize.Height) * framesPerSecond);

    this.videoFileWriter.Open(this.OutputFilePath,
                                    this.videoSource.VideoResolution.FrameSize.Width,
                                    this.videoSource.VideoResolution.FrameSize.Height,
                                    framesPerSecond,
                                    VideoCodec.H264,
                                    bitRate);
                
    this.isRecordingVideo = true;
}

private void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    try
    {
        if (this.isRecordingVideo)
        {
            lock (this.videoWriterLock)
            {
                // Exception is thrown here
                this.videoFileWriter?.WriteVideoFrame((Bitmap)eventArgs.Frame.Clone());
            }
        }
    }
}

Using v3.6.0 and the above code I can happily record from all the above resolutions on the rear camera using H264 codec however when it comes to the front camera I can only record at the lowest resolution, using Medium or High I receive the following exception:

Exception Info: System.AccessViolationException
   at <Module>.sws_scale(libffmpeg.SwsContext*, Byte**, Int32*, Int32, Int32, Byte**, Int32*)
   at Accord.Video.FFMPEG.VideoFileWriter.WriteVideoFrame(System.Drawing.Bitmap, UInt32)
   at Accord.Video.FFMPEG.VideoFileWriter.WriteVideoFrame(System.Drawing.Bitmap)
   at MyProject.Video.AccordCamReader.videoSource_NewFrame(System.Object, Accord.Video.NewFrameEventArgs)
   at Accord.Video.DirectShow.VideoCaptureDevice.OnNewFrame(System.Drawing.Bitmap)
   at Accord.Video.DirectShow.VideoCaptureDevice+Grabber.BufferCB(Double, IntPtr, Int32)

Now as far as I can tell the frames coming back are matching the resolution as indicated by the selected resolution and I have been able to write this image out to disk in order to verify that. Note that recording MPEG4 with the higher resolutions on the same faulting camera work correctly.

In case it helps the tablet is running Windows 10 64 bit but my build is a 32 bit application.

My issue with the above obviously aside from the exception is that I am unable to determine whether the camera or Accord supports the certain qualities and therefore disable the relevant options unless I am missing anything?

I haven't had a chance to yet and really hope I don't need to delve down in to the swscale code. Are there any issues around this area that you are aware of?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions