FFMpeg.AutoGen讲解官方example代码:解码(未完成)
Posted edzjx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FFMpeg.AutoGen讲解官方example代码:解码(未完成)相关的知识,希望对你有一定的参考价值。
1 /// <summary> 2 /// 编码 把解码出来的jpg文件,再编码成UV420P 3 /// </summary> 4 private static unsafe void EncodeImagesToH264() 5 { 6 7 //获取解码出来的文件队列 8 var frameFiles = Directory.GetFiles(".", "frame.*.jpg").OrderBy(x => x).ToArray(); 9 //获取第一张帧图片 10 var fistFrameImage = Image.FromFile(frameFiles.First()); 11 12 //设置导出媒体信息 13 var outputFileName = "out.h264"; 14 var fps = 25; 15 var sourceSize = fistFrameImage.Size; 16 var sourcePixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24; 17 var destinationSize = sourceSize; 18 var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_YUV420P; 19 using (var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat)) 20 { 21 using (var fs = File.Open(outputFileName, FileMode.Create)) // be advise only ffmpeg based player (like ffplay or vlc) can play this file, for the others you need to go through muxing 22 { 23 using (var vse = new H264VideoStreamEncoder(fs, fps, destinationSize)) 24 { 25 var frameNumber = 0; 26 foreach (var frameFile in frameFiles) 27 { 28 byte[] bitmapData; 29 30 using (var frameImage = Image.FromFile(frameFile)) 31 using (var frameBitmap = frameImage is Bitmap bitmap ? bitmap : new Bitmap(frameImage)) 32 { 33 bitmapData = GetBitmapData(frameBitmap); 34 } 35 36 fixed (byte* pBitmapData = bitmapData) 37 { 38 var data = new byte_ptrArray8 { [0] = pBitmapData }; 39 var linesize = new int_array8 { [0] = bitmapData.Length / sourceSize.Height }; 40 var frame = new AVFrame 41 { 42 data = data, 43 linesize = linesize, 44 height = sourceSize.Height 45 }; 46 var convertedFrame = vfc.Convert(frame); 47 convertedFrame.pts = frameNumber * fps; 48 vse.Encode(convertedFrame); 49 } 50 51 Console.WriteLine($"frame: {frameNumber}"); 52 frameNumber++; 53 } 54 } 55 } 56 } 57 }
以上是关于FFMpeg.AutoGen讲解官方example代码:解码(未完成)的主要内容,如果未能解决你的问题,请参考以下文章
还有另一种方法可以将ffmpeg中的帧导出到texture2d吗?我的代码在Windows中运行但不在Linux上运行
Qt Style Sheets Examples(官方例子目录,很全)
[Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes