Authored by 马力

转码

... ... @@ -69,7 +69,7 @@ public class QNLiveUtilService {
* @param endTime 摄像结束时间
*/
public void fetch(String fileKey, String liveM3u8Url, String startTime, String endTime) throws PlatformException {
logger.info("bucketManager.fetch begin fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, liveM3u8Url, startTime, endTime);
logger.info("bucketManager.fetch begin fileKey is :{}, liveM3u8Url is :{}, startTime is :{}, endTime is :{}.", fileKey, liveM3u8Url, startTime, endTime);
//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth, cfg);
... ... @@ -80,16 +80,16 @@ public class QNLiveUtilService {
//要fetch的url "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1544425260&endtime=1544425440";
String fetchUrl = liveM3u8Url + "?starttime=" + startTime + "&endtime=" + endTime;
logger.info("bucketManager.fetch before fetchUrl is {}", fetchUrl);
logger.info("bucketManager.fetch before fetchUrl is :{}.", fetchUrl);
if (null == fetchUrl) {
if (null == liveM3u8Url) {
throw new PlatformException(400);
}
try {
FetchRet fetch = bucketManager.fetch(fetchUrl, BUCKET, key); //调用fetch方法抓取文件
logger.info("Resp is {} from bucketManager.fetch", fetch.key);
logger.info("Resp is {} from bucketManager.fetch key is :{}, hash is :{},fsize is :{},mimeType is :{}.", fetch.key, key, fetch.hash, fetch.fsize, fetch.mimeType);
} catch (QiniuException e) {
logger.error("bucketManager.fetch find wrong fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, liveM3u8Url, startTime, endTime, e.response);
... ...
... ... @@ -12,6 +12,7 @@ import com.qiniu.storage.model.FetchRet;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.qiniu.util.UrlSafeBase64;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.IQNUploadService;
import com.yoho.ufo.util.ImagesHelper;
import org.slf4j.Logger;
... ... @@ -64,17 +65,46 @@ public class QNUploadServiceImpl implements IQNUploadService {
*/
public static void main(String[] args) {
fetch();
public static void main(String[] args) throws Exception{
//fetch("9790249123840_1545543654", "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8", "1545543654", "1545543664");
transfer();
}
public static void fetch(String fileKey, String liveM3u8Url, String startTime, String endTime) throws PlatformException {
logger.info("bucketManager.fetch begin fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, liveM3u8Url, startTime, endTime);
Auth auth = Auth.create("atSf7xxIl8alEnsXbhC1bOD1GWVW3qYffz8SlB4m", "pyoJzPygXIkFWrc1BAsH6tAJ0yweTchpJwGKEwhm");
//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth, cfg);
//文件保存的空间名和文件名
String key = "ufo/live/m3u8/" + fileKey + ".m3u8"; // 例如 "ufo/live/m3u8/yohotest15.m3u8";
//要fetch的url "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1544425260&endtime=1544425440";
String fetchUrl = liveM3u8Url + "?starttime=" + startTime + "&endtime=" + endTime;
logger.info("bucketManager.fetch before fetchUrl is :{}.", fetchUrl);
if (null == fetchUrl) {
throw new PlatformException(400);
}
try {
FetchRet fetch = bucketManager.fetch(fetchUrl, "yhbflv", key); //调用fetch方法抓取文件
logger.info("Resp is {} from bucketManager.fetch key is :{}.", fetch.key, key);
} catch (QiniuException e) {
logger.error("bucketManager.fetch find wrong fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, liveM3u8Url, startTime, endTime, e.response);
throw new PlatformException(400);
}
}
public static void fetch() {
//设置需要操作的账号的AK和SK
String ACCESS_KEY = "atSf7xxIl8alEnsXbhC1bOD1GWVW3qYffz8SlB4m";
String SECRET_KEY = "pyoJzPygXIkFWrc1BAsH6tAJ0yweTchpJwGKEwhm";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
Auth auth = Auth.create("atSf7xxIl8alEnsXbhC1bOD1GWVW3qYffz8SlB4m", "pyoJzPygXIkFWrc1BAsH6tAJ0yweTchpJwGKEwhm");
//Zone z = Zone.zone0();
//Configuration c = new Configuration(z);
... ... @@ -83,15 +113,14 @@ public class QNUploadServiceImpl implements IQNUploadService {
BucketManager bucketManager = new BucketManager(auth, cfg);
//文件保存的空间名和文件名
String bucket = "yhbflv";
String key = "ufo/live/m3u8/yohotest115.m3u8";
String key = "ufo/live/m3u8/9790249123840_1545530300.m3u8";
//要fetch的url
String url = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1545291515&endtime=1545292115";
url = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1545484537&endtime=1545484565";
url = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1545530300&endtime=1545530313";
try {
//调用fetch方法抓取文件
FetchRet fetch = bucketManager.fetch(url, bucket, key);
FetchRet fetch = bucketManager.fetch(url, "yhbflv", key);
//fetch.
... ... @@ -105,7 +134,7 @@ url = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1545484537&e
// http://api.qiniu.com/status/get/prefop?id=z0.5c1b4c0138b9f349c8bb9c46 查看文件的状态
// http://flv01.static.yhbimg.com/ufo/live/mp4/yohotest15.mp4
private static void transfer() {
String m3u8Address = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8";
//String m3u8Address = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8";
//设置账号的AK,SK
String ACCESS_KEY = "atSf7xxIl8alEnsXbhC1bOD1GWVW3qYffz8SlB4m";
String SECRET_KEY = "pyoJzPygXIkFWrc1BAsH6tAJ0yweTchpJwGKEwhm";
... ... @@ -114,7 +143,8 @@ url = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1545484537&e
OperationManager operater = new OperationManager(auth, cfg);
//设置要转码的空间和key,并且这个key在你空间中存在
String bucket = "yhbflv";
String key = "ufo/live/m3u8/yohotest115.m3u8"; // 14 4 分钟 15 3分钟
String key = "ufo/live/m3u8/9790249123840_1545530300.m3u8"; // 14 4 分钟 15 3分钟
key = "ufo/live/m3u8/9790249123840_1545543654.m3u8";
//设置转码操作参数 1920x1080 1280x720 848x480
String fops = "avthumb/mp4/s/1280x720/vb/1m/an/1/hr/0/r/30";
... ... @@ -122,7 +152,7 @@ url = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1545484537&e
//设置转码的队列
String pipeline = "yoho-m3u8-to-mp4";
//可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
String urlbase64 = UrlSafeBase64.encodeToString("yhbflv:ufo/live/mp4/yohotest115.mp4");
String urlbase64 = UrlSafeBase64.encodeToString("yhbflv:ufo/live/mp4/9790249123840_1545543654.mp4");
String pfops = fops + "|saveas/" + urlbase64;
//设置pipeline参数 http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/ufoLive/ufo_avthumb_notify
StringMap params = new StringMap().putWhen("force", 1, true).putNotEmpty("pipeline", pipeline).put("notifyURL", "http://testapi.yohops.com/ufoLive/ufo_avthumb_notify");
... ...