php - ffmpeg 转换为没有音频的 mp4

标签 php ffmpeg

我有一个应该上传视频并将任何上传的视频格式转换为 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'.

最佳答案

我创建了一个 shell 脚本并使用另一个命令来创建 mp4(带音频):
测试.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 - ffmpeg 转换为没有音频的 mp4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69928564/

相关文章:

ffmpeg - 使用 ffmpeg 加水印后质量不佳的视频

ios - 我的 m3u8 带宽值有问题

ffmpeg - 将麦克风从客户端浏览器流式传输到远程服务器,并将音频实时传递到 ffmpeg 以与第二个视频源结合

video - ffprobe 输出视频 : png

php - PHP从文本 explode URL,可能吗?

windows - ffmpeg 标准化视频的响度

php - 根据单击的复选框显示值?

php - 从 Google News RSS Feed 获取更大的图片

java.lang.String 无法从 Android 转换为 JSONObject

php - 如何在 apache 中阻止不需要的 php 请求