ffmpeg可以手动工作但不能用cron工作吗?

时间:2017-05-02 11:34:53

标签: php ffmpeg

当我手动运行脚本时,我可以成功将mp3 +音频转换为mp4。

exec("/usr/bin/ffmpeg -loop 1 -i $destination_thumbnail -i $input_file -c:a copy -c:v libx264 -shortest $videoPath 2>&1",$output);

当我在通过cron执行的脚本中有上述代码时,它不会转换。我收到了这个错误。

Array
(
    [0] => ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
    [1] =>   built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
    [2] =>   configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
    [3] =>   libavutil      54. 20.100 / 54. 20.100
    [4] =>   libavcodec     56. 26.100 / 56. 26.100
    [5] =>   libavformat    56. 25.101 / 56. 25.101
    [6] =>   libavdevice    56.  4.100 / 56.  4.100
    [7] =>   libavfilter     5. 11.102 /  5. 11.102
    [8] =>   libavresample   2.  1.  0 /  2.  1.  0
    [9] =>   libswscale      3.  1.101 /  3.  1.101
    [10] =>   libswresample   1.  1.100 /  1.  1.100
    [11] =>   libpostproc    53.  3.100 / 53.  3.100
    [12] => [mp3 @ 0x1d62bc0] Estimating duration from bitrate, this may be inaccurate
    [13] => Input #0, mp3, from '/home/example/public_html/wp-content/channels/videos/temp_1473937603.mp3':
    [14] =>   Duration: 00:06:51.05, start: 0.000000, bitrate: 64 kb/s
    [15] =>     Stream #0:0: Audio: mp3, 16000 Hz, stereo, s16p, 64 kb/s
    [16] => [mjpeg @ 0x1d73de0] Changeing bps to 8
    [17] => Input #1, image2, from '/home/examples/public_html/wp-content/channels/thumbnails/thumbnail_516919517.jpg':
    [18] =>   Duration: 00:00:00.50, start: 0.000000, bitrate: N/A
    [19] =>     Stream #1:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 250x135 [SAR 1:1 DAR 50:27], 2 fps, 2 tbr, 2 tbn, 2 tbc
    [20] => No pixel format specified, yuvj420p for H.264 encoding chosen.
    [21] => Use -pix_fmt yuv420p for compatibility with outdated media players.
    [22] => [libx264 @ 0x1d75240] height not divisible by 2 (250x135)
    [23] => Output #0, mp4, to '/home/example/public_html/wp-content/channels/videos/temp_1473937603.mp4':
    [24] =>     Stream #0:0: Video: h264, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 2 fps
    [25] =>     Metadata:
    [26] =>       encoder         : Lavc56.26.100 libx264
    [27] =>     Stream #0:1: Audio: none, 0 channels, 128 kb/s
    [28] => Stream mapping:
    [29] =>   Stream #1:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
    [30] =>   Stream #0:0 -> #0:1 (copy)
    [31] => Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
)

当我在conversion.php中手动执行脚本时,为什么这会起作用,但是当我通过cron运行conversion.php时,会出现上述错误?

1 个答案:

答案 0 :(得分:1)

正如它所说,在控制台中:[libx264 @ 0x1d75240] height not divisible by 2 (250x135)

添加-vf "scale='2*trunc(iw/2)':'2*trunc(ih/2)'"