![编码使视频更长,因此与视频不同步](https://linux22.com/image/1477102/%E7%BC%96%E7%A0%81%E4%BD%BF%E8%A7%86%E9%A2%91%E6%9B%B4%E9%95%BF%EF%BC%8C%E5%9B%A0%E6%AD%A4%E4%B8%8E%E8%A7%86%E9%A2%91%E4%B8%8D%E5%90%8C%E6%AD%A5.png)
我有一个音频和视频输入,必须将其转码为libx264
和libfdk_aac
。
为了做到这一点,我准备了这个 ffmpeg 句子:
ffmpeg -i temp/filename.wav -i temp/filename.webm -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -map 0:0 -map 1:0 -fflags +genpts -vcodec libx264 -threads 0 -b:a 128k temp/filename.mp4'
不知为何,当我直接在控制台上执行该句子时,它起作用,但如果我使用 php 执行它,它不知为何不起作用。
有人能帮我找出问题所在吗?
谢谢建议。
编辑1
由于我遇到 libfdk_aac 错误,我已将 ffmpeg 句子更新为此。
ffmpeg -i temp/filename.wav -i temp/filename.webm -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -map 0:0 -map 1:0 -fflags +genpts -c:v libx264 -preset ultrafast -qp 0 -c:a libvo_aacenc -b:a 128k temp/filename.mp4'
应要求埃利我正在发布完成该过程的所有步骤:
JavaScript 文件使用媒体流捕获视频和音频(均与摄像头和麦克风分开),然后我通过 AJAX 将其打包成 formData(php 脚本)上传到服务器:
function uploadVideo(url, data, callback) {
var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { callback(xhr.responseText); } }; xhr.open('POST', url); xhr.send(data); }function upload() { var formData = new FormData(), path,audioBlob, videoBlob; path = 'video/chromeAnswer'; formData.append('filename', video_temp_name); formData.append('audio-blob', source.recordRTC[0].getBlob()); formData.append('video-blob', source.recordRTC[1].getBlob()); uploadVideo(path, formData, function (ffmpeg_output) { window.console.log(ffmpeg_output); }); }
将视频移动到 A2 Azure 实例临时实例文件夹并使用下一个函数进行处理:
public function chromeFFmpeg($filename) { $cmd = 'ffmpeg -i temp/filename.wav -i temp/filename.webm -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -map 0:0 -map 1:0 -fflags +genpts -vcodec libx264 -threads 0 -b:a 128k temp/filename.mp4' exec(escapeshellcmd($cmd), $out, $return); unlink(TEMP . $filename . '.webm'); unlink(TEMP . $filename . '.wav'); if ($return === false) { return false; } return true; }
该过程正确完成并且没有错误日志,但我还粘贴了视频、音频和结果ffprobe
的分析:.webm
.wav
.mp4
ffmpeg version 2.7.3-0ubuntu0.15.10.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.1 (Ubuntu 5.2.1-22ubuntu2) 20151010
configuration: --prefix=/usr --extra-version=0ubuntu0.15.10.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=$
WARNING: library configuration mismatch
avcodec configuration: --prefix=/usr --extra-version=0ubuntu0.15.10.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-g$
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, matroska,webm, from '../project/temp/92.webm':
Metadata:
encoder : whammy
Duration: 00:00:02.21, start: 0.000000, bitrate: 1408 kb/s
Stream #0:0: Video: vp8, yuv420p, 221x221, SAR 1:1 DAR 1:1, 1k tbr, 1k tbn, 1k tbc (default)
At least one output file must be specified
[Wed Dec 16 20:44:09.121995 2015] [:error] [pid 5958] [client 130.117.93.205:47172] PHP Notice: Undefined offset: 1 in /var/www/html/dev1/project/models$
[Wed Dec 16 20:44:09.122037 2015] [:error] [pid 5958] [client 130.117.93.205:47172] PHP Notice: Undefined offset: 1 in /var/www/html/dev1/project/models$
[Wed Dec 16 20:44:09.122043 2015] [:error] [pid 5958] [client 130.117.93.205:47172] PHP Notice: Undefined offset: 2 in /var/www/html/dev1/project/models$
ffmpeg version 2.7.3-0ubuntu0.15.10.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.1 (Ubuntu 5.2.1-22ubuntu2) 20151010
configuration: --prefix=/usr --extra-version=0ubuntu0.15.10.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=$
WARNING: library configuration mismatch
avcodec configuration: --prefix=/usr --extra-version=0ubuntu0.15.10.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-g$
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, matroska,webm, from '../project/temp/92.webm':
Metadata:
encoder : whammy
Duration: 00:00:02.21, start: 0.000000, bitrate: 1408 kb/s
Stream #0:0: Video: vp8, yuv420p, 221x221, SAR 1:1 DAR 1:1, 1k tbr, 1k tbn, 1k tbc (default)
[swscaler @ 0x21c7d40] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '../project/temp/92.jpg':
Metadata:
encoder : Lavf56.36.100
Stream #0:0: Video: mjpeg, yuvj420p(pc), 221x221 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 1k fps, 1k tbn, 1k tbc (default)
Metadata:
encoder : Lavc56.41.100 mjpeg
Stream mapping:
Stream #0:0 -> #0:0 (vp8 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame= 1 fps=0.0 q=3.7 Lsize=N/A time=00:00:00.02 bitrate=N/A
video:6kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
ffmpeg version 2.7.3-0ubuntu0.15.10.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.1 (Ubuntu 5.2.1-22ubuntu2) 20151010
configuration: --prefix=/usr --extra-version=0ubuntu0.15.10.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=$
WARNING: library configuration mismatch
avcodec configuration: --prefix=/usr --extra-version=0ubuntu0.15.10.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-g$
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from '../project/temp/92.wav':
Duration: 00:00:02.23, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
Input #1, matroska,webm, from '../project/temp/92.webm':
Metadata:
encoder : whammy
Duration: 00:00:02.21, start: 0.000000, bitrate: 1408 kb/s
Stream #1:0: Video: vp8, yuv420p, 221x221, SAR 1:1 DAR 1:1, 1k tbr, 1k tbn, 1k tbc (default)
[libx264 @ 0x7f5080] using SAR=1/1
[libx264 @ 0x7f5080] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7f5080] profile High 4:4:4 Predictive, level 3.2, 4:2:0 8-bit
[libx264 @ 0x7f5080] 264 - core 146 r2555 0c21480 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=0 r$
Output #0, mp4, to '../project/temp/92.mp4':
Metadata:
encoder : Lavf56.36.100
Stream #0:0: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s
Metadata:
encoder : Lavc56.41.100 libvo_aacenc
Stream #0:1: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 220x220 [SAR 1:1 DAR 1:1], q=-1--1, 1k fps, 16k tbn, 1k tbc (default)
Metadata:
encoder : Lavc56.41.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le (native) -> aac (libvo_aacenc))
Stream #1:0 -> #0:1 (vp8 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 304 fps=0.0 q=0.0 size= 287kB time=00:00:00.33 bitrate=7011.9kbits/s dup=292 drop=0 ^Mframe= 665 fps=621 q=0.0 size= 574kB time=00:0$
video:1893kB audio:36kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.600680%
[libx264 @ 0x7f5080] frame I:9 Avg QP: 0.00 size: 26600
[libx264 @ 0x7f5080] frame P:2201 Avg QP: 0.00 size: 772
[libx264 @ 0x7f5080] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x7f5080] mb P I16..4: 1.5% 0.0% 0.0% P16..4: 1.5% 0.0% 0.0% 0.0% 0.0% skip:97.0%
[libx264 @ 0x7f5080] coded y,uvDC,uvAC intra: 98.6% 97.2% 97.0% inter: 1.5% 1.6% 1.6%
[libx264 @ 0x7f5080] i16 v,h,dc,p: 34% 65% 0% 0%
[libx264 @ 0x7f5080] i8c dc,h,v,p: 2% 61% 38% 0%
[libx264 @ 0x7f5080] kb/s:7014.78
主要问题是视频卡顿。