使用ffmpeg在电影之前添加JPG图像

问题描述:

我想使用ffmpeg从JPG图像和一些电影文件创建新电影.影像应在影片开头显示几秒钟.这可以使用命令

I would like to create a new movie from a JPG image and some movie file using ffmpeg. The image should be displayed for some seconds at the beginning of the movie. This can be achieved using the command

ffmpeg -loop 1 -framerate 60 -t 8 -i image.jpg -t 8 -f lavfi -i aevalsrc=0 -i movie.mp4 -filter_complex '[0:0] [1:0] [2:0] [2:1] concat=n=2:v=1:a=1' output.mp4

此处帧速率为60fps,图像显示8秒钟.一切都很好,但是又花费了很多时间,因为所有内容都重新编码了.相反,我尝试首先使用

Here the framerate is 60fps and the image is shown for 8 seconds. This all works fine, but takes a lot of time as everything is encoded again. Instead I tried to create a movie from the image first using

ffmpeg -loop 1 -framerate 60 -i image.jpg -c:v libx264 -t 8 -pix_fmt yuv420p intro.mp4

,然后将简介连接到电影文件,如此处所述 https://trac.ffmpeg.org/wiki/Concatenate .第二种方法明显更快,但是生成的电影文件没有音频.有人知道这样做的快速方法吗?

and then concatenating the intro to the movie file as described here https://trac.ffmpeg.org/wiki/Concatenate. The second method is significantly faster, but the resulting movie file has no audio. Does anyone know a fast method to do this?

根据下面的请求,我发布了 ffmpeg -i movie.mp4 ,它给出了

As per the request below, I post ffmpeg -i movie.mp4, it gives

ffmpeg -i movie.mp4                   
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'movie.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:01:36.55, start: 0.000000, bitrate: 445 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1488x1116, 301 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 131 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

  1. 制作 intro.mp4 :匹配 movie.mp4 的属性.

ffmpeg -loop 1 -framerate 60 -t 8 -i image.jpg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -filter_complex "[0]scale=1488:1116:force_original_aspect_ratio=increase,crop=1488:1116,setsar=1,format=yuvj420p[v]" -map "[v]" -map 1 -c:v libx264 -c:a aac -shortest intro.mp4

  • 使 input.txt 包含:

    file 'intro.mp4'
    file 'movie.mp4'
    

  • concat多路复用器连接:

    ffmpeg -f concat -i input.txt -c copy -movflags +faststart output.mp4
    

  • 如果要填充而不是裁剪以适合图像以匹配图像,请参见使用ffmpeg调整视频大小以适应特定大小.视频.

    See Resizing videos with ffmpeg to fit specific size if you want to pad instead of crop to fit the image to match the video.