-1

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.

time4tea
  • 2,169
  • 3
  • 16
  • 21
  • The inputs will have the same attributes. The process that generates them simply creates a new file from the camera stream when the output file size reaches 4GB - this is a vendor product that I cannot change. – time4tea Oct 06 '21 at 08:40

1 Answers1

0

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
    
llogan
  • 121,796
  • 28
  • 232
  • 243
  • thanks - i'll give this a try.... – time4tea Oct 07 '21 at 10:26
  • Sorry! I didn't get a chance to try yet. Next day or so I will have some time. – time4tea Oct 10 '21 at 18:20
  • it sort of works... although it doesn't pass through essential information regarding orientation - e.g. "displaymatrix rotation of -180 degrees" - so the concat'ed movies are all upside down (from my camera - it *is* mounted upside down, but without the concat filter, it just works) – time4tea Oct 13 '21 at 13:32
  • @time4tea Copy and paste the complete output from `ffmpeg -i one-of-the-videos-listed-in-inputs.txt-that-gets-rotated-incorrectly.mp4` This will show required info. You can edit your question to add this info. – llogan Oct 13 '21 at 16:13
  • i updated the question as requested. I hope it gives you useful information. thanks for your help so far! – time4tea Oct 24 '21 at 15:05
  • @time4tea Does each input have the same `displaymatrix: rotation` value? – llogan Oct 25 '21 at 15:43
  • it is very likely (95%) that they will, but I'm not sure that I know in advance what that will be - depends on how the camera is mounted. – time4tea Oct 26 '21 at 08:28
  • @time4tea Worked for me to concatenate 3 videos with `displaymatrix: rotation of -180.00 degrees` sidedata. Output preserved the rotation sidedata. I did not include a piped rawvideo overlay. Unfortunately, you did not provide the **complete** output as asked for, so I can only suggest that your ffmpeg might be old so upgrade. Other guesses: 1) the rotation sidedata of the original file is possibly incorrect. 2) Your player is ignoring the rotation sidedata. Try playing the output with current ffplay or mpv to verify. – llogan Oct 28 '21 at 15:47