diff --git a/app/libs/aliyun_vod/service/video_manage.rb b/app/libs/aliyun_vod/service/video_manage.rb index ef8e707b3..d93a0f5ef 100644 --- a/app/libs/aliyun_vod/service/video_manage.rb +++ b/app/libs/aliyun_vod/service/video_manage.rb @@ -26,7 +26,7 @@ module AliyunVod::Service::VideoManage result end - # 读取视频编码格式 + # 读取视频编码格式与视频格式 def get_meta_code_info(video_id) params = { Action: 'GetMezzanineInfo', @@ -36,11 +36,14 @@ module AliyunVod::Service::VideoManage result = request(:post, params) Rails.logger.info("#######:#{result['Mezzanine']['VideoStreamList'][0]['CodecName']}") - result['Mezzanine']['VideoStreamList'][0]['CodecName'] + codecnamne = result['Mezzanine']['VideoStreamList'].first['CodecName'] + file_url = result['Mezzanine']['FileURL'] + format = file_url&.split(".")&.last + {codecnamne: codecnamne, format: format} rescue => e Rails.logger.info "读取视频编码信息失败: #{video_id}, #{e.message}" - "" + [codecnamne: "", format: ""] end # 删除视频信息 diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 022098fd4..20ce4ac32 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -29,12 +29,13 @@ class Videos::BatchPublishService < ApplicationService video.status = "published" end - # 标清转码为h264 + # 非MP4 H264编码的都转码 code_info = AliyunVod::Service.get_meta_code_info(video.uuid) - if code_info.present? && code_info.start_with?('h264', 'h265') + Rails.logger.info("code_info: #{ode_info['format']}, #{code_info['codecnamne']}") + if code_info['format'] == "mp4" && code_info['codecnamne'].present? && code_info['codecnamne'].start_with?('h264') video.transcoded = true result = AliyunVod::Service.get_play_info(video.uuid) rescue nil - play_url = result['PlayInfoList']['PlayInfo'][0]['PlayURL'] if result.present? + play_url = result['PlayInfoList']['PlayInfo'].first['PlayURL'] if result.present? video.play_url = play_url else AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID) diff --git a/lib/tasks/video_transcode.rake b/lib/tasks/video_transcode.rake index 955905632..a14b5bf8b 100644 --- a/lib/tasks/video_transcode.rake +++ b/lib/tasks/video_transcode.rake @@ -3,7 +3,7 @@ namespace :video_transcode do desc "视频转码成h264" task :submit => :environment do Video.find_each do |v| - if v.uuid && !v.transcoded && !v.file_url.include?('.mp4') && !AliyunVod::Service.get_meta_code_info(v.uuid).start_with?("h264", "h265") + if v.uuid && !v.transcoded && !v.file_url.include?('.mp4') && !AliyunVod::Service.get_meta_code_info(v.uuid)['codecnamne'].start_with?("h264", "h265") p "--- Start submit video trans code #{v.uuid}" AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') else