转码转码处理

video_transcode
anke1460 5 years ago
parent af1ca5a645
commit c4e44e1442

@ -26,6 +26,20 @@ module AliyunVod::Service::VideoManage
result
end
# 读取视频编码格式
def get_meta_code_info(video_id)
params = {
Action: 'GetMezzanineInfo',
VideoId: video_id,
AdditionType: 'video'
}.merge(base_params)
result = request(:post, params)
result['Mezzanine']['VideoStreamList'][0]['CodecName']
rescue => e
Rails.logger.info "读取视频编码信息失败: #{video_id}, #{e.message}"
end
# 删除视频信息
def delete_video(video_ids)
params = {

@ -14,4 +14,20 @@ module AliyunVod::Service::VideoProcess
result
end
# 提交视频转码任务
def submit_transcode_job(video_id, group_id, **opts)
params = {
Action: 'SubmitTranscodeJobs',
VideoId: video_id,
TemplateGroupId: group_id
}.merge(base_params)
params = opts.merge(params)
result = request(:post, params)
raise AliyunVod::Error, '提交视频转码作业失败' if result['TranscodeJobs'].blank?
result
end
end

@ -1,6 +1,9 @@
class Video < ApplicationRecord
include AASM
# 标准视频转码组
NORMAL_TRANSCODE_GROUP_ID = 'a0277c5c0c7458458e171b0cee6ebf5e'
belongs_to :user
has_many :video_applies, dependent: :destroy

@ -28,6 +28,14 @@ class Videos::BatchPublishService < ApplicationService
if param[:course_id].present?
video.status = "published"
end
# 标清转码为h264
if AliyunVod::Service.get_meta_code_info(video.uuid).start_with?('h264', 'h265', 'flv')
video.transcoded = true
else
AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID)
end
video.save!
if param[:course_id].present?

@ -15,14 +15,15 @@ class Videos::DispatchCallbackService < ApplicationService
video.file_url = convert_https(params['FileUrl'])
video.filesize = params['Size']
video.upload_success
video.play_url = video.file_url if video.transcoded #不需要转码时,则统一播放地址
video.save!
when 'SnapshotComplete' then # 封面截图完成
return if video.cover_url.present?
video.update!(cover_url: params['CoverUrl'])
when 'TranscodeComplete' then # 转码完成
when 'StreamTranscodeComplete' then # 转码完成
return if video.play_url.present?
video.update!(play_url: params['FileUrl'])
video.update!(play_url: params['FileUrl'], transcoded: true)
end
rescue => ex

@ -0,0 +1,5 @@
class AddTranscodedToVideo < ActiveRecord::Migration[5.2]
def change
add_column :videos, :transcoded, :boolean, default: false
end
end

@ -0,0 +1,12 @@
#coding=utf-8
namespace :video_transcode do
desc "视频转码成h264"
task :submit => :environment do
Video.find_each do |v|
if v.uuid && v.transcoded == false && AliyunVod::Service.get_meta_code_info(v.uuid).start_with?("h264", "h265", "flv") == false
p "--- Start submit video trans code #{v.uuid}"
AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e')
end
end
end
end
Loading…
Cancel
Save