Skip to main content
4 of 6
added 877 characters in body

How to fix ffmpeg concatenated video playback issue?

I want to put watermarks in my video (in Specific time). I researched some sources, and it said I need to (video filter) reencode the whole video to put a watermark, but I don't have a high-end PC to do this. If I reencode the whole video, it takes about 6 to 7 hours.

However, I have come up with some good ideas to do this. I created three segments, the first segment (19 mins) is the original video, the second segment (21 seconds) is where the watermark needs to be, and the third segment (15 mins) is also the original video. So, I put the watermark in the second segment and then concat them with ffmpeg (Note: I didn't re-encode all segments. I re-encoded only the second segment and merged them wit without re-encoded videos).

However,when going through segment 2, it encounters playback issues such as being stuck. However, I played the segments individually before concatting them, and they played smoothly. When concatenated, the playback issues occurred. FFmpeg details for the three segments are provided below

Segment 1 (Original video)

 libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pt1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:19:53.17, start: 0.066000, bitrate: 5467 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 5265 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 194 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]

Segment 2 (Watermark video)


 libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pt.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:21.20, start: 0.000000, bitrate: 11253 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 11048 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]


Segment 3 (Original video)

 libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pt3.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:39:47.56, start: 0.000000, bitrate: 5490 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 5287 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 194 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]


Concated full video


  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'full.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 01:00:01.93, start: 0.000000, bitrate: 5516 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 5313 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 194 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      

UPDATE 1 - Used FFMPEG Commands

These commands are from a shell script function.

Split command

ffmpeg -hide_banner -ss "0" -i "output.mp4" -t "90" -avoid_negative_ts make_zero -map "0:0" "-c:0" copy -map "0:1" "-c:1" copy -map_metadata 0 -movflags "+faststart" -ignore_unknown -f mp4 -y "tmp/output_1.mp4"

Applying watermark command

ffmpeg -hide_banner -i "tmp/output_2.mp4" -vf "drawtext='fontfile=DejaVu Sans\:style=Semibold:text=HelloWorld:fontcolor=white:fontsize=30:y=h-50*t:x=w-(t-4.5)*(w+tw)/15'" -vcodec libx264 -crf 15 -c:a copy "tmp/watermark_output_2.mp4"


Concat files command

ffmpeg -f concat -safe 0 -i "../filelist.txt" -c copy "output_merged.mp4"

UPDATE - 2 Uploaded output video to see what the issue is.

Sgement 1 original video (Without re-encode) https://drive.google.com/file/d/1Mg7rJxXGcxg25328flJ_CD9NJhfpFj37/view?usp=sharing

Sgement 2 watermark video (With re-encode) - watermark starts at 4 seconds and plays without any issue.

https://drive.google.com/file/d/141KYQ1m94bIpxKj5n7_wCcbTOWQ9uO17/view?usp=sharing

Sgement 3 original video (Without re-encode)

https://drive.google.com/file/d/1fYkFvD6Yg81Un7YhfUJbSJ-VBk2qlFvJ/view?usp=sharing

Concated full video (The issue starts when the watermark appears. (time 00:01:28 Minutes)

https://drive.google.com/file/d/1Tq6wXSWGSeAHBwfsV31-Qpt5BhJeWwSJ/view?usp=sharing

repeated error appearing during the concat process

[mp4 @ 0x5594ce3c8280] Non-monotonous DTS in output stream 0:0; previous: 8099300, current: 1715482; changing to 8099301. This may result in incorrect timestamps in the output file.