ffmpeg转换为没有音频的mp4

ffmpeg converting to mp4 without audio

我有一个表单可以上传视频并将任何上传的视频格式转换为 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: process.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'.

我创建了一个 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']);