ffmpeg: simultaneously overlaying and concatenating files

475 views Asked by At

I have a python program that is generating a stream of images to overlay on top of an MP4 file. This is working great. I pipe the image data from python to ffmpeg, and it overlays it on top of the video. I generate the images at a different framerate from the video file, and ffmpeg makes it all work.

Ignoring the python, as its probably not relevant here, the ffmpeg command line I run is:

(this isn't bash-quoted)

ffmpeg -y -i inputmpeg.mp4 -f rawvideo -framerate 10.0 -s 1920x1080 -pix_fmt rgba -i - -r 30 -filter_complex [0:v][1:v]overlay -vcodec libx264 -crf 18 -preset veryfast

To generate a scaled output image, I can sometimes call it with

-filter_complex [0:v][1:v]overlay,scale=-1:720

However, sometimes the input mpegs are split up over multiple files, so i'd like to do just the same here, but allow two (or three or ten) input files to be specified, which will result in them being played sequentially to the overlay filter to be overlayed with the images coming from stdin (-i -)

Thanks for any suggestions!

The camera in question is a GoPro. Here is some output from ffprobe

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GH070061.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2021-09-01T10:31:46.000000Z
    location        : xxxxx/
    location-eng    : xxxxx/
    firmware        : HD9.01.01.60.00
  Duration: 00:09:42.05, start: 0.000000, bitrate: 45276 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 44997 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
    Metadata:
      rotate          : 180
      creation_time   : 2021-09-01T10:31:46.000000Z
      handler_name    : GoPro AVC  
      encoder         : GoPro AVC encoder
      timecode        : 11:53:44:51
    Side data:
      displaymatrix: rotation of -180.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      creation_time   : 2021-09-01T10:31:46.000000Z
      handler_name    : GoPro AAC  
      timecode        : 11:53:44:51
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2021-09-01T10:31:46.000000Z
      handler_name    : GoPro TCD  
      timecode        : 11:53:44:51
    Stream #0:3(eng): Data: bin_data (gpmd / 0x646D7067), 61 kb/s (default)
    Metadata:
      creation_time   : 2021-09-01T10:31:46.000000Z
      handler_name    : GoPro MET  
    Stream #0:4(eng): Data: none (fdsc / 0x63736466), 13 kb/s (default)
    Metadata:
      creation_time   : 2021-09-01T10:31:46.000000Z
      handler_name    : GoPro SOS 

if the concatenation could also copy the "unknown codec" streams that would be a bonus - although perhaps another question.

1

There are 1 answers

8
llogan On

You can try the concat demuxer.

  1. Create a text file named input.txt containing a list of your files:

    file '0001.MTS'
    file '0002.MTS'
    file '0003.MTS'
    

    All inputs to the concat demuxer must share the same attributes.

  2. Run your ffmpeg command:

    ffmpeg -f concat -i inputs.txt -f rawvideo -framerate 10 -video_size 1920x1080 -pixel_format rgba -i - -r 30 -filter_complex "[0:v][1:v]overlay=format=auto,format=yuv420p" -c:v libx264 -crf 18 -preset veryfast -movflags +faststart output.mp4