使用JAVE将MP3转换为视频格式

时间:2018-04-01 15:23:53

标签: java jave

我正在尝试将音频(mp3)文件转换为视频文件(理想情况下是flv或youtube将接受的任何内容)。环顾四周,我认为JAVE可能能够完成这项工作并一直在玩它,但大多数支持是从视频中提取音频而不是相反。我猜我可能需要一张空白图片或其他东西来形成视频中的图片部分,但似乎无法解决这个问题。感谢您的帮助!

我目前的代码如下:

        File source = new File("voicetomstest.mp3");
        File target = new File("target.flv");
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("libmp3lame");
        audio.setBitRate(new Integer(64000));
        audio.setChannels(new Integer(1));
        audio.setSamplingRate(new Integer(22050));
        VideoAttributes video = new VideoAttributes();
        video.setCodec("flv");
        video.setBitRate(new Integer(160000));
        video.setFrameRate(new Integer(15));
        video.setSize(new VideoSize(400, 300));
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("flv");
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        encoder.encode(source, target, attrs);

目前有以下错误

Apr 01, 2018 3:13:34 PM testvoice2video.TestVoice2Video main
SEVERE: null
it.sauronsoftware.jave.InputFormatException
at it.sauronsoftware.jave.Encoder.parseMultimediaInfo(Encoder.java:659)
at it.sauronsoftware.jave.Encoder.encode(Encoder.java:840)
at it.sauronsoftware.jave.Encoder.encode(Encoder.java:713)
at testvoice2video.TestVoice2Video.main(TestVoice2Video.java:74)

其中第74行是" encoder.encode(source,target,attrs);"

1 个答案:

答案 0 :(得分:0)

我不使用这段代码,但是在我看来,从查看Encoder.parseMultiMediaInfo()源代码看来,第659行引发的InputFormatException是无法从目标创建MultimediaInfo文件的结果。它正在目标的开头寻找这个正则表达式:

function getrecommendations(){
    global $conn;
    $sql = "SELECT keywords FROM books WHERE Id = ".$_GET['id']."";
    $result = mysqli_query($conn,$sql);
    $row = mysqli_fetch_array($result);
    $keyword = preg_match_all('/([a-zA-Z]|\xC3[\x80-\x96\x98-\xB6\xB8-\xBF]|\xC5[\x92\x93\xA0\xA1\xB8\xBD\xBE]){4,}/', $row['keywords'],$match_arr);
    $keyword = $match_arr[0];        
    $i = 0;
        $query ="";
        foreach($keyword as $value)
        {
          if($i==0)
          {
              $query = "'%$value%'";
              $i=1;
          }
            else
            {
         $query = $query . " AND keywords LIKE '%$value%'";  
            }
        }
        $key = $query;
        $sql = "SELECT * FROM books WHERE keywords LIKE $key";
        $result = query($sql);
        confirm($result);
        $no=mysqli_num_rows($result);
        if($no==0){

        }else{
        echo "<p><b><big><big>RECOMMENDED FOR YOU</big></big></b></p>";
        echo "<hr>";
        while($row = mysqli_fetch_array($result))
        {
$book = <<<MYHERODOC
<div class="col-lg-3 col-md-6 col-sm-6">
            <div class="container2">
                <img style="height:383px; width:254px" src="img/pic_book/{$row['pathtoimage']}" alt="Avatar" class="image img-responsive">
                <div class="overlay">
                    <div class="text" style="text-transform:capitalize"><b>{$row['Title']}</b><br><small><small><span style="text-transform:lowercase">by</span> {$row['Author']}</small></small>
                        <a class = "btn overlay-btn" href="book.php?id={$row['Id']}"> Preview </a>
                    </div>
                </div>
            </div><br>
            <a href="book.php?id={$row['Id']}" style="color:#cdae51; text-transform:uppercase">{$row['Title']}</a><br>
            <p style="color:#262626">{$row['Author']}</p>     
        </div>
MYHERODOC;
echo $book;
        } 
    }
}

目标文件作为ffmpeg可执行文件打开,然后根据您的属性添加各种参数。我不知道ffmpeg参数会导致“输入#0”类型标题,但我必须假设它是

^\\s*Input #0, (\\w+).+$\\s*"

您确定找到了源文件吗?