FFMPEG-based program to extract the time/date/GPS/speed information from a h264 video stream and make this available in a subtitle file of the SRT format.
Using googleapi, the GPS location information is translated to an address (street/place/state/country) where possible and added. An internet connection and the packages "wget" and "awk" are required for this to work.
Tested on Ubuntu 10.10 and Windows 7 – older/other versions may work as well.
Copyright (c) 2010, 2011 Henry Devettens - The Netherlands - henryd65@gmail.com
The GPS data can be entered directly as formatted into maps.google.com. In the example above, simply type “30 6 29.53 N 31 32 32.81 E” in the address field.
avchd2srt-core:
Following a brief discussion with Phil Harvey, I corrected the way 0x000003 data is treated. The bug resulted mainly in less data being extracted from the video stream than possible. Ref: http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,3330.0.html
avchd2srt-core:
Switched back to the frame rate determination method of v04, which seems more robust.
avchd2srt:
Tests for QUERY_LIMIT: google allows a max number of address requests per day
Switched to using wget instead of lynx for retrieving files from Internet
Information and errors sent to .log file instead of .inf
This script is now included in the Windows version
avchd2srt.awk:
New script, used by both the Linux and Windows version. Had to make it a separate file because I don't know how to include it in the source text of the cmd file on Windows (like it was on the Linux version).
Fixed the address extraction, because Google seem to have changed the data format...
avchd2srt-core:
following healthy challenge from Xymox finally got rid of avcodec_decode_video(), so now the core program is around 20 times faster. Also, it now appears frame accurate (for Sony generated PAL videos at least). Other than that exactly the same functionality as version 0.4.
Will provide two distribitions: one for Linux, one for Windows.
avchd2srt:
adapted for the new core output
more readable during processing
information and errors now sent to .inf file instead of .err
avchd2srt-core:
a couple of smaller changes to allow for compilation under mingw on Windows
added output of speed info if available in the GPS stream
fixed a bug when altitude exceeds 10000 m
reformatted the latitude/longitude output line
.srt output now sent to a file with same basename as input, .srt extension
printing #frames and timing (performance) at the end (on stderr)
avchd2srt:
fixed bug in moving srt- to srt when no internet and spaces in file names
better check whether the core program is in the same directory as the wrapper script
now creating UTF-8 srt files, enabling import by e.g. Corel VideoStudio Pro X3 from linux generated SRT files
avchd2srt-core:
Now believe Sony, Canon and Panasonic files are properly read
Using ffmpeg-0.6.1, which makes avchd2srt-core up to 25% faster
Subtitle now "Wednesday 29-Dec-2010" instead of "2010-12-29"
Subtitle now includes time zone info when available (Sony and Canon)
End time of one subtitle now equals start time of next (rather than 1 ms gap)
Subtitles one second older than previous one are ignored (assumed caused by B frames)
avchd2srt:
Changed to loop over "$@" iso "$*" - fixed the spaces in filenames problem
Made adding addresses conditional on having a working internet connection
avchd2srt-core:
Handles both Sony and Panasonic video streams
Combines two subsequent SRT subtitles when identical
No occasional one-millisecond gaps between two subsequent SRT subtitles
First beta release
For the complete FFMPEG package (0.6.1 has been used): http://www.ffmpeg.org/download.html
Phil Harley's exiftool and H264 doc: http://owl.phy.queensu.ca/~phil/exiftool/TagNames/H264.html
GMERLIN package, especially learnings from bgavdump: http://hirntier.blogspot.com
Example program for FFMPEG: http://dranger.com/ffmpeg/tutorial01.html
H264 muxer/demuxer: http://www.smlabs.net/tsmuxer_en.html
Sony AVC-HD camcorders insert metadata with every thirteenth frame or so, containing date, time, camera settings and when available geo-position information. This program reads the metadata and converts it to an SRT subtitle file. This makes it possible to edit and join single clips into one large fragment, then extract the metadata into an SRT file. Mediaplayers can then play both simultaneously. Or the SRT can be merged with the fragment using tsMuxeR (converting it to a PGS stream).
Use e.g. Sony's PMB for editing and tsMuxeR for joining clips.
More advanced use with e.g. Corel VideoStudio Pro X3:
trim and join the various video clips into one big video
use avchd2srt to create a date/time/position subtitle
import it in VideoStudio for further processing
Linux package:
avchd2srt-core.c: the source code for the core program (uses the ffmpeg package)
avchd2srt-core: Linux executable, running for instance under Ubuntu 10.10
avchd2srt: linux bash script wrapper around the core, adding address info
avchd2srt.awk: awk script used to extract the address from the google API information
00 Readme.html: this file
A2S capture.jpg: the example image that belongs to the Readme file.
Windows package:
avchd2srt-core.c: the source code for the core program (uses the ffmpeg package)
avchd2srt-core.exe: Windows executable, running for intstance under Windows7 (cmd script)
avchd2srt.cmd: Windows script wrapper around the core, adding address info
avchd2srt.awk: awk script used to extract the address from the google API information
00 Readme.html: this file
A2S capture.jpg: the example image that belongs to the Readme file.
The program was created on Ubuntu 10.10, running under VMPlayer 3.1.2 on Windows 7 HP. It has not been tested on other Linux releases. There may be unknown dependencies as a result.
The core does not depend on runtime libraries. The script requires wget and awk (gawk on Windows) to get address information from Google via Internet. If Google changes the data format the script may stop working correctly. That has happened already before... You may have to fix it in the avchs2srt.awk script.
Windows version also runs “stand alone”. Please note it cannot handle path names – only video files in the current folder.
Unpack the zipped tar file and store in a folder somewhere, preferably a folder in your path.
You can run the wrapper script (avchd2srt) from anywhere, as long as the core (avchd2srt-core) and the awk scrript (avchd2srt.awk) are in the same directory as the wrapper script. Usage:
avchd2srt videofile1.mts [videofile2.mts...]
This will create files videofile1.srt etc with the subtitle, videofile1.log with video and processing information and temporary file videofile1.loc with data for the address (if Internet is working). Wildcards in filenames are supported.
Make sure that the applications wget and gawk have been installed as well.
The Linux executable runs on Ubuntu 10.10, and as such can also easily be run in a guest Ubuntu using VMPlayer on Windows. Ubuntu 10.10 comes with wget and awk, so no additional installation is required.
The Windows executable runs on Windows 7 – other windows versions may work. Get “gawk.exe” from http://gnuwin32.sourceforge.net/packages/gawk.htm and get “wget.exe” from http://users.ugent.be/~bpuype/wget/#download, please make sure these are in a folder in your path.
The software is made available without any warranty - see also licensing below.
The core program will happily overwrite an .srt file if that was passed as a parameter. Hence make sure you only pass e.g. .m2ts or .MTS files.
Many, I'm sure.
Test more on non-Sony full HD camera's
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.