FFMpeg command to convert from avi to mp4 in php script

浪尽此生 提交于 2021-01-28 08:05:31

问题


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.

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     

Log after the attempt:

[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

回答1:


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.

Solutions

Compile

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

FFmpeg Wiki: Compile for RHEL/Fedora/CentOS

Or download

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.



来源:https://stackoverflow.com/questions/52322544/ffmpeg-command-to-convert-from-avi-to-mp4-in-php-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!