ActionScript 3 FFMPEG 丢失视频元数据

ActionScript 3 FFMPEG losing Metadata of video

我正在使用 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");
    }

我已经上传了一个示例项目供下载,这应该有助于解释问题。要使用它,您需要将 ActionScript 属性指向 Greensock 的位置以使用 LoaderMax,并在您的计算机上的某个位置放置一个视频以供测试。 link 是:http://www.prospectportal.co.uk/example.zip

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

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();
}

希望能帮到你。