FFMPEG - Add text to jpeg timelapse and efficient transcoding question

Hi there,

I am struggling and run out of ideas on how to get around this challenge. There are two core problems:

  1. Adding a specific text label to each image I am rendering together
  2. Most efficient way of cropping all the videos and outputting different resolutions.

Issue 1 - Labels
I have a collection of images that I am stitching together into a timelapse. This is working ok with NVIDIA CUDA acceleration. It is running in my Python script fine as well.

However, I would like to put the file names on each frame. Or specifically:
File name: 2024-01-01-11-00-00.jpg
Label: 2024-01-01 11:00:00

"ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -r 8 -safe 0 -f concat -i {1} -c:v hevc_nvenc -b:v 41M {0}_FULL.mp4 \
                                -vf scale_npp=3840:2160 -c:a copy -c:v h264_nvenc -b:v 20M {0}_UHD.mp4 \
                                -vf scale_npp=1920:1080 -c:a copy -c:v h264_nvenc -b:v 8M {0}_FHD.mp4 \
                                -vf scale_npp=1280:720 -c:a copy -c:v h264_nvenc -b:v 5M {0}_HD.mp4 \
                                -vf scale_npp=640:480 -c:a copy -c:v h264_nvenc -b:v 2M {0}_SD.mp4".format(local_file_path_base, os.path.abspath('files.txt'))

I’ve researched this extensively but have not been able to produce a reliable solution. The best I could find is opening up each file, stamping the name on it, and rendering the video. That takes ages and I don’t think it works with the NVIDIA FFMPEG compiled version that well.

The docs mention something to do with a textlabels file or something but I couldn’t get that to work either.

So, is there a way I can get FFMPEG to label my pictures as outlined above?

Issue 2 - Efficient Scaling

I am going to continue outputting each of the videos in the 5 formats above, however, I also need to produce an additional cropped frame from the larger videos.

The best I could manage to get the cropping working was to use the raw photos again to stitch together a video and then crop each resolution.

ffmpeg -hwaccel_output_format cuda -extra_hw_frames 0 -r 8 -safe 0 -f concat -i files.txt -vf "crop=4933:1961:2361:297,drawtext=fontfile=/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf: text='test': fontsize=10: x=2: y=2: fontcolor=yellow: box=0" -c:v hevc_nvenc -b:v 41M output4_full.mp4 -map 0:0 -vf "crop=4933:1961:2361:297,hwupload_cuda,scale_npp=3840:2160" -c:a copy -c:v h264_nvenc -b:v 20M output4_uhd.mp4 -map 0:0 -vf "crop=4933:1961:2361:297,hwupload_cuda,scale_npp=1920:1080" -c:a copy -c:v h264_nvenc -b:v 8M output4_fhd.mp4 -map 0:0 -vf "crop=4933:1961:2361:297,hwupload_cuda,scale_npp=1280:720" -c:a copy -c:v h264_nvenc -b:v 5M output4_hd.mp4 -map 0:0 -vf "crop=4933:1961:2361:297,hwupload_cuda,scale_npp=640:480" -c:a copy -c:v h264_nvenc -b:v 2M output4_sd.mp4

I read in the NVIDIA documentation about more efficient ways, however, each time I have tried them the FFMPEG segmentation faults.

Any chance someone has done this or knows better than I do on how to make this more efficient?

Progress Update

I asked a friend how to do this. They gave me two tutorials on how to use or stamp subtitles onto the video. This seems to be working well. I am just building the whole pipeline and workflow.

Format: Create an SRT File: Your Complete Guide
Usage: mp4 - Use ffmpeg to add text subtitles - Stack Overflow

Will report back once the whole pipeline is operational!