Actionscript 3 ActionScript 3 FFMPEG丢失视频元数据

Actionscript 3 ActionScript 3 FFMPEG丢失视频元数据,actionscript-3,ffmpeg,actionscript,Actionscript 3,Ffmpeg,Actionscript,我正在使用FFMPEG将视频文件转换为.flv格式,以便使用LoaderMax(GreenSocks)播放视频文件。问题是,当使用FFMPEG转换视频时,元数据丢失,因此我无法稍后使用LoaderMax使用下面的代码获取持续时间或当前播放时间 video.getTime(); video.duration(); 在使用FFMPEG转换视频之前,我可以很容易地获取视频的持续时间,但这并不能解决获取当前播放时间的问题。我的目标是允许用户点击搜索栏并跳转到视频中的任何一点,但由于明显的原因,我需要能

我正在使用FFMPEG将视频文件转换为.flv格式,以便使用LoaderMax(GreenSocks)播放视频文件。问题是,当使用FFMPEG转换视频时,元数据丢失,因此我无法稍后使用LoaderMax使用下面的代码获取持续时间或当前播放时间

video.getTime();
video.duration();
在使用FFMPEG转换视频之前,我可以很容易地获取视频的持续时间,但这并不能解决获取当前播放时间的问题。我的目标是允许用户点击搜索栏并跳转到视频中的任何一点,但由于明显的原因,我需要能够显示当前时间和视频长度

我现在尝试将FFMPEG与名为flvtool2的东西一起使用,它应该重建元数据

我的代码当前用于此:

    nativeProcessInfo = new NativeProcessStartupInfo();
    nativeProcessInfo.executable = File.applicationDirectory.resolvePath(ffmpegPath); //path to ffmpeg (included in project files)
    //nativeProcessInfo.executable = File.applicationDirectory.resolvePath(flvtool2Path); //path to flvtool2 (included in project files)

    var processArgument:Vector.<String> = new Vector.<String>(); //holds command line arguments for converting video
    processArgument.push("-i"); //filename
    processArgument.push(filePath);

    processArgument.push("-s"); //size
    processArgument.push("640x480");
    processArgument.push("-b:v"); //bitrate - video
    processArgument.push("4800k");
    processArgument.push("-b:a"); //bitrate -  
    processArgument.push("6400k");
    processArgument.push("-ar"); //audio sampling frequency
    processArgument.push("44100");
    processArgument.push("-ac"); //audio channels
    processArgument.push("2");
    processArgument.push("-ab"); //audio bitrate frequency
    processArgument.push("160k");
    processArgument.push("-f"); //force
    processArgument.push("flv");
    processArgument.push("-");

    /*processArgument.push("|");
    processArgument.push("flvtool2");
    processArgument.push("-U");
    processArgument.push("stdin");
    processArgument.push(filePath);*/

    nativeProcessInfo.arguments = processArgument;

    if (NativeProcess.isSupported) {
        nativeProcess = new NativeProcess();

        nativeProcess.start(nativeProcessInfo); //start video buffering

        nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, ProgressEventOutputHandler);
        nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, ProgressEventErrorHandler);
        nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, NativeProcessExitHandler);
        nativeProcess.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, standardIOErrorHandler);
        nativeProcess.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, standardIOErrorHandler);

    } else {
        trace("!NativeProcess.isSupported");
    }
nativeProcessInfo=新的NativeProcessStartupInfo();
nativeProcessInfo.executable=File.applicationDirectory.resolvePath(ffmpegPath)//ffmpeg的路径(包含在项目文件中)
//nativeProcessInfo.executable=File.applicationDirectory.resolvePath(flvtool2Path)//flvtool2的路径(包含在项目文件中)
变量processArgument:Vector.=新向量()//保存用于转换视频的命令行参数
processArgument.push(“-i”)//文件名
push(文件路径);
processArgument.push(“-s”)//大小
processArgument.push(“640x480”);
processArgument.push(“-b:v”)//比特率视频
processArgument.push(“4800k”);
processArgument.push(“-b:a”)//比特率-
processArgument.push(“6400k”);
processArgument.push(“-ar”)//音频采样频率
processArgument.push(“44100”);
processArgument.push(“-ac”)//音频频道
processArgument.push(“2”);
processArgument.push(“-ab”)//音频比特率频率
processArgument.push(“160k”);
processArgument.push(“-f”)//武力
processArgument.push(“flv”);
processArgument.push(“-”);
/*processArgument.push(“|”);
processArgument.push(“flvtool2”);
processArgument.push(“-U”);
processArgument.push(“stdin”);
push(文件路径)*/
nativeProcessInfo.arguments=ProcessArguments;
if(NativeProcess.isSupported){
nativeProcess=新的nativeProcess();
nativeProcess.start(nativeProcessInfo);//开始视频缓冲
nativeProcess.addEventListener(ProgressEvent.STANDARD_输出_数据,ProgressEventOutputHandler);
nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_数据,ProgressEventErrorHandler);
nativeProcess.addEventListener(NativeProcessExiteEvent.EXIT,NativeProcessExitHandler);
nativeProcess.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR,standardIOErrorHandler);
nativeProcess.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR,standardIOErrorHandler);
}否则{
跟踪(“!NativeProcess.isSupported”);
}

