Browse Source

处理资源文件视频格式

tags/正式3.14.1
王宁 3 months ago
parent
commit
ad106b8c73

+ 2
- 1
scommons/src/main/java/com/xhkjedu/utils/N_Utils.java View File

@@ -825,8 +825,9 @@ public class N_Utils {
825 825
             URL realUrl = new URL(url);
826 826
             // 打开和URL之间的连接
827 827
             URLConnection conn = realUrl.openConnection();
828
+
828 829
             // 设置通用的请求属性
829
-            conn.setRequestProperty("accept", "application/x-www-form-urlencoded");
830
+            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
830 831
             conn.setRequestProperty("connection", "Keep-Alive");
831 832
             conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
832 833
             // 发送POST请求必须设置如下两行

+ 35
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/controller/resource/FlvUpdateResController.java View File

@@ -0,0 +1,35 @@
1
+package com.xhkjedu.sstudy.controller.resource;
2
+
3
+import com.xhkjedu.sstudy.service.resource.FlvUpdateResService;
4
+import com.xhkjedu.vo.ResultVo;
5
+import org.springframework.web.bind.annotation.GetMapping;
6
+import org.springframework.web.bind.annotation.RequestMapping;
7
+import org.springframework.web.bind.annotation.RestController;
8
+
9
+import javax.annotation.Resource;
10
+
11
+/**
12
+ * @Description:flv资源更改状态
13
+ * @Author: WN
14
+ * @Date: 2024/9/14 16:15:35
15
+ **/
16
+@RequestMapping("/flvu")
17
+@RestController
18
+public class FlvUpdateResController {
19
+    @Resource
20
+    private FlvUpdateResService flvUpdateResService;
21
+
22
+    /*
23
+     * @Description 处理flv资源
24
+     * @Date 2024/9/14 16:36:22
25
+     * @Author WN
26
+     * @Param []
27
+     * @Return com.xhkjedu.vo.ResultVo
28
+     **/
29
+    @GetMapping("/fv")
30
+    public ResultVo handleFlvRes() {
31
+        int count = flvUpdateResService.hadnleFlvResource();
32
+        return new ResultVo(0, "处理成功",count);
33
+    }
34
+
35
+}

+ 9
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/mapper/resource/ResourceMapper.java View File

@@ -90,4 +90,13 @@ public interface ResourceMapper extends TkMapper<TResource> {
90 90
 
91 91
     //资源是否分享过
92 92
     List<Map<String, String>> listShareNumByIds(@Param("shareqids") String shareqids);
93
+
94
+    //获取flv资源
95
+    List<TResource> listFlvResources();
96
+
97
+    //修改资源flv编码
98
+    int updateFlvResconverted(@Param("resourceid")String resourceid, @Param("mp4code")String mp4code);
99
+
100
+    //更改flv编码
101
+    int updateFlvMp4code(@Param("resourceid")String resourceid, @Param("mp4code")String mp4code);
93 102
 }

+ 57
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/service/resource/FlvUpdateResService.java View File

@@ -0,0 +1,57 @@
1
+package com.xhkjedu.sstudy.service.resource;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.xhkjedu.sstudy.config.ConfigKey;
5
+import com.xhkjedu.sstudy.mapper.resource.ResourceMapper;
6
+import com.xhkjedu.sstudy.model.resource.TResource;
7
+import com.xhkjedu.utils.N_Utils;
8
+import com.xhkjedu.vo.ResultVo;
9
+import lombok.extern.slf4j.Slf4j;
10
+import org.springframework.stereotype.Service;
11
+
12
+import javax.annotation.Resource;
13
+import java.util.List;
14
+
15
+/**
16
+ * @Description:flv非h264格式视频转码
17
+ * @Author: WN
18
+ * @Date: 2024/9/14 16:16:02
19
+ **/
20
+@Slf4j
21
+@Service
22
+public class FlvUpdateResService {
23
+
24
+    @Resource
25
+    ResourceMapper resourceMapper;
26
+
27
+    /*
28
+     * @Description 如果flv编码不是h264格式,则设置资源带转换
29
+     * @Date 2024/9/14 16:33:23
30
+     * @Author WN
31
+     * @Param []
32
+     * @Return void
33
+     **/
34
+    public int hadnleFlvResource() {
35
+        List<TResource> resourceList = resourceMapper.listFlvResources();
36
+        int count = 0;
37
+        for (TResource resource : resourceList) {
38
+            String resourceid = resource.getResourceid();
39
+
40
+            String params = "filepath=" + resource.getResourceurl();
41
+            String fileInfoStr = N_Utils.sendPost(ConfigKey.fileapi + "video/vc", params);
42
+
43
+            ResultVo fileResult = JSON.parseObject(fileInfoStr, ResultVo.class);
44
+            if (fileResult.getCode() == 0 && N_Utils.isNotEmpty(fileResult.getObj())) {
45
+                String flvCode = fileResult.getObj().toString();
46
+                if (!"h264".equals(flvCode)) {
47
+                    resourceMapper.updateFlvResconverted(resourceid, flvCode);
48
+                    count++;
49
+                }else{
50
+                    resourceMapper.updateFlvMp4code(resourceid, "h264");
51
+                }
52
+            }
53
+        }
54
+        return count;
55
+    }
56
+
57
+}

+ 16
- 0
sstudy/src/main/resources/mapper/resource/ResourceMapper.xml View File

@@ -308,4 +308,20 @@
308 308
         <foreach collection="list" item="schoolid" open="(" separator="," close=")">${schoolid}</foreach>
309 309
     </update>
310 310
 
311
+    <!--获取flv资源-->
312
+    <select id="listFlvResources" resultType="com.xhkjedu.sstudy.model.resource.TResource">
313
+        select resourceid,suffix,resourcename,resourceurl
314
+        from t_resource where resourcestate=1 and LOWER(suffix)='flv' and mp4code!='h264' order by createtime asc
315
+    </select>
316
+
317
+    <!--修改资源flv编码-->
318
+    <update id="updateFlvResconverted">
319
+        update t_resource set converted=0,mp4code=#{mp4code} where resourceid=#{resourceid}
320
+    </update>
321
+
322
+    <!--更改flv编码-->
323
+    <update id="updateFlvMp4code">
324
+        update t_resource set mp4code=#{mp4code} where resourceid=#{resourceid}
325
+    </update>
326
+
311 327
 </mapper>

Loading…
Cancel
Save