打开网页,选择视频,上传视频,解析完成后播放及视频下载
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using sportweb.Utility; using System; using System.Collections.Generic; using System.IO; namespace sportweb.Controllers { [Route("api/file/[action]")] [ApiController] public class FileController : ControllerBase { private IWebHostEnvironment WebHostEnvironment; public FileController(IWebHostEnvironment webHostEnvironment) { WebHostEnvironment = webHostEnvironment; } /// <summary> /// 上传mp4文件 /// </summary> /// <returns></returns> [HttpPost] public string import([FromForm(Name = "file")] IFormFile formFile) { if (formFile == null) ResponseUtil.Message(false, "上传文件不能为空"); string fileExt = Path.GetExtension(formFile.FileName); string fileName = Guid.NewGuid().ToString().ToLower() + fileExt; string inputFilePath = Path.Combine(WebHostEnvironment.WebRootPath, "input", fileName); //inputFilePath = inputFilePath.Replace("\\", "/").Replace("//", "/"); if (!Directory.Exists(Path.GetDirectoryName(inputFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(inputFilePath)); } string outFileName1 = "out_" + fileName; string outPutFilePath1 = Path.Combine(WebHostEnvironment.WebRootPath, "output", outFileName1); if (!Directory.Exists(Path.GetDirectoryName(outPutFilePath1))) { Directory.CreateDirectory(Path.GetDirectoryName(outPutFilePath1)); } using (var stream = new FileStream(inputFilePath, FileMode.Create)) { formFile.CopyTo(stream); } Dictionary<string, string> dicData = new Dictionary<string, string>(); dicData["InputPath"] = inputFilePath; dicData["OutputPath"] = outPutFilePath1; Utility.HttpMethods.Post(Program.AiUrl, JsonConvert.SerializeObject(dicData)); // mp4: mp4v转H264 string outFileName2 = "final_" + outFileName1; string outPutFilePath2 = Path.Combine(WebHostEnvironment.WebRootPath, "output", outFileName2); string args = $"-i {outPutFilePath1} -c:v libx264 -crf 24 {outPutFilePath2}"; ProcessHelper.RunProcess(Program.FFmpegPath, args); string accessPath = $"/output/{outFileName2}"; return ResponseUtil.Message(true, accessPath); } } }
#!/usr/bin/python # -*- coding:utf-8 -*- from commondlib.help.ini import * from commondlib.help.data import * from commondlib.help.pose import CPoseHelper from commondlib.help.txt import * from flask import Flask, abort, request, jsonify import json __name__ = '__main__' __webapi = 8080 app = Flask(__name__) def init(): # log CTxtHelper.init("restserver") CTxtHelper.appendlog("soft start") # ini status = CIniHelper.getfile("config.ini") if not status: return False node = "systemparam" __webapi = CDataHelper.string2int(CIniHelper.read(node, "webapi")) return True @app.route('/test/', methods=['GET'], strict_slashes=False) def test(): return jsonify({'code': 0, 'info': "ok", 'errmsg': ""}) @app.route('/pose/', methods=['POST'], strict_slashes=False) def pose(): if not request.json or 'InputPath' not in request.json or 'OutputPath' not in request.json: abort(400) code = 1 info = "success" outmsg = [] inputPath = request.json['InputPath'] outputPath = request.json['OutputPath'] #inputPath = "F:\\SportWeb\\wwwroot\\input\\00ec4451-95d1-4eea-991b-2c7eff332281.mp4" # "pose1.mp4" CDataHelper.fromate_utf( #outputPath = "F:\\SportWeb\\wwwroot\\output\\out_00ec4451-95d1-4eea-991b-2c7eff332281.mp4" # "save.mp4" CDataHelper.fromate_utf( CPoseHelper.Process(inputPath, outputPath, outmsg) errmsg = CDataHelper.list2string(outmsg) if not CDataHelper.string_empty(errmsg): code = 1000 info = "fail" out = {'code': code, 'info': info, 'errmsg': errmsg} CTxtHelper.appendlog("[Info] pose,inputPath:" + inputPath + ",output:" + json.dumps(out)) return jsonify(out) if __name__ == '__main__': init() app.run("0.0.0.0", __webapi, True)
标签:__,mediapipe,string,NetCore,Python,import,json,Path,using From: https://www.cnblogs.com/chen1880/p/16996319.html