我上传了一个要下载的示例项目,它应该可以帮助解释这个问题。要使用它,您需要将ActionScript属性指向Greensock的位置,以使用LoaderMax,并在您的计算机上某处有一个视频进行测试。链接是:

以工作代码为例,通过AIR的
NativeProcess使用ffmpeg将视频(在我的例子中是AVI)转换为FLV视频文件:

var loader:VideoLoader,
    exe:File = File.applicationDirectory.resolvePath('ffmpeg.exe'),
    video_in:File = File.applicationDirectory.resolvePath('video.avi'),
    video_out:File = File.applicationDirectory.resolvePath('video.flv');

var args:Vector.<String> = new Vector.<String>();
    args.push("-i", video_in.nativePath, "-b:v", "800k", "-ar", "44100", "-ab", "96k", "-f", "flv", video_out.nativePath);

var npsi:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    npsi.executable = exe;
    npsi.arguments = args;

var process:NativeProcess = new NativeProcess();
    process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
    process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
    process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
    process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
    process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
    process.start(npsi);

function onOutputData(event:ProgressEvent):void
{
    trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
function onErrorData(event:ProgressEvent):void
{
    trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
function onExit(event:NativeProcessExitEvent):void
{
    playFLV();
}
function onIOError(event:IOErrorEvent):void
{
    trace(event.toString());
}

function playFLV()
{
    loader = new VideoLoader(
        video_out.nativePath,
        {
            container: this, 
            width: 400, 
            height: 300, 
            scaleMode: "proportionalInside", 
            bgColor: 0x000000, 
            autoPlay: true, 
            volume: 0.5
        }
    );
    loader.addEventListener(LoaderEvent.COMPLETE, onVideoLoad);
    loader.load();
}
function onVideoLoad(e:LoaderEvent): void {
    trace(loader.duration);    // gives for example : 67.238
    loader.playVideo();
}
var加载程序:视频加载程序,
exe:File=File.applicationDirectory.resolvePath('ffmpeg.exe'),
video_in:File=File.applicationDirectory.resolvePath('video.avi'),
视频输出:File=File.applicationDirectory.resolvePath('video.flv');
变量args:Vector.=新向量();
参数推送(“-i”,视频输入本机路径,“-b:v”,“800k”,“-ar”,“44100”,“-ab”,“96k”,“-f”,“flv”,视频输出本机路径);
var npsi:NativeProcessStartupInfo=新的NativeProcessStartupInfo();
npsi.executable=exe;
npsi.arguments=args;
var进程:NativeProcess=new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_输出数据,onOutputData);
process.addEventListener(ProgressEvent.STANDARD_ERROR_数据,onErrorData);
process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR,onIOError);
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR,onIOError);
process.addEventListener(nativeProcessExiteEvent.EXIT,onExit);
过程启动(npsi);
函数onOutputData(事件:ProgressEvent):void
{
跟踪(“get:,process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
函数onErrorData(事件:ProgressEvent):无效
{
跟踪(“错误-”,process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
函数onExit(事件:NativeProcessExiteEvent):void
{
playFLV();
}
函数错误(事件:IOErrorEvent):无效
{
跟踪(event.toString());
}
函数playFLV()
{
加载器=新视频加载器(
视频输出本地路径,
{
集装箱:这个,,
宽度:400,
身高:300,
scaleMode:“按比例排列”,
bgColor:0x000000,
自动播放:对,
数量:0.5
}
);
loader.addEventListener(LoaderEvent.COMPLETE,onVideoLoad);
loader.load();
}
函数onVideoLoad(e:LoaderEvent):void{
trace(loader.duration);//给出例如:67.238
loader.playVideo();
}

希望这能有所帮助。

您可以使用该工具注入元数据…如何使用ActionScript?您可以通过
NativeProcess
使用它,就像使用ffmpeg一样…好的,没问题。我将发布我的代码作为答案,因为我无法将其全部作为注释…PS:您的“发送方式”文件无法为我编译。我的Flash不知道GlobalAccess是什么
utils.PopulateCriteria
etc意味着我放弃了。zip下载很好,但是FLA是CC版本,我使用的是旧的CS版本,所以也拒绝打开。准备再次放弃。作为最后的尝试。。。我将调整我向您展示的,以获得实时转换/播放/s