1VIDEO_FORMAT(7) DVDAuthor Man Pages VIDEO_FORMAT(7)
2
3
4
6 video_format - Proposal For A Video Format Preference Specification
7
9 A number of different programs that create or work with video material
10 need to know whether to generate their output in NTSC or PAL format.
11 The ones that I’ve seen seem to have a hard-coded preference for one
12 unless the user specifies the other. Overriding the default every time
13 you want to use these programs gets tiresome.
14
15 Therefore, there needs to be a way for the user to configure a single
16 default that will apply to all these programs. This default should be
17 settable on a per-user basis and a systemwide basis, with the per-user
18 setting overriding the systemwide one, as is usual. It makes sense to
19 avoid dotfile clutter by following, at least to some extent, the XDG
20 Base Directory Specification http://standards.freedesktop.org/basedir-
21 spec/latest/.
22
23 The preference setting shall consist of the single word “NTSC” or “PAL”
24 (without quotes, might as well be case-insensitive). This can be speci‐
25 fied in the following ways, in order of decreasing priority:
26
27 · As the value of the environment variable VIDEO_FORMAT
28
29 · As the contents of the user-specific file $XDG_CONFIG_HOME/video_for‐
30 mat, with $XDG_CONFIG_HOME defaulting to $HOME/.config if not
31 defined.
32
33 · As the contents of a systemwide file dir/video_format, where dir is
34 taken in turn from the colon-separated items in the value of
35 $XDG_CONFIG_DIRS until the file is found, or if $XDG_CONFIG_DIRS is
36 not defined, then the single directory /etc.
37
38 The application should use the first of these settings that it finds,
39 searching in the specified order.
40
41 Note: the XDG Base Dir spec says systemwide config files should go in
42 /etc/xdg. I'm not sure why this is, since lots of other apps put sys‐
43 temwide config in other places in /etc. Particularly since the spec
44 doesn’t similarly restrict shared read-only data to just one subdirec‐
45 tory of /usr/share.
46
48 Can this spec apply to both standard-definition and high-definition
49 video? For standard definition, there is a difference of frame size,
50 being 720 by 480 for NTSC and 720 by 576 for PAL (in both cases, the
51 aspect ratio of the displayed image is always 4:3). But this doesn’t
52 seem to matter for high definition. For both standard-definition and
53 high-definition, there is a difference of frame rates, based around
54 29.97 fps for NTSC and 25 fps for PAL.
55
56 Note also that if a config file earlier in the search contains an
57 invalid setting, the search does not continue even if another, later
58 config file might contain a valid setting. This allows the user to
59 override a system default with “no default”. Is this important? I think
60 it could be.
61
63 The following Python code implements a routine called
64 get_default_video_format that returns either one of the strings “NTSC”
65 or “PAL” indicating the user/system-configured default format as per
66 the spec above, or None if the default is invalid or not configured.
67
68 class xdg_base_dir :
69 "Implementation of relevant parts of the XDG Base Directory specification" \
70 " <http://standards.freedesktop.org/basedir-spec/latest/>."
71 @classmethod
72 def get_config_home(self) :
73 "returns the directory for holding user-specific config files."
74 result = os.environ.get("XDG_CONFIG_HOME")
75 if result == None :
76 result = os.path.join(os.environ["HOME"], ".config")
77 #end if
78 return result
79 #end get_config_home
80
81 @classmethod
82 def config_search_path(self) :
83 "returns the list of config directories to search (apart from the user area)."
84 return tuple(os.environ.get("XDG_CONFIG_DIRS", "/etc").split(":"))
85 # note spec actually says default should be /etc/xdg, but /etc is the
86 # conventional location for system config files.
87 #end config_search_path
88
89 @classmethod
90 def find_first_config_path(self, path) :
91 "searches for path in all the config directory locations in order of decreasing" \
92 " priority, returning the expansion where it is first found, or None if not found."
93 paths_to_try = iter((self.get_config_home(),) + self.config_search_path())
94 # highest priority first
95 while True :
96 this_path = next(paths_to_try, None)
97 if this_path == None :
98 break
99 this_path = os.path.join(this_path, path)
100 if os.path.exists(this_path) :
101 break
102 #end while
103 return this_path
104 #end find_first_config_path
105
106 #end xdg_base_dir
107
108 valid_video_formats = frozenset(("NTSC", "PAL"))
109
110 def get_default_video_format() :
111 video_format = os.environ.get("VIDEO_FORMAT")
112 if video_format == None :
113 config_file = xdg_base_dir.find_first_config_path("video_format")
114 if config_file != None :
115 try :
116 video_format = open(config_file, "r").readline().strip()
117 except OSError :
118 video_format = None
119 #end try
120 #end if
121 #end if
122 if video_format != None :
123 video_format = video_format.upper()
124 if video_format not in valid_video_formats :
125 video_format = None
126 #end if
127 #end if
128 return video_format
129 #end get_default_video_format
130
131
132
133
134 Fri Dec 30 19:47:26 CET 2005 VIDEO_FORMAT(7)