0

file does not save sometimes. can someone please tell me the reason for it.

pipe = Popen(f'exiftool.exe -p "lib/ExifTool/gpx.fmt" -S -ext mov -ee "{video_file}" >> "temp/gpx.xml"', shell=True, stdout=PIPE)
  • 1
    See [this recent question](https://stackoverflow.com/questions/70611277/exiftool-export-json-with-python). Redirection is a property of the command shell and might not be available when calling from python. – StarGeek Jan 18 '22 at 15:52
  • You may have to capture the output in python and save it to a file, as the `-w` option doesn't work with the `-p` option used to create the GPX track. – StarGeek Jan 18 '22 at 15:59
  • i tried to capture output from python but it didn't capture all of the output. it capture only some lines – Yasiru Withanage Jan 19 '22 at 04:32
  • part of terminal output Warning: [Minor] Tag 'Doc29:gpsaltitude' not defined - data/2021_0429_171543_002.MOV Warning: [Minor] Tag 'Doc30:gpsaltitude' not defined - data/2021_0429_171543_002.MOV Warning: [Minor] Tag 'Doc39:gpsaltitude' not defined - data/2021_0429_171543_002.MOV – Yasiru Withanage Jan 19 '22 at 04:33
  • part of python output Warning: [Minor] Tag 'Doc29:gpsaltitude' not defined - data/2021_0429_171543_002.MOV Warning: [Minor] Tag 'Doc30:gpsaltitude' not defined - data/2021_0429_171543_002.MOV Warning: [Minor] Tag 'Doc39:gpsaltitude' not defined - data/2021_0429_171543_002.MOV – Yasiru Withanage Jan 19 '22 at 04:34

1 Answers1

0

The warnings you received (and the failure to write) are caused by one of the following:

  • Tags ExifTool found in your videos that it doesn't recognize and therefore won't write (but can still read).
  • Tags that were specified in your print format file (gpx.fmt), that do not exist.

Writing the output to files using Python instead may help you work around the the first issue. Using -f in your ExifTool command will set the value equal to a dash '-' if a tag you specified in your print format file wasn't found. Alternatively you could use an if-statement in your print format file or -m in your command to avoid warnings.

Here is an example where Python is used to capture the ExifTool output and write it to an XML file:

import shlex, subprocess
format_filepath = "Path/To/gpx.fmt"
input_dirpath = "Path/To/Dir"
output_filepath = "Path/To/out.xml"
# I have added the path to exiftool.exe to my PS env so I can just pass exiftool
arg_str = f"exiftool -p {format_filepath} -S -ee -f -ext mov {input_dirpath}"
args = shlex.split(arg_str)
# args=['exiftool', '-p', 'Path/To/gpx.fmt', '-S', '-ee', '-f', '-ext', 'mov', 'Path/To/Dir']
# shell=True is not needed here because ExifTool is an executable
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# You may use code=proc.wait() here, where code=0 means the proccess executed successfully
stdout,stderr = proc.communicate()
# communicate() returns bytes by default
with open(output_filepath, 'wb') as fout:
    fout.write(stdout)

Print format file gpx.fmt:

#[HEAD]<?xml version="1.0" encoding="utf-8"?>
#[HEAD]<gpx version="1.0"
#[HEAD] creator="ExifTool $ExifToolVersion"
#[HEAD] xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
#[HEAD] xmlns="http://www.topografix.com/GPX/1/0"
#[HEAD] xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
#[HEAD]<trk>
#[HEAD]<number>1</number>
#[HEAD]<trkseg>
#[BODY]<trkpt lat="$gpslatitude#" lon="$gpslongitude#">
# Without adding -f or -m to cmd, the below three elements will give Warnings
#[BODY]  <ele>$Doc29:gpsaltitude#</ele>
#[BODY]  <ele>$Doc30:gpsaltitude#</ele>
#[BODY]  <ele>$Doc39:gpsaltitude#</ele>
# or try the following element instead:
#[BODY]  <ele>$gpsaltitude#</ele>
#[BODY]  <time>${gpsdatetime#;my ($ss)=/\.\d+/g;DateFmt("%Y-%m-%dT%H:%M:%SZ");s/Z/${ss}Z/ if $ss}</time>
#[BODY]</trkpt>
#[TAIL]</trkseg>
#[TAIL]</trk>
#[TAIL]</gpx>
Camden
  • 58
  • 7