Giter Site home page Giter Site logo

ruslan-b / ffmpeg.autogen Goto Github PK

View Code? Open in Web Editor NEW
1.3K 68.0 307.0 604.52 MB

FFmpeg auto generated unsafe bindings for C#/.NET and Core (Linux, MacOS and Mono).

License: GNU Lesser General Public License v3.0

C# 74.70% C 25.27% PowerShell 0.03%
ffmpeg mono c-sharp osx linux

ffmpeg.autogen's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffmpeg.autogen's Issues

Wrong channel layout flags

The channel layout flags like "AV_CH_LAYOUT_STEREO" get generated wrongly as zero. In the FFmpeg source code they are set using a bitwise or of other flags like "AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT" in the case of stereo. Anyway, thank you for this great wrapper!

Encode2Stream

First of all. Great project and I think this is the latest .NET ffmpeg project.

I am new to ffmpeg and was wondering if FFmpeg.AutoGen is able to encode to stream. I would like to read a local file (c:\temp\file.mkv),
encode it into streams then live stream it to a client. The request would go through via MVC WebApi with headers that specify resolution to encode etc..

Any examples would be appreciated.

Thanks,
AL

avio_alloc_context method signature and also uint8_t type

Thanks for the 2.8.3 update (it also works with 2.8.4). I am not sure if it's an error or not but I found that some type conversions are different from the ones you generated before using Clang generation (old FFmpegInvoke).

For example avio_alloc_context function is generated with IntPtr* type for parameters read_packet, write_packet and seek:

public static extern AVIOContext* avio_alloc_context(
    sbyte* @buffer, 
    int @buffer_size, 
    int @write_flag, 
    void* @opaque, 
    IntPtr* @read_packet, 
    IntPtr* @write_packet, 
    IntPtr* @seek);

I changed IntPtr* to IntPtr and it worked ok with my existing code, otherwise it required casting. I did not test if it would work if I did the casting though. The original function signature in the header is

AVIOContext *avio_alloc_context(
                  unsigned char *buffer,
                  int buffer_size,
                  int write_flag,
                  void *opaque,
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));

so I mean IntPtr is already a pointer and IntPtr* seems redundant or wrong in this case?

Also I noticed a change with uint8_t, before Clang it was converted to byte but now to sbyte:

internal static extern int sws_scale(
    SwsContext* @c, 
    sbyte** @srcSlice, 
    int* @srcStride, 
    int @srcSliceY, 
    int @srcSliceH, 
    sbyte** @dst, 
    int* @dstStride);

The original function signature in the header is

int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],
              const int srcStride[], int srcSliceY, int srcSliceH,
              uint8_t *const dst[], const int dstStride[]);

Again this also works ok as it is but I think uint8_t is unsigned and sbyte is "signed byte".

Not sure if these would cause problems in future or if they are even considered errors, just documenting differences and letting you know.

replace intptr with StringBuilder in avutil.g.cs

