How to add a date stamp to a series of video files?
July 17, 2018 5:30 PM   Subscribe

I have a series of home videos that I've recorded on my iphone. The videos are in .mov format. I'd like to burn these videos to a dvd so that my parents can watch them. Before I do this, I'd like to find a program that can take all of the video files and stamp them with the date they were recorded. Can anyone suggest a program that can do this?

i.e. when the video plays, I want the date it was recorded to show in the corner of the video for a few seconds. There are many video files, so I'd prefer something where the process is automated.
posted by Proginoskes to Computers & Internet (8 answers total)
 
One roundabout way would be to 1) generate a .srt (subtitle) file per video containing the timestamp of the video as the sole subtitle and then 2) using vlc to burn the subtitle file into the video

I’ve burned “regular” srt files using vlc, and that worked great. In your case, are the file system timestamps equivalent to the date/time you’d like to see burned? i.e. in the Finder (if you’re under macOS), does the date/time for the movie files correspond to when those videos were made? (I’m assuming that yes)
posted by vert canard at 8:56 PM on July 17, 2018


It might be easier to add a title card at the beginning of each video. That way you could include date, but also location, or names of people in the video.
posted by ActingTheGoat at 10:31 PM on July 17, 2018


Best answer: Can't suggest anything useful for doing this natively on an iPhone, but if you can copy the files to a desktop machine you could build a bulk time-stamping script around ffmpeg.

Here's a bash script that works on my Debian box:
#!/bin/bash
# Process all the files and folders specified on the command line.
find "$@" -type f -not -name '*-stamped.*' -printf '%T@ %p\n' |
while read -r modified pathname
do
	# Make sure this is a valid video file and
	# get its creation time tag value, if any.
	created=$(ffprobe "$pathname" \
		-loglevel quiet \
		-of csv=p=0:nk=1 \
		-show_entries format_tags=creation_time
	) || continue

	# Convert video creation or file modification time
	# to a human readable timestamp. Note: ffmpeg requires
	# ridiculous amounts of escaping on colons in overlay text.
	timestamp=$(date -d "${created:-@$modified}" +'%Y-%m-%d %H\\\:%M')

	# Make an output pathname by adding "-stamped" between
	# the basename and extension of the existing pathname.
	output=${pathname%.*}-stamped.${pathname##*.}

	# Build drawtext video filter spec.
	drawtext="
		text='$timestamp'
	:	fontfile=/usr/share/fonts/truetype/liberation2/LiberationSans-Bold.ttf
	:	fontsize=40
	:	fontcolor=white
	:	borderw=4
	:	bordercolor=black
	:	box=0
	:	x=40
	:	y=40
	:	enable='between(t,0,5)'
	"

	# Make a new video with a timestamp overlay.
	ffmpeg \
		-nostdin \
       		-y \
		-i "$pathname" \
		-vf "drawtext=$drawtext" \
		-c:a aac \
		-c:v h264 \
		"$output"
done
It shouldn't be too hard to adapt this for use on Mac OS or Windows, as ffmpeg is available for both and the script glue doesn't need to do anything complicated. Let me know if you need a hand doing that; ffmpeg is powerful and capable, but because it wedges all its scripting functionality into its command line parser, getting its command lines right can be a pain in the arse. Also, the Mac find and date commands work differently to the Gnu versions that come with Debian.
posted by flabdablet at 4:45 AM on July 18, 2018 [2 favorites]


Response by poster: flabdablet - I actually only have a windows machine. Would you be able to help me convert the script to something that I could use on Windows? Also, how exactly do I use the script? I've installed ffmpeg, but not sure what to do beyond that in order to use the script. Sorry - I'm a bit technologically naive about these things. :)
posted by Proginoskes at 9:28 AM on July 18, 2018


Best answer: Okay, try this: copy the following script and paste it into Notepad, then save it as add-stamps.cmd (when you're doing the Save As, change the Save as type: from Text Documents to All Files, otherwise Notepad will make add-stamps.cmd.txt and that won't work). Usage instructions will be in the next comment.
<#	:cmd launcher for PowerShell script
@	set ps1="%TMP%\%~n0-%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.ps1"
@	copy /b /y "%~f0" %ps1% >nul
@	powershell -NoProfile -ExecutionPolicy Bypass -File %ps1% %*
@	del /f %ps1%
@	goto :eof
#>

