public void CreateVideo() { string fileKey = "abcdef"; float outDuration = 1123; string m3u8Key = "m3u8Key"; string thumbKey = "thumKey"; DateTime timeNow = DateTime.Now; Video video = new Video() { VideoRosella = fileKey, VideoState = 0, VideoSource = true, TimeLength = (int)outDuration, VideoPath = m3u8Key, BigPicturePath = thumbKey, SmallPicturePath = thumbKey + "?imageView2/2/w/100/h/100", CreateTime = timeNow, UpdateTime = timeNow, RewardCount = 10 }; video.VideoState = 0; Assert.IsTrue(_videoRepository.CreateEntity(video), "创建成功"); }
public dynamic VideoCallback(JObject postData) { string fileKey = postData.Value <string>("key"); string userIdstr = postData.Value <string>("userId"); int userId = 0; if (!int.TryParse(userIdstr, out userId)) { return("Please Login Account"); } string saveVideo = "video_" + fileKey; var orign = GetVideoByKey(saveVideo); if (orign != null) { //数据已存储 return("Data is stored"); } if (!SaveAsVideo(fileKey, saveVideo)) { return(new { key = fileKey }); } float outDuration = 0; float outBigWidth = 0; float outBigHeight = 0; float outSmallWidth = 0; float outSmallHeight = 0; string avinfoStr = postData.Value <string>("avinfo"); string hashCode = postData.Value <string>("hash"); if (!string.IsNullOrEmpty(avinfoStr)) { JObject avinfoJobj = JObject.Parse(avinfoStr); string durationStr = avinfoJobj["format"].Value <string>("duration"); durationStr = string.IsNullOrEmpty(durationStr) ? avinfoJobj["video"].Value <string>("duration") : durationStr; string widthStr = avinfoJobj["video"].Value <string>("width"); string heightStr = avinfoJobj["video"].Value <string>("height"); float.TryParse(durationStr, out outDuration); float w = 0; float h = 0; if (float.TryParse(widthStr, out w) && float.TryParse(heightStr, out h)) { setBigImageSize(w, h, out outBigWidth, out outBigHeight); setSmallImageSize(w, h, out outSmallWidth, out outSmallHeight); } } Pfop pfop = new Pfop(); //生成缩略图 // refer to http://developer.qiniu.com/docs/v6/api/reference/fop/av/vframe.html // refer to http://developer.qiniu.com/docs/v6/api/reference/fop/saveas.html int offsetTime = (int)(outDuration / 2); offsetTime = offsetTime > 60 ? 60 : offsetTime; //大图 string guid = Guid.NewGuid().ToString("N"); string thumbKey = "cover_" + guid + ".jpg"; string imgFops = VideoImgFop(thumbKey, offsetTime, (int)outBigWidth, (int)outBigHeight); // 小图 string smallPictureKey = "cover_small_" + guid + ".jpg"; string smallImgFops = VideoImgFop(smallPictureKey, offsetTime, (int)outSmallWidth, (int)outSmallHeight); //m3u8 string m3u8Key = "m3u8_" + guid + ".m3u"; string videoFops = VideoFop(m3u8Key); string mp4Key = "mp4_" + guid + ".mp4"; string videoFop4mp4 = VideoFop4mp4(mp4Key); DateTime timeNow = DateTime.Now; Video video = new Video { CreateManageId = userId, VideoRosella = saveVideo, VideoState = 0, VideoSource = true, TimeLength = (int)outDuration, VideoPath = m3u8Key, BigPicturePath = thumbKey, SmallPicturePath = smallPictureKey, CreateTime = timeNow, UpdateTime = timeNow, HashCode = hashCode, DownloadPath = mp4Key }; _videoRepository.CreateEntity(video); //处理m3u8 string pipline = GetPipeline(); PfopDo(pfop, privateBucket, saveVideo, videoFops, pipline, m3u8Key, userId, video.Id); //处理小图 pipline = GetPipeline(); PfopDo(pfop, privateBucket, saveVideo, smallImgFops, pipline, smallPictureKey, userId); //处理大图 pipline = GetPipeline(); PfopDo(pfop, privateBucket, saveVideo, imgFops, pipline, thumbKey, userId); //mp4 pipline = GetPipeline(); PfopDo(pfop, privateBucket, saveVideo, videoFop4mp4, pipline, mp4Key, userId); var returnJson = new { videoId = video.Id, smallKey = smallPictureKey, bigKey = thumbKey, key = saveVideo }; return(returnJson); }