Reputation: 99
I have a form that supposed to upload video and convert any uploaded video format to mp4. The issue is, when i tried to upload a video from iPhone .mov it is converted successfully but without audio
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>';
}
}
?>
When i tried to test the conversion on SSH by runing the comand
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
It gave me the below error:
[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'.
Upvotes: 1
Views: 1664
Reputation: 2512
I have created a shell script and used another command to create the mp4 (with audio):
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
Run
source ./test.sh
Now open test_converted.mp4
to check the audio.
Change the following line
exec($ffmpeg . ' -i "' . $uploaded_file . '" -c:v libx264 -an "./converted/' . $video_mp4 . '" -y 1>convert.txt 2>&1', $output, $convert_status['mp4']);
To
exec($ffmpeg . ' -i "' . $uploaded_file . '" -vcodec h264 -acodec aac "./converted/' . $video_mp4 . '">convert.txt 2>&1', $output, $convert_status['mp4']);
Upvotes: 1