# Find the ffmpeg executables.
$bin = gi "$env:ProgramFiles\ffmpeg*\bin"
$ffprobe = "$bin\ffprobe.exe"
$ffmpeg = "$bin\ffmpeg.exe"

# Process all the files and folders specified on the command line.
$Args | dir -recurse -exclude *-stamped.* | %{
	# Make sure this is a valid video file and
	# get its creation time tag value, if any.
	$creation_time_tag = &$ffprobe "$_" `
		-loglevel quiet `
		-of csv=p=0 `
		-show_entries format_tags=creation_time

	# If ffprobe exits with success, file can be
	# processed by ffmpeg.
	if ($?) {
		# Generate video overlay text from creation time tag
		# if it exists, otherwise use file modification time.
		$time = $_.LastWriteTime
		if ($creation_time_tag) {$time = get-date $creation_time_tag}
		$text = '{0:yyyy-MM-dd hh:mm}' -f $time

		# Build drawtext video filter spec from an array of strings using
		# -replace and -join to drag something resembling sanity out of
		# ffmpeg's -vf argument parser, which treats : and \ characters
		# as special and needs them prefixed with \ in order to take them
		# literally.
		$drawtext = (
			"text='$text'",
			"fontfile='$env:SystemRoot\Fonts\arialbd.ttf'",
			"fontsize=40",
			"fontcolor=white",
			"borderw=4",
			"bordercolor=black",
			"box=0",
			"x=40",
			"y=40",
			"enable='between(t,0,5)'"
		) -replace '([:\\])', '\$1' -join ':'

		# Make an output pathname by adding "-stamped" between
		# the basename and extension of the existing pathname.
		$output = "$($_.DirectoryName)\$($_.BaseName)-stamped$($_.Extension)"

		# Make a new video with overlaid text.
		&$ffmpeg -y -i $_ -vf "drawtext=$drawtext" $output
	}
}

posted by flabdablet at 7:18 AM on July 19, 2018 [1 favorite]


Best answer: To try out the script, use Windows Explorer to drag a JPEG picture file and drop it onto add-stamps.cmd's icon. You should see a black window with pile of scrolling crap open briefly, and when that closes, you should find a new JPEG file appear in the same folder as the one you dragged, with "-stamped" appended to its name; and when you open that, you should see the original picture with the original file's modification date and time overlaid in the top left corner.

If that doesn't work, the most likely thing is that you're either using a different version of ffmpeg from the one I tried, or you've put it somewhere the script wasn't expecting to find it. I used a 32-bit Windows installation to test this, so I downloaded the Version 4.0.1, Windows 32-bit, Shared linking Zeranoe build of ffmpeg, opened the Zip file with Windows Explorer, copied the ffmpeg-4.0.1-win32-shared folder inside it and pasted that into C:\Program Files.

If you have a 64-bit Windows, doing exactly the same thing with the Version 4.0.1, Windows 64-bit, Shared linking build should work fine.

The script assumes that there is exactly one subfolder of Program Files whose name begins with "ffmpeg" and has a "bin" subfolder, and that this subfolder contains ffprobe.exe and ffmpeg.exe. If any of those assumptions are wrong, it will break. Let me know if it breaks for you and I'll try to fix it.

If you do manage to get it to work with a JPEG, try it with a video file. It should make a "-stamped" version that looks the same as the original, with a timestamp overlaid in the top left corner for the first five seconds.

And if that works, you can run it against a batch of video files, either by multi-selecting them before dragging and dropping the whole group onto add-stamps.cmd or by dragging and dropping their containing folder.

If the existing logic for working out what to put in the timestamp doesn't suit you, or you don't like the timestamp format, or you don't like the convention for generating output filenames from input filenames, let me know and I'll work with you to tweak the script to suit.
posted by flabdablet at 7:43 AM on July 19, 2018 [2 favorites]


Response by poster: Thank you flabdablet, that worked perfectly!!
posted by Proginoskes at 5:38 PM on July 19, 2018


That makes me happy. Thanks for letting me know.
posted by flabdablet at 4:28 AM on July 20, 2018


« Older Recipes with large (at least 1/2 C) quantities of...   |   Physics/math problem - how to get from one... Newer »
This thread is closed to new comments.