【问题标题】:ffmpeg converting to mp4 without audioffmpeg 转换为没有音频的 mp4
【发布时间】:2021-12-23 22:54:44
【问题描述】:

我有一个应该上传视频并将任何上传的视频格式转换为 mp4 的表单。 问题是,当我尝试从 iPhone .mov 上传视频时,它已成功转换但没有音频

HTML:

<form action="https://propeview.com/wp-includes/video/process.php" method="post" enctype="multipart/form-data">
  <input type="file" size="1040" class="wpcf7-form-control wpcf7-drag-n-drop-file d-none" aria-invalid="false" multiple="multiple" name="file" id="file" data-limit="200000000" data-max="1" data-id="9015" accept=".">
 
  
  <input type="submit" name="submit" value="upload video" class="wpcf7-form-control has-spinner wpcf7-submit btn color-bg">
</form>

PHP:进程.php

<?php 
$uploads_dir = 'original/';
$file_name = basename($_FILES['file']['name']);
$output_name = explode('.', $file_name)[0];
$uploaded_file = $uploads_dir . $file_name;
$convert_status = ['mp4' => 0];

if(isset($_POST['submit'])) {
  if(move_uploaded_file($_FILES['file']['tmp_name'], $uploaded_file)) {
    // Make sure to get the correct path to ffmpeg
    // Run $ where ffmpeg to get the path
    $ffmpeg = '/bin/ffmpeg';
    
    // MP4
    $video_mp4 = $output_name . '.mp4';
    exec($ffmpeg . ' -i "' . $uploaded_file . '" -vcodec h264 -an -acodec aac -an "./converted/' . $video_mp4 . '" -y 1>convert.txt 2>&1', $output, $convert_status['mp4']);

    // Debug
    // echo '<pre>' . print_r($output, 1) . ' </pre>';

    // WebM
    $video_webm = $output_name . '.webm';
    exec($ffmpeg . ' -i "' . $uploaded_file . '" -c:v libvpx -c:a libvorbis -an "./converted/' . $video_webm . '" -y 1>convert.txt 2>&1', $output, $convert_status['webm']);

    // Debug
    // echo '<pre>' . print_r($output, 1) . ' </pre>';
  }
}
?>

当我尝试通过运行命令在 SSH 上测试转换时


wget https://filesamples.com/samples/video/mov/sample_960x400_ocean_with_audio.mov;
ffmpeg -i sample_960x400_ocean_with_audio.mov -vcodec h264 -acodec aac test_converted.mp4

它给了我以下错误:

[aac @ 0x17332e0] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.
[aac @ 0x17332e0] Alternatively use the non experimental encoder 'libfdk_aac'.

【问题讨论】:

    标签: php ffmpeg


    【解决方案1】:

    我创建了一个 shell 脚本并使用另一个命令来创建 mp4(带音频):

    test.sh

    wget https://filesamples.com/samples/video/mov/sample_960x400_ocean_with_audio.mov;
    ffmpeg -i sample_960x400_ocean_with_audio.mov -vcodec h264 -acodec aac test_converted.mp4
    

    运行

    source ./test.sh
    

    现在打开test_converted.mp4查看音频。

    php 脚本

    更改以下行

    exec($ffmpeg . ' -i "' . $uploaded_file . '" -c:v libx264 -an "./converted/' . $video_mp4 . '" -y 1>convert.txt 2>&1', $output, $convert_status['mp4']);
    

    exec($ffmpeg . ' -i "' . $uploaded_file . '" -vcodec h264 -acodec aac  "./converted/' . $video_mp4 . '">convert.txt 2>&1', $output, $convert_status['mp4']);
    

    【讨论】:

    • 当我们更改 PHP 代码时,文件 stile 没有音频,并且在转换时给我一个错误。
    • 我们是否需要在 SSH 上做任何事情。
    • 你得到什么错误?
    • 我们将代码更改为 exec($ffmpeg . ' -i "' . $uploaded_file . '" -vcodec h264 -an -acodec aac -an "./converted/' . $video_mp4 . ' " -y 1>convert.txt 2>&1', $output, $convert_status['mp4']);它现在正在转换,但仍然没有音频
    • 奇怪,我提供的代码无法重现。也许您可以尝试重新安装ffmpeg?
    猜你喜欢
    • 2016-09-23
    • 2015-07-02
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 2016-10-19
    • 2019-04-04
    相关资源
    最近更新 更多