docker容器 ffmpeg
2022/4/1 23:22:23
本文主要是介绍docker容器 ffmpeg,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \ && apt-get update \ && apt-get install -y ffmpeg \ && apt-get clean && apt-get autoclean && apt-get autoremove \ && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y libgdiplus libc6-dev && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src COPY ["test/test.csproj", "test/"] RUN dotnet restore "test/test.csproj" COPY . . WORKDIR "/src/test" RUN dotnet build "test.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "test.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . VOLUME /app/wwwroot ENTRYPOINT ["dotnet", "test.dll"]
相关代码,可以见解下
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace test.Ffmpeg { public static class FfmpegHelper { private static System.Diagnostics.ProcessStartInfo cmdFfmpeg; private static System.Diagnostics.ProcessStartInfo cmdFfprobe; static FfmpegHelper() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { string ffmpegPath = "/usr/bin/ffmpeg"; string ffprobePath = "/usr/bin/ffprobe"; cmdFfmpeg = new System.Diagnostics.ProcessStartInfo(ffmpegPath); cmdFfprobe = new System.Diagnostics.ProcessStartInfo(ffprobePath); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string ffmpegPath = AppDomain.CurrentDomain.BaseDirectory+ "Ffmpeg\\ffmpeg.exe"; string ffprobePath = AppDomain.CurrentDomain.BaseDirectory + "Ffmpeg\\ffprobe.exe"; cmdFfmpeg = new System.Diagnostics.ProcessStartInfo(ffmpegPath); cmdFfprobe = new System.Diagnostics.ProcessStartInfo(ffprobePath); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { string ffmpegPath = "/usr/bin/ffmpeg"; string ffprobePath = "/usr/bin/ffprobe"; cmdFfmpeg = new System.Diagnostics.ProcessStartInfo(ffmpegPath); cmdFfprobe = new System.Diagnostics.ProcessStartInfo(ffprobePath); } cmdFfmpeg.RedirectStandardError = false; // 输出错误 cmdFfmpeg.RedirectStandardOutput = true; //输出打印 cmdFfmpeg.UseShellExecute = false; //使用Shell cmdFfmpeg.CreateNoWindow = true; //创建黑窗 cmdFfprobe.RedirectStandardError = false; //set false cmdFfprobe.RedirectStandardOutput = true; cmdFfprobe.UseShellExecute = false; //set true cmdFfprobe.CreateNoWindow = true; //don't need the black window } /// <summary> /// 获取视频信息 /// </summary> /// <param name="path"></param> public static async Task<VideoInfoModel> GetVideoInfo(string path) { try { string command = $"-i {path} -print_format json -show_format -show_streams -show_data"; cmdFfprobe.Arguments = command; System.Diagnostics.Process cmd = new System.Diagnostics.Process(); cmd.StartInfo = cmdFfprobe; cmd.Start(); string InfoStr = await cmd.StandardOutput.ReadToEndAsync(); cmd.WaitForExit(10000); VideoInfoModel resp = JsonConvert.DeserializeObject<VideoInfoModel>(InfoStr); return resp; } catch (Exception) { return null; } } /// <summary> /// 视频截图 /// </summary> /// <param name="path"></param> /// <param name="outPath"></param> public static void VideoScreenshot(string path,string outPath) { string command = $"-i {path} -y -q:v 7 -f image2 -t 0.001 {outPath}"; cmdFfmpeg.Arguments = command; System.Diagnostics.Process cmd = new System.Diagnostics.Process(); cmd.StartInfo = cmdFfmpeg; cmd.Start(); cmd.WaitForExit(10000); } } }
这篇关于docker容器 ffmpeg的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-17docker 里面的postgis没有中文支持,如何解决?-icode9专业技术文章分享
- 2024-11-17宿主机上开了阿里云的代理,在docker容器内ping不通阿里云的内网ip什么原因?-icode9专业技术文章分享
- 2024-11-17怎么配置docker dns?-icode9专业技术文章分享
- 2024-11-15在树莓派上用Docker-in-Docker模拟Docker Swarm集群
- 2024-11-14Docker端口:你真的公开了哪些东西?
- 2024-11-14用DOCKER在家里的实验室里搞些酷炫的玩意儿
- 2024-11-05掌握Docker:高效安全的十大最佳实践
- 2024-11-05在 Docker Compose 中怎么设置端口映射-icode9专业技术文章分享
- 2024-11-05在 Docker Compose 中怎么设置环境变量-icode9专业技术文章分享
- 2024-11-04Docker环境部署项目实战:新手入门教程