In avutil.g.cs, should be

    [DllImport(libavutil, EntryPoint = "av_log_format_line", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern void av_log_format_line(void* @ptr, int @level, [MarshalAs(UnmanagedType.LPStr)] string @fmt, sbyte* @vl, StringBuilder @line, int @line_size, int* @print_prefix);
    
    [DllImport(libavutil, EntryPoint = "av_log_format_line2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern int av_log_format_line2(void* @ptr, int @level, [MarshalAs(UnmanagedType.LPStr)] string @fmt, sbyte* @vl, StringBuilder @line, int @line_size, int* @print_prefix);

Wrong signature for: av_get_channel_layout_string

av_get_channel_layout_string is supposed to write the found channel layout into buf, which doesn't work for me with the given signature:

// Action<String, int, int, ulong>
[DllImport(AVUTIL_LIBRARY, EntryPoint="av_get_channel_layout_string", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern void av_get_channel_layout_string(String buf, int buf_size, int nb_channels, ulong channel_layout);

After changing the code to:

// Action<String, int, int, ulong>
[DllImport(AVUTIL_LIBRARY, EntryPoint = "av_get_channel_layout_string", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern void av_get_channel_layout_string(sbyte* buf, int buf_size, int nb_channels, ulong channel_layout);

the channel layout can be retrieved easily via:

public static String av_get_channel_layout_string(int nb_channels, ulong channel_layout)
{
    int len = 20;
    sbyte[] buffer = new sbyte[len];

    fixed (sbyte* buf = buffer)  {
        av_get_channel_layout_string(buf, len, nb_channels, channel_layout);

        return new String(buf);
    }
}

Green color shift encoding RGBA to YUV420p

Hi,

I was wondering If you could help. I'm currently taking converting RBGA bitmaps to YUV420p before encoding the frames with h264 codec and dumping the encoded packets to file successfully.

I'm also able to playback the h264 video file in VLC. However, there seems to be a color shift which is more apparent where grey is actually light tint of screen. I'm used a an animation video as my example which is supposed to show a blue sky in the background, however after converting the image, I'm getting an orange sky background. Do you have any ideas how I can fix this please?

Thanks Michael

var ctx = ffmpeg.sws_getContext(
c->width,
c->height,
AVPixelFormat.AV_PIX_FMT_RGBA,
c->width,
c->height,
AVPixelFormat.AV_PIX_FMT_YUV420P,
ffmpeg.SWS_FAST_BILINEAR,
null,
null,
null);

/inData is a pointer to rgb32data pulled from bitmap using lockbits/
ffmpeg.sws_scale(ctx, inData, inLineSize, 0, c->height, frame->data, frame->linesize);

Do you happen to know if it's possible to convert rgba to yuv BEFORE calling sws_scale and before encoding packet?

change the inputs for ffmpeg

I thank you for your great effort to create very useful plugin. the example you given is generating 100 frames but those are continuous.

I want something like where it generates random meaningful thumbnails, I am little confuse where the code written for giving input to ffmpeg command.

I want to use commands like:
https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video

Can you please refer stackoverflow answer here:
http://superuser.com/questions/538112/meaningful-thumbnails-for-a-video-using-ffmpeg

if you provide example for that, that would be great help for me.

Thank you :-)

Generate new version

Hello Ruslan,

I've been using your library for a little while but today, I need to use a newer version of libav.
I downloaded the packages at Zeranoe and replaced the bin & include folders.
When I try to generate the new .cs file using the python script, this error got raised (which was not raised with the older version) :

Status: Preprocessing d:\temp\tmpv8qtyr.h
Status: gcc -v -E -U GNUC -dD -I./FFmpeg/include "-Dinline=" "-D__inline__=" "-D__extension__=" "-D__const=const" "-D__asm__(x)=" "-D__asm(x)=" "-DCTYPESGEN=1" "d:\temp\tmpv8qtyr.h"
Error: gcc -v -E: Using built-in specs.
Error: gcc -v -E: COLLECT_GCC=gcc
Error: gcc -v -E: Target: mingw32
Error: gcc -v -E: Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Error: gcc -v -E: Thread model: win32
Error: gcc -v -E: gcc version 4.8.1 (GCC)
Error: gcc -v -E: COLLECT_GCC_OPTIONS='-v' '-E' '-U' 'GNUC' '-dD' '-I' './FFmpeg/include' '-D' 'inline=' '-D' 'inline=' '-D' 'extension=' '-D' 'const=const' '-D' '__asm(x)=' '-D' 'asm(x)=' '-D' 'CTYPESGEN=1' '-mtune=generic' '-march=pentiumpro'
Error: gcc -v -E: c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1.exe -E -quiet -v -I ./FFmpeg/include -iprefix c:\mingw\bin../lib/gcc/mingw32/4.8.1/ -U __GNUC
-D inline= -D inline= -D extension= -D const=const -D __asm(x)= -D asm(x)= -D CTYPESGEN=1 d:\temp\tmpv8qtyr.h -mtune=generic -march=pentiumpro -dD
Error: gcc -v -E: ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
Error: gcc -v -E: ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
Error: gcc -v -E: ignoring duplicate directory "/mingw/include"
Error: gcc -v -E: ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
Error: gcc -v -E: ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
Error: gcc -v -E: ignoring duplicate directory "/mingw/include"
Error: gcc -v -E: #include "..." search starts here:
Error: gcc -v -E: #include <...> search starts here:
Error: gcc -v -E: ./FFmpeg/include
Error: gcc -v -E: c:\mingw\bin../lib/gcc/mingw32/4.8.1/include
Error: gcc -v -E: c:\mingw\bin../lib/gcc/mingw32/4.8.1/../../../../include
Error: gcc -v -E: c:\mingw\bin../lib/gcc/mingw32/4.8.1/include-fixed
Error: gcc -v -E: c:\mingw\bin../lib/gcc/mingw32/4.8.1/../../../../mingw32/include
Error: gcc -v -E: End of search list.
Error: gcc -v -E: COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/
Error: gcc -v -E: LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../
Error: gcc -v -E: COLLECT_GCC_OPTIONS='-v' '-E' '-U' '__GNUC
' '-dD' '-I' './FFmpeg/include' '-D' 'inline=' '-D' 'inline=' '-D' 'extension=' '-D' 'const=const' '-D' '__asm(x)=' '-D' 'asm(x)=' '-D' 'CTYPESGEN=1' '-mtune=generic' '-march=pentiumpro'
Status: Parsing d:\temp\tmpv8qtyr.h
Error: c:\mingw\include\inttypes.h:275: Syntax error at 'nptr'
Error: c:\mingw\include\inttypes.h:276: Syntax error at 'endptr'
Error: c:\mingw\include\inttypes.h:277: Syntax error at 'nptr'
Error: c:\mingw\include\inttypes.h:278: Syntax error at 'endptr'
Error: c:\mingw\include\inttypes.h:280: Syntax error at 'nptr'
Error: c:\mingw\include\inttypes.h:281: Syntax error at 'endptr'
Error: c:\mingw\include\inttypes.h:282: Syntax error at 'nptr'
Error: c:\mingw\include\inttypes.h:283: Syntax error at 'endptr'
Error: c:\mingw\lib\gcc\mingw32\4.8.1\include\stdarg.h:40: Syntax error at '__gnuc_va_list'
Error: c:\mingw\include\sys\types.h:27: Syntax error at '__time32_t'
Error: c:\mingw\include\stdlib.h:313: Syntax error at '__nptr'
Error: c:\mingw\include\stdlib.h:313: Syntax error at '__endptr'
Error: c:\mingw\include\stdlib.h:427: Syntax error at 'atoi64'
Error: c:\mingw\include\stdlib.h:428: Syntax error at 'char'
Error: c:\mingw\include\stdlib.h:430: Syntax error at 'wtoi64'
Error: c:\mingw\include\stdlib.h:431: Syntax error at 'wchar_t'
Error: c:\mingw\lib\gcc\mingw32\4.8.1\include\stdarg.h:98: Syntax error at 'va_list'
Error: ./FFmpeg/include/libavutil/log.h:246: Syntax error at 'va_list'
Error: ./FFmpeg/include/libavutil/log.h:276: Syntax error at 'va_list'
Error: ./FFmpeg/include/libavutil/log.h:292: Syntax error at 'va_list'
Error: ./FFmpeg/include/libavutil/log.h:311: Syntax error at 'va_list'
Error: ./FFmpeg/include/libavutil/log.h:312: Syntax error at 'int'
Error: ./FFmpeg/include/libavutil/log.h:312: Syntax error at ')'
Error: c:\mingw\include\time.h:102: Syntax error at 'time'
Error: c:\mingw\include\time.h:104: Syntax error at 'mktime'
Error: c:\mingw\include\time.h:119: Syntax error at '
'
Error: c:\mingw\include\time.h:120: Syntax error at '
'
Error: c:\mingw\include\time.h:121: Syntax error at ''
Error: c:\mingw\include\time.h:252: Syntax error at '
'
Status: Processing description list.
Traceback (most recent call last):
File "C:\Users\Booster\Desktop\Bar\FFmpeg.AutoGen-master\FFmpeg.AutoGen-master\generate.py", line 512, in
ctypesgencore.processor.process(descriptions, options)
File "C:\Users\Booster\Desktop\Bar\FFmpeg.AutoGen-master\FFmpeg.AutoGen-master\ctypesgencore\processor\pipeline.py", line 53, in process
find_source_libraries(data,options)
File "C:\Users\Booster\Desktop\Bar\FFmpeg.AutoGen-master\FFmpeg.AutoGen-master\ctypesgencore\processor\operations.py", line 191, in find_source_libraries
library=ctypesgencore.libraryloader.load_library(library_name)
File "C:\Users\Booster\Desktop\Bar\FFmpeg.AutoGen-master\FFmpeg.AutoGen-master\ctypesgencore\libraryloader.py", line 239, in load_library
result = LibraryLoader.load_library(self, libname)
File "C:\Users\Booster\Desktop\Bar\FFmpeg.AutoGen-master\FFmpeg.AutoGen-master\ctypesgencore\libraryloader.py", line 56, in load_library
return self.load(path)
File "C:\Users\Booster\Desktop\Bar\FFmpeg.AutoGen-master\FFmpeg.AutoGen-master\ctypesgencore\libraryloader.py", line 260, in load
return _WindowsLibrary(path)
File "C:\Users\Booster\Desktop\Bar\FFmpeg.AutoGen-master\FFmpeg.AutoGen-master\ctypesgencore\libraryloader.py", line 224, in __init

self.cdll = ctypes.cdll.LoadLibrary(path)
File "C:\Python27\lib\ctypes__init__.py", line 443, in LoadLibrary
return self.dlltype(name)
File "C:\Python27\lib\ctypes__init
_.py", line 365, in init
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 n’est pas une application Win32 valide // [Error 193] %1 is not a valid Win32 application

If you could help me with that, I would be pleased :)

License for the generated files?

Hi, thanks for this wonderful tool. We now have a project which is using the output from this tool, and we want to publish it to NuGet by either MS-Pl or MIT(discussion here). One remaining block ahead is the license issue: we are not sure about the license of the output from your AutoGen program because the output of a GPL program is not automatically protected by GPL. Therefore could you add a license to the generated file, so we'll know how to use it correctly?

Thanks!

Distributing FFmpeg.AutoGen

Hi,

I am quite new to this library but currently I have the example working fine. I was thinking of maybe integrating the library into a C# project, though I am unsure as to how I would distribute it.

I am planning on thinking of using the 32-bit FFmpeg DLLs so that it would run on both 32-bit and 64-bit computers however would I need to provide compiled 32-bit and 64-bit version's of the FFmpeg.AutoGen DLL?

Thank you.

Generate.py on Windows

Hi Ruslan-B,

First of all, congratulations for the great work.
I'm trying to run the generate.py on Windows 8, with no success. Can you help me?

Tried to use this stack:
MingW: Latest version from their website. mingw32-base 2013072200. GCC version is 4.8.1.
Python: Version 2.7.6 (also the latest stable). Comes with ctypes 1.1.0 by default.

Output:
Status: Preprocessing c:\users\wagner\appdata\local\temp\tmpesd5dv.h
Status: gcc -E -U GNUC -dD -I./FFmpeg/include "-Dinline=" "-D__inline__=" "-D__extension__=" "-D_Bool=uint8_t" "-D__const=const" "-D__asm__(x)=" "-D__asm(x)=" "-DCTYPESGEN=1" c:\users\wagner\appdata\local\temp\tmpesd5dv.h
Error: gcc -E: In file included from c:\mingw\include\errno.h:27:0,
Error: gcc -E: from D:\FFMpeg.AutoGen\FFmpeg.AutoGen\FFmpeg\include\libavcodec\avcodec.h:30,
Error: gcc -E: from c:\users\wagner\appdata\local\temp\tmpesd5dv.h:1:
Error: gcc -E: c:\mingw\include_mingw.h:51:2: error: #error ERROR: You must use a GNU Compiler.
Error: gcc -E: #error ERROR: You must use a GNU Compiler.
Error: gcc -E: ^
Error: gcc -E: In file included from c:\mingw\include\errno.h:27:0,
Error: gcc -E: from D:\FFMpeg.AutoGen\FFmpeg.AutoGen\FFmpeg\include\libavcodec\avcodec.h:30,
Error: gcc -E: from c:\users\wagner\appdata\local\temp\tmpesd5dv.h:1:
Error: gcc -E: c:\mingw\include_mingw.h:55:2: error: #error ERROR: You must use a GNU Compiler version >= 3.4.5.
Error: gcc -E: #error ERROR: You must use a GNU Compiler version >= 3.4.5.
Error: gcc -E: ^
Status: Parsing c:\users\wagner\appdata\local\temp\tmpesd5dv.h
Error: c:\mingw\include\errno.h:107: Syntax error at '('
Error: c:\mingw\include\errno.h:107: Syntax error at ';'
Error: c:\mingw\include\inttypes.h:299: Syntax error at '('
Error: c:\mingw\include\inttypes.h:299: Syntax error at ';'
...

I've tried to downgrade ctypes to 1.0.2, as you required. But after installing it, I get the following error:
Exception: ('Version number mismatch', '1.0.2', '1.1.0').

I'm not sure if it is possible to have 2 versions of this ctypes package installed in Python.

Thanks in advance,

Wagner.

Some changes/additions I had to make

Great wrapper Ruslan!

public static unsafe partial class FFmpegInvoke
{
    [DllImport(AVUTIL_LIBRARY, EntryPoint = "av_image_alloc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern int av_image_alloc(byte*[] pointers, int[] linesizes, int w, int h, AVPixelFormat pix_fmt, int align);

    [DllImport(AVUTIL_LIBRARY, EntryPoint = "av_image_copy", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern void av_image_copy(byte*[] pointers, int[] linesizes, byte** src_data, int* src_linesizes, AVPixelFormat pix_fmt, int width, int height);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate int AVIOInterruptCBDelegate(void* opaque);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void AVLogCBDelegate(void* avcl, int level, string fmt, void* vl);

Crashing on close

FFmpegInvoke.avformat_close_input(&pFormatcurrent);
causes a crash.
I am u using ffmpeg.autogen.dll in unity to decode a stream and then output. well the decoding and output works good but after the operation when i do close_input the application freezes.

example code fails to release packets

The example code has a bad memory leak: it fails to release the frame packets. I have that fixed in my working code, which I've included below. In the spirit of reposting your modified MIT code, feel free to pull from that code to update your examples. It comes as complements of ASI (http://asirobots.com/), who is looking for more software engineers at the moment.

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Asi.Common.Native;
using Asi.Common.Logging;
using Asi.Shared.Interfaces.Cameras;
using FFmpeg.AutoGen;

namespace Asi.FFmpegWrapper
{
    public enum DetectedPixelFormat { Bgr24 }

    public interface IDetectedImageDimensions
    {
        int Width { get; }
        int Height { get; }
        DetectedPixelFormat Format { get; }
        int Linesize { get; }
    }

    public interface IFrameReceptical
    {
        IntPtr Buffer { get; }

        void Refresh(int width, int height);

        void Write(int width, int height, IntPtr data, int stride);
    }


    public interface IFrameGrabber
    {
        Task<bool> WriteFrameToFile(string url, string filename);
    }

    public class FrameGrabberWrapper : IFrameGrabber
    {
        public Task<bool> WriteFrameToFile(string url, string filename)
        {
            return FrameGrabber.WriteFrameToFile(url, filename);
        }
    }

    [ExcludeFromCodeCoverage]
    public static class FrameGrabber
    {
        private static readonly Logger _logger = new Logger(typeof(FrameGrabber));

        [DllImport("kernel32.dll", SetLastError = true)]
        private static extern bool SetDllDirectory(string lpPathName);

        [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
        private static extern void CopyMemory(IntPtr destination, IntPtr source, int length);


        static FrameGrabber()
        {
            var folder = IntPtr.Size > 4 ? "x64" : "x32";
            var location = typeof(FrameGrabber).Assembly.Location;
            SetDllDirectory(Path.Combine(Path.GetDirectoryName(location), folder)); // do we need to set it back after all the libraries are loaded?

            // I like the LoadLibrary approach better, but it wasn't working
            //LoadLibrary(Path.Combine(pth, FFmpegInvoke.AVFORMAT_LIBRARY));
            //LoadLibrary(Path.Combine(pth, FFmpegInvoke.AVCODEC_LIBRARY));
            //LoadLibrary(Path.Combine(pth, FFmpegInvoke.AVDEVICE_LIBRARY));
            //LoadLibrary(Path.Combine(pth, FFmpegInvoke.AVFILTER_LIBRARY));
            //LoadLibrary(Path.Combine(pth, FFmpegInvoke.AVUTIL_LIBRARY));
            //LoadLibrary(Path.Combine(pth, FFmpegInvoke.SWSCALE_LIBRARY));

            ffmpeg.av_register_all();
            ffmpeg.avcodec_register_all();
            ffmpeg.avformat_network_init();
        }

        private class DetectedImageDimensions : IDetectedImageDimensions
        {
            public int Width { get; internal set; }
            public int Height { get; internal set; }
            public DetectedPixelFormat Format { get; internal set; }
            public int Linesize { get; internal set; }
        }

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private unsafe delegate int AvioInterruptCbDelegate(void* opaque);

#if DEBUG_VIDEO
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private unsafe delegate void AvioLogDelegate(void* opaque, int level, string message, RuntimeArgumentHandle stringFormatArgs);
#endif
        /// <summary>
        /// Return false in the callback to stop.
        /// Taken from https://github.com/Ruslan-B/FFmpeg.AutoGen/blob/master/FFmpeg.AutoGen.Example/Program.cs
        /// </summary>
        public static unsafe Task CreateVideoStream(string url, CancellationToken token, Func<IDetectedImageDimensions, IFrameReceptical> writableBitampCreationCallback, Action<bool, CameraErrors> isConnected)
        {
            var taskSource = new TaskCompletionSource<bool>();
            var thread = new Thread(() =>
            {
#if DEBUG_VIDEO
                var logDel = new AvioLogDelegate((opaque, level, message, args) =>
                {
                    int i = 0;
                    Debug.WriteLine(Regex.Replace(message, "%.", m => "{" + ++i + "}"), ToObjectArray(args));
                });
                var logDelPointer = Marshal.GetFunctionPointerForDelegate(logDel);
                ffmpeg.av_log_set_callback(logDelPointer);
#endif
                IFrameReceptical receptical = null;
                AVFormatContext* pFormatContext = ffmpeg.avformat_alloc_context();
                pFormatContext->flags |= ffmpeg.AVFMT_FLAG_NOBUFFER | ffmpeg.AVFMT_FLAG_DISCARD_CORRUPT;
                pFormatContext->avio_flags |= ffmpeg.AVIO_FLAG_DIRECT;
                pFormatContext->probesize = 1000000; // about 1MB (default is 5MB)
                AVDictionary* avDict = null;
                ffmpeg.av_dict_set(&avDict, "allowed_media_types", "video", 0); // don't return audio streams here
                ffmpeg.av_dict_set(&avDict, "buffer_size", "4000000", 0); // Super Critical! default is 80KB; I don't think that is quite big enough for the average 1080p I-frames. In fact, it seems too small for many 720p I-frames. Keep it a multiple of 32
                ffmpeg.av_dict_set(&avDict, "tune", "zerolatency", 0); // not sure this does anything in our particular scenario
                ffmpeg.av_dict_set(&avDict, "reorder_queue_size", "1", 0); // # to buffer for packet reordering, default is 10, we're not sure we want any

                var sw = Stopwatch.StartNew();

                var avioInterruptCbDelegate = new AvioInterruptCbDelegate(s =>
                {
                    var over5Seconds = sw.ElapsedMilliseconds >= 5000;
                    return over5Seconds ? 1 : 0;
                });
                var funcPointer = Marshal.GetFunctionPointerForDelegate(avioInterruptCbDelegate);
                pFormatContext->interrupt_callback = new AVIOInterruptCB { callback = funcPointer, opaque = pFormatContext };
                if (ffmpeg.avformat_open_input(&pFormatContext, url, null, &avDict) != 0)
                {
                    // probably in here because we went over five seconds
                    isConnected(false, CameraErrors.CantOpenUrl);
                    taskSource.SetResult(false);
                    return;
                }
                sw.Stop(); // av_read_frame has an issue where it uses the callback but can't handle a nonzero return
                pFormatContext->interrupt_callback.callback = IntPtr.Zero;

                if (ffmpeg.avformat_find_stream_info(pFormatContext, null) != 0)
                {
                    isConnected(false, CameraErrors.CantFindStreamInfo);
                    taskSource.SetResult(false);
                    return;
                }

                AVStream* pStream = null;
                for (int i = 0; i < pFormatContext->nb_streams; i++)
                {
                    if (pFormatContext->streams[i]->codec->codec_type == AVMediaType.AVMEDIA_TYPE_VIDEO)
                    {
                        pStream = pFormatContext->streams[i];
                        break;
                    }
                }
                if (pStream == null)
                {
                    isConnected(false, CameraErrors.CantFindVideoStream);
                    taskSource.SetResult(false);
                    return;
                }

                AVCodecContext* pCodecContext = pStream->codec;
                int width = pCodecContext->width;
                int height = pCodecContext->height;
                AVPixelFormat sourcePixFmt = pCodecContext->pix_fmt;
                AVCodecID codecId = pCodecContext->codec_id;

                if ((width == 0 && height == 0) || sourcePixFmt == AVPixelFormat.AV_PIX_FMT_NONE)
                {
                    ffmpeg.avcodec_close(pCodecContext);
                    ffmpeg.avformat_close_input(&pFormatContext);

                    isConnected(false, CameraErrors.Kaboom);
                    taskSource.SetResult(false);
                    return;
                }

                // not working yet (unfortunately) -- we don't know how to convert from D3D pixels to BGR24
                // actually, we would probably have to pipe the results right into a shader; it could be some work
                //if (pCodecContext->hwaccel == null)
                //{
                //  AVHWAccel* accelerator = null;
                //  do
                //  {
                //      accelerator = ffmpeg.av_hwaccel_next(accelerator);
                //      if (accelerator != null && accelerator->id == codecId)
                //      {
                //          sourcePixFmt = accelerator->pix_fmt;
                //          break;
                //      }
                //  } while (accelerator != null);
                //  pCodecContext->hwaccel = accelerator;
                //}

                var convertToPixFmt = AVPixelFormat.AV_PIX_FMT_BGR24;
                SwsContext* pConvertContext = ffmpeg.sws_getContext(width, height, sourcePixFmt, width, height, convertToPixFmt,
                    ffmpeg.SWS_FAST_BILINEAR, null, null, null); // bilinear shouldn't do anything as we're only changing pixel format

                if (pConvertContext == null)
                {
                    isConnected(false, CameraErrors.CantInitConversion);
                    taskSource.SetResult(false);
                    return;
                }

                var pConvertedFrame = (AVPicture*)ffmpeg.av_frame_alloc();
                int convertedFrameBufferSize = ffmpeg.avpicture_get_size(convertToPixFmt, width, height);
                var pConvertedFrameBuffer = (sbyte*)ffmpeg.av_malloc((ulong)convertedFrameBufferSize);
                ffmpeg.avpicture_fill(pConvertedFrame, pConvertedFrameBuffer, convertToPixFmt, width, height);

                AVCodec* pCodec = ffmpeg.avcodec_find_decoder(codecId);
                if (pCodec == null)
                {
                    isConnected(false, CameraErrors.UnsupportedCodec);
                    taskSource.SetResult(false);
                    return;
                }

                if ((pCodec->capabilities & ffmpeg.AV_CODEC_CAP_TRUNCATED) == ffmpeg.AV_CODEC_CAP_TRUNCATED)
                    pCodecContext->flags |= ffmpeg.AV_CODEC_FLAG_TRUNCATED;

                pCodecContext->refcounted_frames = 1;

                // I can't see a difference with these next three settings:
                //pCodecContext->thread_type = 0; // disable multithreaded decoding to reduce latency; surely one thread can keep up (it's typically 720p)
                //pCodecContext->thread_count = 1; // default is 0, but I think it uses more than 0
                //pCodecContext->delay = 0; // disable frame buffering (which I think the LOW_DELAY flag does as well)

                pCodecContext->flags |= ffmpeg.AV_CODEC_FLAG_LOW_DELAY; // cuts off 100ms of latency in h264 -- a must-have
                pCodecContext->flags2 |= ffmpeg.AV_CODEC_FLAG2_FAST; // avoids a single memcpy according to the source (and I have no idea why the memcpy exists in the first place)
                //pCodecContext->flags2 |= ffmpeg.AV_CODEC_FLAG2_CHUNKS; // saw this on some number of sites dealing with performance, but I don't understand it

                if (ffmpeg.avcodec_open2(pCodecContext, pCodec, null) < 0)
                {
                    isConnected(false, CameraErrors.CantOpenCodec);
                    taskSource.SetResult(false);
                    return;
                }

                AVFrame* pDecodedFrame = ffmpeg.av_frame_alloc();

                var packet = new AVPacket();
                AVPacket* pPacket = &packet;
                ffmpeg.av_init_packet(pPacket);

                IntPtr target = IntPtr.Zero;

                try
                {
                    isConnected(true, CameraErrors.None);
                    while (!token.IsCancellationRequested)
                    {
                        if (ffmpeg.av_read_frame(pFormatContext, pPacket) != 0)
                        {
                            // end of the stream
                            ffmpeg.av_free_packet(pPacket);
                            break;
                        }

                        if (pPacket->stream_index != pStream->index || (pPacket->flags & ffmpeg.AV_PKT_FLAG_CORRUPT) > 0)
                        {
                            // not a video packet or it's corrupt
                            ffmpeg.av_free_packet(pPacket);
                            continue;
                        }

                        int gotPicture = 0;
                        ffmpeg.av_frame_unref(pDecodedFrame); // goes with refcounted frames above

                        int result = ffmpeg.avcodec_decode_video2(pCodecContext, pDecodedFrame, &gotPicture, pPacket); // I can't see that this checks the CORRUPT flag internally

                        ffmpeg.av_free_packet(pPacket); // must be called after each av_read_frame
                        if (result < 0)
                        {
                            // bad data in the frame; ignore it
                            continue;
                        }

                        if (gotPicture == 1)
                        {
                            sbyte** src = &pDecodedFrame->data0;
                            sbyte** dst = &pConvertedFrame->data0;
                            ffmpeg.sws_scale(pConvertContext, src, pDecodedFrame->linesize, 0, height, dst, pConvertedFrame->linesize);

                            sbyte* convertedFrameAddress = pConvertedFrame->data0;

                            int linesize = pConvertedFrame->linesize[0];

                            if (receptical == null)
                            {
                                receptical = writableBitampCreationCallback.Invoke(new DetectedImageDimensions { Width = width, Height = height, Format = DetectedPixelFormat.Bgr24, Linesize = linesize });
                                target = receptical.Buffer; // this returns the buffer from a WritableBitmap: only run Dispatcher.Invoke once
                            }

                            var imageBufferPtr = new IntPtr(convertedFrameAddress);

                            // in theory it would be great to keep this MemCpy on a background thread
                            // that seems to work so I'm leaving it that way for the moment
                            // but not throwing out the on-ui-thread write call yet
                            CopyMemory(target, imageBufferPtr, linesize * height);
                            receptical.Refresh(width, height);

                            // receptical.Write(width, height, imageBufferPtr, linesize); // memcpy on UI thread

                            // for BitmapSource (not quite as fast as using WritableBitmap) :
                            //var bi = BitmapImage.Create(width, height, 96, 96, PixelFormats.Bgr24, null, imageBufferPtr, linesize * height, linesize);
                            //bi.Freeze(); // make it threadsafe
                        }
                    }

                    // ignoring CODEC_CAP_DELAY -- the last few frames may be lost

                    taskSource.SetResult(true);

                    GC.KeepAlive(avioInterruptCbDelegate); // w/o this we get a strange NullRefExcpt in random methods
                    GC.KeepAlive(funcPointer);
#if DEBUG_VIDEO
                    GC.KeepAlive(logDel);
                    GC.KeepAlive(logDelPointer);
#endif
                }
                catch (Exception ex)
                {
                    //taskSource.SetException(ex);
                    _logger.Warn("Should have gracefully disconnected", ex);
                }
                finally
                {
                    try
                    {
                        ffmpeg.av_free(pConvertedFrame);
                        ffmpeg.av_free(pConvertedFrameBuffer);
                        ffmpeg.sws_freeContext(pConvertContext);

                        ffmpeg.av_frame_free(&pDecodedFrame);
                        ffmpeg.avcodec_close(pCodecContext);
                        ffmpeg.avformat_close_input(&pFormatContext);
                        ffmpeg.av_dict_free(&avDict);
                    }
                    catch (Exception)
                    {
                        // nom nom nom
                    }

                    isConnected(false, CameraErrors.NoPreview);

                    if (!taskSource.Task.IsCompleted)
                        taskSource.SetResult(false);
                }
            })
            {
                Name = "Video decoder: " + url,
                IsBackground = true,
                Priority = ThreadPriority.AboveNormal
            };
            // using a normal thread so we can set its priority
            thread.Start();
            return taskSource.Task;
        }

#if DEBUG_VIDEO
        private static object[] ToObjectArray(RuntimeArgumentHandle stringFormatArgs)
        {
            return new object[20];

            // should work but doesn't:
            var args = new ArgIterator(stringFormatArgs);
            var ret = new object[args.GetRemainingCount()];
            for (int i = 0; i < ret.Length; i++)
                ret[i] = TypedReference.ToObject(args.GetNextArg());
            return ret;
        }
#endif
    }
}

images to mp4

I am very appreciate for your wonderful work ,since I am not familar with your lib yet,could you give us an example of how to use autogen to convert images to mp4?

av_version_info causes AccessViolationException

When using the ffmpeg.av_version_info method, I get a "System.AccessViolationException", here are some of the details:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Stacetrace
at Microsoft.Win32.Win32Native.CoTaskMemFree(IntPtr ptr)
at FFmpeg.AutoGen.ffmpeg.av_version_info()
[REMOVED]

I have found two ways of fixing this,

  • Using a custom marshaler
  • Changing the return type of av_version_info to char* and then using Marshal.PtrToStringAnsi((IntPtr) ffmpeg.av_version_info())

I am unsure if there is a better fix this however the first one could be incorporated directly into this project.

AVFrame.data contruct

Hi Mr. @Ruslan-B ,

I posted a week before saying how I had no access to AVFrame.data and that I could only use AVFrame.data0 - AVFrame.data7. Would it be possible if we could access AVFrame.data by just constructing a list of the pointers to the data from data0 to data7?

Thank you.

Many functions are missed. E.g.: av_fifo_size, av_buffersink_get_frame_flags, ff_request_frame, filter_encode_write_frame and etc

Hello Ruslan!

I'm trying to use your project FFmpeg.AutoGen to transcode video.
I've already used it to implement an ability to get info about video streams and to get thumbnails. But I have an issues when try to use it to transcode video. It seems that functions that are declared in avcodec.h are not included into FFmpeg.AutoGen.
I just tried to re-implamant http://ffmpeg.org/doxygen/trunk/transcoding_8c-example.html on C# and FFmpeg.AutoGen. but there are many functions are missed. E.g.: av_fifo_size, av_buffersink_get_frame_flags, ff_request_frame, filter_encode_write_frame and etc.

Could you help me and explain how can I implement funcation to transcode videos with FFmpeg.AutoGen and with ability to use filters.

Best Regards,
Alexander

AvFrame changed from byte[] to sbyte[] ?

Hi,
First a big thank for your work on ffmpeg - I do appreciate it!

My code is using an old version of your wrapper (based on FFmpeg 2.3.6, from 2015-01-06).
I wanted to upgrade to your latest release, but discovered that the AvFrame struct is now using sbyte pointers instead of byte pointers for dataX fields (your commit as of Nov 7, 2015). Yet, all my code in the upper classes uses bytes (byte arrays, Marshal.Copy, etc.) and at the end, when I transform into an image, it is with a byte[].

How would you advice me to do? Should I convert sbyte[] to byte[] as soon as possible in my code? Can I simply do it by using byte[] byteArray = (byte[])(Array)mySbyteArray ?

Thank you for your answers!

FFmpeg 3.1.1 "Laplace" support

If you use FFmpeg 3.1.1 DLLs with current 3.0 bindings avcodec_find_decoder method always returns null so it's pretty unusable for opening video files.

So I tried to regenerate the bindings for 3.1.1 exports but it generated some crazy code which is not even compilable, for example:

    public unsafe static partial class ffmpeg
    {
        public const int LIBAVCODEC_VERSION_MAJOR = 57;
        public const int LIBAVCODEC_VERSION_MINOR = 48;
        public const int LIBAVCODEC_VERSION_MICRO = 101;
        public const int LIBAVCODEC_VERSION_INT = AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR,LIBAVCODEC_VERSION_MINOR,LIBAVCODEC_VERSION_MICRO);
        public const int LIBAVCODEC_VERSION = AV_VERSION(LIBAVCODEC_VERSION_MAJOR,LIBAVCODEC_VERSION_MINOR,LIBAVCODEC_VERSION_MICRO);
        public const int LIBAVCODEC_BUILD = LIBAVCODEC_VERSION_INT;
        public const int LIBAVCODEC_IDENT = "Lavc"AV_STRINGIFY(LIBAVCODEC_VERSION);
        public const int FF_API_VIMA_DECODER = (LIBAVCODEC_VERSION_MAJOR<58);
        public const int FF_API_AUDIO_CONVERT = (LIBAVCODEC_VERSION_MAJOR<58);
        public const int FF_API_AVCODEC_RESAMPLE = FF_API_AUDIO_CONVERT;
        public const int FF_API_GETCHROMA = (LIBAVCODEC_VERSION_MAJOR<58);
        public const int FF_API_MISSING_SAMPLE = (LIBAVCODEC_VERSION_MAJOR<58);

So it directly puts macros like AV_VERSION_INT (can't resolve it?) and marks all constants int instead of bool.

Note that FFmpeg upto 3.0.2 works good with current 3.0 bindings.

I hope you can add support for the latest FFmpeg 3.1.1 soon.

Support .net core

Hey, it would be nice if it was also possible to generate Bindings for .net core

Building with mono under Debian 9

Hi,

While trying to build FFmpeg.AutoGen with monodevelop (version 5.10.0.871-2) under Debian 9 (strech/testing), I ran into the following problem: ddlmap statements for the "linux" OS in FFmpeg.AutoGen.dll.config missed the .so part in their name.

Here's the original FFmpeg.AutoGen.dll.config file's content:

<configuration>
  <dllmap os="osx" dll="avcodec-57" target="/opt/local/lib/libavcodec.57"/>
  <dllmap os="osx" dll="avfilter-6" target="/opt/local/lib/libavfilter.6"/>
  <dllmap os="osx" dll="swresample-2" target="/opt/local/lib/libswresample.2"/>
  <dllmap os="osx" dll="avformat-57" target="/opt/local/lib/libavformat.57"/>
  <dllmap os="osx" dll="avutil-55" target="/opt/local/lib/libavutil.55"/>
  <dllmap os="osx" dll="swscale-4" target="/opt/local/lib/libswscale.4"/>
  <dllmap os="osx" dll="postproc-54" target="/opt/local/lib/libpostproc.54"/>
  <dllmap os="osx" dll="avdevice-57" target="/opt/local/lib/libavdevice.57"/>
  <dllmap os="linux" dll="avcodec-57" target="libavcodec.57"/>
  <dllmap os="linux" dll="avfilter-6" target="libavfilter.6"/>
  <dllmap os="linux" dll="swresample-2" target="libswresample.2"/>
  <dllmap os="linux" dll="avformat-57" target="libavformat.57"/>
  <dllmap os="linux" dll="avutil-55" target="libavutil.55"/>
  <dllmap os="linux" dll="swscale-4" target="libswscale.4"/>
  <dllmap os="linux" dll="postproc-54" target="libpostproc.54"/>
  <dllmap os="linux" dll="avdevice-57" target="libavdevice.57"/>
</configuration>

I had to change it to the following to be able to run FFmpeg.Autogen.Example:

<configuration>
  <dllmap os="osx" dll="avcodec-57" target="/opt/local/lib/libavcodec.57"/>
  <dllmap os="osx" dll="avfilter-6" target="/opt/local/lib/libavfilter.6"/>
  <dllmap os="osx" dll="swresample-2" target="/opt/local/lib/libswresample.2"/>
  <dllmap os="osx" dll="avformat-57" target="/opt/local/lib/libavformat.57"/>
  <dllmap os="osx" dll="avutil-55" target="/opt/local/lib/libavutil.55"/>
  <dllmap os="osx" dll="swscale-4" target="/opt/local/lib/libswscale.4"/>
  <dllmap os="osx" dll="postproc-54" target="/opt/local/lib/libpostproc.54"/>
  <dllmap os="osx" dll="avdevice-57" target="/opt/local/lib/libavdevice.57"/>
  <dllmap os="linux" dll="avcodec-57" target="libavcodec.so.57"/>
  <dllmap os="linux" dll="avfilter-6" target="libavfilter.so.6"/>
  <dllmap os="linux" dll="swresample-2" target="libswresample.so.2"/>
  <dllmap os="linux" dll="avformat-57" target="libavformat.so.57"/>
  <dllmap os="linux" dll="avutil-55" target="libavutil.so.55"/>
  <dllmap os="linux" dll="swscale-4" target="libswscale.so.4"/>
  <dllmap os="linux" dll="postproc-54" target="libpostproc.so.54"/>
  <dllmap os="linux" dll="avdevice-57" target="libavdevice.so.57"/>
</configuration>

Otherwhise, I had the following kind of error when trying to run it:

Unhandled Exception:
System.DllNotFoundException: libavformat.57
at (wrapper managed-to-native) FFmpeg.AutoGen.ffmpeg:av_register_all ()
at FFmpeg.AutoGen.Example.Program.Main (System.String[] args) [0x000b5] in /home/cyb/FFmpeg.AutoGen/FFmpeg.AutoGen.Example/Program.cs:35
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libavformat.57
at (wrapper managed-to-native) FFmpeg.AutoGen.ffmpeg:av_register_all ()
at FFmpeg.AutoGen.Example.Program.Main (System.String[] args) [0x000b5] in /home/cyb/FFmpeg.AutoGen/FFmpeg.AutoGen.Example/Program.cs:35
L'application s'est terminée par un signal : SIGHUP

Cheers,

Cyrille

Bitmap save exception

If i take your example and let it run for more then 100 frames, using everything as is, I eventually get an exception when trying to save the bitmap. After that happens we start getting the "Could not read frame" exception too.

Do you have anyway to fix this? Or known ways to work around this.

Side Note:
I changed all the code to be C# safe ( the end goal is to use this in unity3d) and i get the same issue in mine.

Invalid ddlName for swresample

It seems that all the functions of swresample point to the wrong dll.
They are mapped to AVCODEC_LIBRARY which is avcodec-56.dll, but I think they should be mapped to swresample-1.dll

Could you check ?

Video encoder - Image set to video

Hi! Hope all is okay...

Your lib is awesome!

Can you tell me if I can use FFmpeg.AutoGen to encode a image sequence to a video? I know that is possible with ffmpeg, but I want to know if is possible to do this with your lib in Mono.
Can you also indicate me a nice tutorial or samples of how to do this with the recent ffmpeg?(because I only find samples in c that use old ffmpeg dlls).

Best regards,
1100594

Trim/cut video

Hello!
Great library. Could You tell me how to edit video to trim/cut it?

Thanks in advance!
Regards

FFmpeg 3.2

Hi,

Awesome job on this AutoGen project! It's proven very useful.

My software suffers from a thread-handle leak in an older version of zeraroe FFmpeg. After updating to 3.1.4 (that comes with current version of AutoGen) the leak is still applicable. But when I use the DLL's of version 3.2 the thread handle leak appears fixed. Unfortunately, some random Access Violation may occur after several hours of running and switching streams. I suspect this is because the generated code of FFmpeg 3.1.4 does not match the code for 3.2.

Unfortunately I run into similar issues as previously reporting in #24 when I try to update AutoGen with the 3.2 binaries of Zeranoe FFmpeg by myself. And by the looks of things, some manual steps are required?

So my question is; Will you update AutoGen to make use of the latest FFmpeg in the near future?

With thanks and regards,
Koen Visser

__STDC_CONSTANT_MACROS error

After I build the FFmpeg.AutoGen.ClangSharpUnsafeGenerator project and I try to run FFmpeg.AutoGen.ClangSharpUnsafeGenerator.exe, I get following error:

./ffmpeg/include/libavutil/common.h:30:2: error: missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
./ffmpeg/include/libavutil/common.h:33:10: fatal error: 'errno.h' file not found
./ffmpeg/include/libavutil/common.h:30:2: error: missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
./ffmpeg/include/libavutil/common.h:33:10: fatal error: 'errno.h' file not found
./ffmpeg/include/libavutil/common.h:33:10: fatal error: 'errno.h' file not found
./ffmpeg/include/libavutil/common.h:33:10: fatal error: 'errno.h' file not found
./ffmpeg/include/libavutil/common.h:30:2: error: missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
./ffmpeg/include/libavutil/common.h:33:10: fatal error: 'errno.h' file not found

Do you have any idea about how to fix it?

Clarification about generation on Windows

Can you provide more clarifications about running python generate.py on Windows?

First of all, it appears that you can't use Python 2.7 from Cygwin (64-bit), as it doesn't know about WindowsError and results in a name error.

Second of all, can I use MinGW-w64? If so, what installation option should I use?

  • Threads: posix or win32?
  • Exceptions: seh or sjlj?

Issue streaming H264 video via RTP

Currently, we cannot stream H264 video sent via RTP. We we're able to get the input and stream info but we have gotPicture always set to 0 when we decode.

We are wondering if we are missing anything in the configuration to make this work. We also found some old articles that suggest to remove first the RTP header and reconstruct the fragments before decoding the byte[].

av_parser_parse2

hi

can you implement av_parser_parse2
are do you know any 2nd way to decode frame from memory only .

Wrong dll attribute ~

It causes an exception error when I use any of swresample-1.dll functions.
so I've changed FFmpegInvoke.cs file.
like this :

public const string SWRESAMPLE_LIBRARY = "swresample-1";
,,,,
[DllImport(SWRESAMPLE_LIBRARY, EntryPoint = "swr_alloc_set_opts", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]

Sorry for my lack of english.

running under mono

Hi, awesome project - thanks for writing it!
It's working fine under the .net compiler/ debugger but when I use xamarin and try to run it using the mono executable on windows i'm getting errors:

Mono: DllImport attempting to load: 'avformat-57'.
Mono: DllImport error loading library 'D:\Projects\test\bin\Debug\avformat-57': 'The system cannot find the file specified.
'.
Mono: DllImport error loading library 'D:\Projects\test\bin\Debug\avformat-57.dll': 'The system cannot find the file specified.
'.
Mono: DllImport loaded library 'avformat-57'.
Mono: DllImport searching in: 'avformat-57' ('avformat-57').
Mono: Searching for 'av_register_all'.
Mono: Probing 'av_register_all'.
Mono: Found as 'av_register_all'.
Unable to find seq points for method '(wrapper managed-to-native) FFmpeg.AutoGen.ffmpeg:av_register_all ()'.

  • Assertion at ..\mono\mini\debugger-agent.c:5345, condition `sp' not met

Any ideas? I have the latest version of xamarin studio installed and it works fine under the .net debugger.

no methods added when targeting FFmpeg 2.7.x

I was attempting to run your generation script on a recent build of FFmpeg. It generates the structs okay but not the methods. I was using MSYS2. I need a custom LGPL build of FFmpeg that has the --enable-small and I also need the ffmpeg.exe itself included alongside the DLLs. When running the generated code downloaded from this site, I get a memory corruption error in release compiles. Please consider an update here. Thanks.

Update for the new version of FFMPEG

Hi Rusian-B,

I am having trouble using your library against the newest version of FFMPEG. The problem is that I can not generate *.g.cs files properly for some reason. Can you take a look at this ?

Thanks

stream asx

When streaming and http that returns an asx it seems to only find one stream, the audio so we are unable to stream. is there a way to parse the asx to get the video stream correctly with your wrapper?

example url,
HTTP://nsx.nvfast.org:80/wme_-_las_vegas_blvd_and_charleston_

This is a traffic camera from Las Vegas. This works in VLC (used for testing) but i am not sure how to get the correct data with the autogen project.

Access AVFrame data

Hi,

I am quite new to FFmpeg and the AutoGen library and was wondering as to how I can access the data within an allocated AVFrame.

I allocated an AVFrame via

AVFrame* encodedFrame = ffmpeg.av_frame_alloc();

However I cannot access the data when calling:

encodedFrame->data;

since doesn't exist, I only have access to data0 up until data7.

I was trying to encode pixel data which was gained from decoding a JPEG image via av_send_packet() and av_receive_frame(). And I wanted to encode the RGB data into YUV_420P to get make sure I can create an FLV1 frame (ffmpeg.AVCodec.AV_CODEC_ID_FLV1).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.