The new Java project studies online notes -day14 (c)

1.2.3 1.2.3.1 video processing implemented to determine the message format 
video processing MQ messages after using json uniform format, the video processing production side sends the following message to the MQ, the video processing consumer receives this message:
{ "mediaId": 1.2} XXX .3.2 process flow 
1) receiving a video message processing 2) determines whether the media files to process (present only the video processing program is currently received video processing avi)
current avi file only needs to process other files to update the processing status is "without treatment." 3) the initialization process before the processing status is "untreated"
4) requires a processing failure log database recording processing, and the processing status is "treatment failure" 5) for recording the success of the processing status is "Successful treatment" 1.2.3.3 Data Model 
in MediaFile class attribute records ts added mediaFileProcess_m3u8 list of files, as follows:

[AppleScript]  plain text view  Copy the code

?

1

2

//处理状态 private String processStatus;

//hls处理 private MediaFileProcess_m3u8 mediaFileProcess_m3u8;

 

[AppleScript]  plain text view  Copy the code

?

1

2

3

4

@Data

 @ToString public class MediaFileProcess_m3u8 extends MediaFileProcess { 

   //ts列表  

  private List<String> tslist; }


1.2.3.4 video processing to generate Mp4 
1, create Dao video processing results need to be saved to media information database, create dao as follows:
 

[AppleScript]  plain text view  Copy the code

?

1

2

public interface MediaFileRepository extends MongoRepository<MediaFile,String> { 

 }


2, disposed in application.yml ff mpeg root location and the video category of:
 

[AppleScript]  plain text view  Copy the code

?

1

2

3

xc‐service‐manage‐media: 

 video‐location: F:/develop/video/

  ffmpeg‐path: D:/Program Files/ffmpeg‐20180227‐fa0c9d6‐win64‐static/bin/ffmpeg.exe


3, processing tasks created in the class mq package MediaProcessTask class, which is responsible for monitoring video processing queue, and video processing.
The entire content more video processing, to achieve here in two parts: generation and generation Mp4 m3u8, the following code implements generation mp4. 
 

[AppleScript]  plain text view  Copy the code

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

@Component public class MediaProcessTask {     private static final Logger LOGGER = LoggerFactory.getLogger(MediaProcessTask.class);  

    //ffmpeg绝对路径 

   @Value("${xc‐service‐manage‐media.ffmpeg‐path}")  

  String ffmpeg_path;   

   //上传文件根目录 

   @Value("${xc‐service‐manage‐media.upload‐location}")

    String serverPath;

    @Autowired   

 MediaFileRepository mediaFileRepository;  

      @RabbitListener(queues = "${xc‐service‐manage‐media.mq.queue‐media‐processtask}")     public void receiveMediaProcessTask(String msg) throws IOException {  

      Map msgMap = JSON.parseObject(msg, Map.class);   

     LOGGER.info("receive media process task msg :{} ",msgMap);     

   //解析消息 

       //媒资文件id  

      String mediaId = (String) msgMap.get("mediaId");   

     //获取媒资文件信息

        Optional<MediaFile> optional = mediaFileRepository.findById(fileMd5)

       if(!optional.isPresent()){       

     return ;   

     }     

   MediaFile mediaFile = optional.get();    

    //媒资文件类型       

 String fileType = mediaFile.getFileType();    

    if(fileType == null || !fileType.equals("avi")){//目前只处理avi文件   

         mediaFile.setProcessStatus("303004");//处理状态为无需处理      

      mediaFileRepository.save(mediaFile);    

        return

       }else{

            mediaFile.setProcessStatus("303001");//处理状态为未处理      

      mediaFileRepository.save(mediaFile)

       }    

    //生成mp4  

      String video_path = serverPath + mediaFile.getFilePath()+mediaFile.getFileName();  

      String mp4_name = mediaFile.getFileId()+".mp4";   

     String mp4folder_path = serverPath + mediaFile.getFilePath();   

     Mp4VideoUtil videoUtil = new  Mp4VideoUtil(ffmpeg_path,video_path,mp4_name,mp4folder_path);    

    String result = videoUtil.generateMp4();  

      if(result == null || !result.equals("success")){      

      //操作失败写入处理日志   

         mediaFile.setProcessStatus("303003");//处理状态为处理失败    

        MediaFileProcess_m3u8 mediaFileProcess_m3u8 = new MediaFileProcess_m3u8();  

          mediaFileProcess_m3u8.setErrormsg(result);          

  mediaFile.setMediaFileProcess_m3u8(mediaFileProcess_m3u8);      

      mediaFileRepository.save(mediaFile);   

         return ;   

     }   

     //生成m3u8...  

      } }


说明:
1、原始视频转成mp4如何判断转换成功?

根据视频时长来判断,取原视频和转换成功视频的时长(时分秒),如果相等则相同。

Guess you like

Origin blog.csdn.net/czbkzmj/article/details/91802598