FFMpeg命令在php脚本中从avi转换为mp4 [英] FFMpeg command to convert from avi to mp4 in php script

查看:142
本文介绍了FFMpeg命令在php脚本中从avi转换为mp4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ffmpeg命令从下面的avi文件转换为mp4文件确实创建了mp4文件,但是它的质量不是很好.拳头,文件大小不同,mp4小得多,约为avi文件的1/10.其次,新创建的mp4的播放时间持续约0.1秒,而avi文件持续约60秒.

ffmpeg command to convert from avi file to mp4 file below does create mp4 file, but the quality of it is not all right at all. Fist, the sizes of the files are different, the mp4 is much smaller and about 1/10 of the avi file. Second, the playing time of the newly created mp4 is short lasting about 0.1 seconds where the avi file lasts about 60 seconds.

有人可以帮我帮助ffmpeg命令从avi下创建mp4文件吗?

Can anyone please help me out for the ffmpeg command to create mp4 file from avi under the directory like below?

for i in /xxxxxxx/xxxxxxx/*.avi; do
    ffmpeg -i "$i" -frames:v 1  "/xxxxxxx/xxxxxxx/$(basename "$i" .avi).mp4"
done     

尝试后登录:

[root@server-xxxxxxx-x ~]# for i in /xxxxxx/xxxxxxx/xxxxxxx/*.avi; do ffmpeg -i "$i" -pix_fmt yuv420p -movflags +faststart "/xxxxxx/xxxxxxx/xxxxxxx/$(basename "$i" .avi).mp4"; done
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18)
  configuration:
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
 Guessed Channel Layout for Input Stream #0.1 : mono
 Input #0, avi, from '/xxxxxx/xxxxxxx/xxxxxxx/09141944_5b9b910308858.avi':
  Metadata:
    creation_time   : 2018-09-14 00:18:07
    encoder         : CanonMVI06
   Duration: 00:00:04.20, start: 0.000000, bitrate: 12999 kb/s
    Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc,    bt470bg/unknown/unknown), 640x480, 12384 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
     Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
 File '/xxxxxx/xxxxxxx/xxxxxxx/09141944_5b9b910308858.mp4' already exists.    Overwrite ? [y/N]

                                                                                                                          y
 Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (native))
  Press [q] to stop, [?] for help
  [swscaler @ 0x3d75fa0] deprecated pixel format used, make sure you did set   range correctly
 Output #0, mp4, to '/xxxxxx/xxxxxxx/xxxxxxx/09141944_5b9b910308858.mp4':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 640x480, q=2-31, 200 kb/s, 30 fps, 65521 tbn, 30 tbc
    Metadata:
      encoder         : Lavc57.107.100 mpeg4
     Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
     Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s
     Metadata:
       encoder         : Lavc57.107.100 aac
  [mp4 @ 0x3d0e6e0] Starting second pass: moving the moov atom to the  beginning of the file17x
  frame=  126 fps=0.0 q=11.8 Lsize=     310kB time=00:00:04.20 bitrate= 603.3kbits/s speed=6.21x
  video:270kB audio:35kB subtitle:0kB other streams:0kB global headers:0kB  muxing overhead: 1.605194%
  [aac @ 0x3d36f40] Qavg: 2283.534
  ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
   built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18)
   configuration:
   libavutil      55. 78.100 / 55. 78.100
   libavcodec     57.107.100 / 57.107.100
   libavformat    57. 83.100 / 57. 83.100
   libavdevice    57. 10.100 / 57. 10.100
   libavfilter     6.107.100 /  6.107.100
   libswscale      4.  8.100 /  4.  8.100
   libswresample   2.  9.100 /  2.  9.100
   Guessed Channel Layout for Input Stream #0.1 : mono
   Input #0, avi, from '/xxxxxx/xxxxxxx/xxxxxxx/09141945_5b9b913e87834.avi':
    Metadata:
     creation_time   : 2018-09-14 00:18:07
     encoder         : CanonMVI06
    Duration: 00:00:04.20, start: 0.000000, bitrate: 12999 kb/s
    Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc,      bt470bg/unknown/unknown), 640x480, 12384 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono,    s16, 705 kb/s

推荐答案

问题:您不支持编码器

您的配置行为空.这意味着您没有启用H.264/H.265视频编码器.因此, ffmpeg 选择本机编码器 mpeg4 输出MPEG-4 Part 2视频.这是HTML5视频不支持的旧格式.

Problem: You have no supported encoder

Your configuration line is blank. This means that you do not have an H.264/H.265 video encoder enabled. So ffmpeg chooses the native encoder mpeg4 which outputs MPEG-4 Part 2 video. This is an old format which is not supported by HTML5 video.

使用-enable-libx264 -enable-libx265 进行编译.您还需要-enable-gpl 才能使用这些编码器.有关说明,请参见本指南:

Compile using --enable-libx264 or --enable-libx265. You'll also need --enable-gpl to use these encoders. See this guide for instructions:

FFmpeg Wiki:针对RHEL/Fedora/CentOS进行编译

或者,一种简单的方法是下载已经编译的 ffmpeg 并将其放在您的PATH中的某个位置,例如/usr/local/bin .或者,如果您希望脚本在任意位置,请确保脚本提供了可执行文件的完整路径.确保执行此新的 ffmpeg 而不是旧的,残废的代码.

Alternatively, an easy method is to download an already compiled ffmpeg and put it somewhere in your PATH, such as /usr/local/bin. Or make sure your script provides the full path to the executable if you want it in an arbitrary location. Ensure that this new ffmpeg gets executed instead of your old, crippled one.

这篇关于FFMpeg命令在php脚本中从avi转换为mp4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