courseware
daiao 5 years ago
parent f340b54c61
commit 2caaf8c346

@ -26,7 +26,7 @@ module AliyunVod::Service::VideoManage
result result
end end
# 读取视频编码格式 # 读取视频编码格式与视频格式
def get_meta_code_info(video_id) def get_meta_code_info(video_id)
params = { params = {
Action: 'GetMezzanineInfo', Action: 'GetMezzanineInfo',
@ -36,11 +36,14 @@ module AliyunVod::Service::VideoManage
result = request(:post, params) result = request(:post, params)
Rails.logger.info("#######:#{result['Mezzanine']['VideoStreamList'][0]['CodecName']}") 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 rescue => e
Rails.logger.info "读取视频编码信息失败: #{video_id}, #{e.message}" Rails.logger.info "读取视频编码信息失败: #{video_id}, #{e.message}"
"" [codecnamne: "", format: ""]
end end
# 删除视频信息 # 删除视频信息

@ -29,12 +29,13 @@ class Videos::BatchPublishService < ApplicationService
video.status = "published" video.status = "published"
end end
# 标清转码为h264 # 非MP4 H264编码的都转码
code_info = AliyunVod::Service.get_meta_code_info(video.uuid) 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 video.transcoded = true
result = AliyunVod::Service.get_play_info(video.uuid) rescue nil 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 video.play_url = play_url
else else
AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID) AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID)

@ -3,7 +3,7 @@ namespace :video_transcode do
desc "视频转码成h264" desc "视频转码成h264"
task :submit => :environment do task :submit => :environment do
Video.find_each do |v| 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}" p "--- Start submit video trans code #{v.uuid}"
AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e')
else else

Loading…
Cancel
Save