百度智能云

All Product Document

          Multimedia Cloud Processing

          Transcoding-Job

          Transcoding Job is the most basic execution unit in audio and video transcoding. Each job transcodes an original audio and video resource into a target audio and video resource. Therefore, there is a one-to-one correspondence between jobs and transcoding goals, that is, if the user needs to convert an original video specification into three target specifications, such as transcoding from AVI format to FLV/MP4/HLS format, then the user needs to create three jobs.

          Create Transcoding Job

          When creating the transcoding job, the user needs to assign the affiliated Pipeline, the applied Preset, the original AV resource BOS Key and the target AV resource BOS Key for the transcoding job.

          The following code creates a Job and gets the created jobId:

          public void createJob(MediaClient client, String pipelineName, 
                    String sourceKey, String targetKey, String presetName) { 
              String jobId = client.createJob(pipelineName, sourceKey, targetKey, presetName).getJobId(); 
          } 

          The following code can create a Job supporting video combination, watermark removing and watermark embedding (assign the watermarkId in Job instead of Preset), and get the created jobID:

          public void createJob(MediaClient client, String pipelineName, 
                    List<SourceClip> clips, String targetKey, String presetName, String watermarkId, Area delogoArea) { 
              // Area delogoArea = new Area().withX(10).withY(200).withWidth(100).withHeight(150); 
              String jobId = mediaClient.createTranscodingJob(pipelineName, clips, targetKey, presetName, 
                                 watermarkId, delogoArea).getJobId(); 
          } 

          The following code can create a Job supporting video combination, watermark removing, watermark embedding, black border removing and multiple overlays inserting (Insert), and get the created jobID:

          public void createJob(MediaClient client, String pipelineName, 
                    List<SourceClip> clips, String targetKey, String presetName, String watermarkId, Area delogoArea, 
                    Area crop, List<Insert> inserts) { 
              // Layout layout = new Layout().withHorizontalAlignment("right").withHorizontalOffsetInPixel(10) 
              //                              .withVerticalAlignment("top").withVerticalOffsetInPixel(100); 
              // Timeline timeline = new Timeline().withStartTimeInMillisecond(4500).withDurationInMillisecond(3000); 
              // Insert insert = new Insert().withBucket("testbucket").withKey("logo.png").withType("image") 
              //                              .withLayout(layout).withTimeline(timeline); 
              String jobId = mediaClient.createTranscodingJob(pipelineName, clips, targetKey, presetName, 
                                 watermarkId, delogoArea, crop, inserts).getJobId(); 
          } 

          Note

          • The warteramrkId, delogo, crop and inserts can be set as null, meaning the feature is disused.
          • If multiple videos need to be combined without transcoding, set transmux as true in Preset to realize.

          List All the Transcoding Jobs of the Assigned Pipeline

          The following code queries all the Jobs under the Pipeline through the assigned pipelineName:

          public void listJobs(MediaClient client, String pipelineName) { 
          
              //Get all the Job information under assigned Pipeline 
              List<Job> jobs = client.listJobs(pipelineName).getJobs(); 
              for (Job job : jobs) { 
                  System.out.println("jobId: " + job.getJobId()); 
              } 
          } 

          listJobs method returns ListJobsResponse object, and ListJobsResponse object contains the returned result of the listJob request. You can get the description information of all Jobs through the getJobs method in ListJobsResponse.

          Query Assigned Transcoding Job Information

          The user can read a certain Job through the following code:

          public void getJob(MediaClient client, String jobId) { 
              GetJobResponse resp = client.getJob(jobId); 
              System.out.println("pipelineName: " + resp.getPipelineName()); 
              System.out.println("sourceKey: " + resp.getSource().getSourceKey()); 
              System.out.println("targetKey: " + resp.getTarget().getTargetKey()); 
              System.out.println("jobStatus: " + resp.getJobStatus()); 
              System.out.println("startTime: " + resp.getStartTime()); 
              System.out.println("endTime: " + resp.getEndTime()); 
          } 
          Previous
          Pipeline
          Next
          Preset