gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:57:02 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com