1 /*****************************************************************************
2 * vdr.c: VDR recordings access plugin
3 *****************************************************************************
4 * Copyright (C) 2010 Tobias Güntner
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
22 VDR splits recordings into multiple files and stores each recording in a
23 separate directory. If VLC opens a normal directory, the filesystem module
24 will add all files to the playlist. If, however, VLC opens a VDR recording,
25 this module will join all files within that directory and provide a single
26 continuous stream instead.
28 VDR recordings have either of two directory layouts:
30 /path/to/0000-00-00.00.00.00.00.rec/
31 001.vdr, 002.vdr, 003.vdr, ...
32 index.vdr, info.vdr, marks.vdr, ...
34 /path/to/0000-00-00.00.00.0-0.rec/
35 00001.ts, 00002.ts, 00003.ts, ...
36 index, info, marks, ...
37 See http://www.vdr-wiki.de/ and http://www.tvdr.de/ for more information.
40 /*****************************************************************************
42 *****************************************************************************/
48 #include <sys/types.h>
53 #elif defined( WIN32 )
61 #include <vlc_common.h>
62 #include <vlc_plugin.h>
63 #include <vlc_access.h>
64 #include <vlc_input.h>
66 #include <vlc_charset.h>
67 #include <vlc_dialog.h>
68 #include <vlc_configuration.h>
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Open ( vlc_object_t * );
74 static void Close( vlc_object_t * );
76 #define HELP_TEXT N_("Support for VDR recordings (http://www.tvdr.de/).")
78 #define CHAPTER_OFFSET_TEXT N_("Chapter offset in ms")
79 #define CHAPTER_OFFSET_LONGTEXT N_( \
80 "Move all chapters. This value should be set in milliseconds." )
82 #define FPS_TEXT N_("Frame rate")
83 #define FPS_LONGTEXT N_( \
84 "Default frame rate for chapter import." )
87 set_category( CAT_INPUT )
88 set_shortname( N_("VDR") )
90 set_subcategory( SUBCAT_INPUT_ACCESS )
91 set_description( N_("VDR recordings") )
92 add_integer( "vdr-chapter-offset", 0,
93 CHAPTER_OFFSET_TEXT, CHAPTER_OFFSET_LONGTEXT, true )
94 add_float_with_range( "vdr-fps", 25, 1, 1000,
95 FPS_TEXT, FPS_LONGTEXT, true )
96 set_capability( "access", 60 )
98 add_shortcut( "directory" )
100 add_shortcut( "file" )
101 set_callbacks( Open, Close )
104 /*****************************************************************************
105 * Local prototypes, constants, structures
106 *****************************************************************************/
108 /* minimum chapter size in seconds */
109 #define MIN_CHAPTER_SIZE 5
111 TYPEDEF_ARRAY( uint64_t, size_array_t );
115 /* file sizes of all parts */
116 size_array_t file_sizes;
118 /* index and fd of current open file */
119 unsigned i_current_file;
126 input_title_t *p_marks;
129 /* file format: true=TS, false=PES */
133 #define CURRENT_FILE_SIZE ARRAY_VAL(p_sys->file_sizes, p_sys->i_current_file)
134 #define FILE_SIZE(pos) ARRAY_VAL(p_sys->file_sizes, pos)
135 #define FILE_COUNT (unsigned)p_sys->file_sizes.i_size
137 static int Control( access_t *, int, va_list );
138 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len );
139 static int Seek( access_t *p_access, uint64_t i_pos);
140 static void FindSeekpoint( access_t *p_access );
141 static bool ScanDirectory( access_t *p_access );
142 static char *GetFilePath( access_t *p_access, unsigned i_file );
143 static bool ImportNextFile( access_t *p_access );
144 static bool SwitchFile( access_t *p_access, unsigned i_file );
145 static void OptimizeForRead( int fd );
146 static void UpdateFileSize( access_t *p_access );
147 static FILE *OpenRelativeFile( access_t *p_access, const char *psz_file );
148 static bool ReadLine( char **ppsz_line, size_t *pi_size, FILE *p_file );
149 static void ImportMeta( access_t *p_access );
150 static void ImportMarks( access_t *p_access );
151 static bool ReadIndexRecord( FILE *p_file, bool b_ts, int64_t i_frame,
152 uint64_t *pi_offset, uint16_t *pi_file_num );
153 static int64_t ParseFrameNumber( const char *psz_line, float fps );
154 static const char *BaseName( const char *psz_path );
156 /*****************************************************************************
158 *****************************************************************************/
159 static int Open( vlc_object_t *p_this )
161 access_t *p_access = (access_t*)p_this;
163 if( !p_access->psz_filepath )
166 /* Some tests can be skipped if this module was explicitly requested.
167 * That way, the user can play "corrupt" recordings if necessary
168 * and we can avoid false positives in the general case. */
169 bool b_strict = strcmp( p_access->psz_access, "vdr" );
171 /* Do a quick test based on the directory name to see if this
172 * directory might contain a VDR recording. We can be reasonably
173 * sure if ScanDirectory() actually finds files. */
176 char psz_extension[4];
178 const char *psz_name = BaseName( p_access->psz_filepath );
179 if( sscanf( psz_name, "%*u-%*u-%*u.%*u.%*u.%*u%*[-.]%*u.%3s%n",
180 psz_extension, &i_length ) != 1 || strcasecmp( psz_extension, "rec" ) ||
181 ( psz_name[i_length] != DIR_SEP_CHAR && psz_name[i_length] != '\0' ) )
185 /* Only directories can be recordings */
187 if( vlc_stat( p_access->psz_filepath, &st ) ||
188 !S_ISDIR( st.st_mode ) )
192 STANDARD_READ_ACCESS_INIT;
194 p_sys->fps = var_InheritFloat( p_access, "vdr-fps" );
195 ARRAY_INIT( p_sys->file_sizes );
197 /* Import all files and prepare playback. */
198 if( !ScanDirectory( p_access ) ||
199 !SwitchFile( p_access, 0 ) )
205 free( p_access->psz_demux );
206 p_access->psz_demux = strdup( "ts" );
210 /*****************************************************************************
211 * Close files and free resources
212 *****************************************************************************/
213 static void Close( vlc_object_t * p_this )
215 access_t *p_access = (access_t*)p_this;
216 access_sys_t *p_sys = p_access->p_sys;
218 if( p_sys->fd != -1 )
220 ARRAY_RESET( p_sys->file_sizes );
223 vlc_meta_Delete( p_sys->p_meta );
225 vlc_input_title_Delete( p_sys->p_marks );
229 /*****************************************************************************
230 * Determine format and import files
231 *****************************************************************************/
232 static bool ScanDirectory( access_t *p_access )
234 access_sys_t *p_sys = p_access->p_sys;
236 /* find first part and determine directory format */
237 p_sys->b_ts_format = true;
238 if( !ImportNextFile( p_access ) )
240 p_sys->b_ts_format = !p_sys->b_ts_format;
241 if( !ImportNextFile( p_access ) )
245 /* get all remaining parts */
246 while( ImportNextFile( p_access ) )
249 /* import meta data etc. */
250 ImportMeta( p_access );
252 /* cut marks depend on meta data and file sizes */
253 ImportMarks( p_access );
258 /*****************************************************************************
259 * Control input stream
260 *****************************************************************************/
261 static int Control( access_t *p_access, int i_query, va_list args )
263 access_sys_t *p_sys = p_access->p_sys;
264 input_title_t ***ppp_title;
271 case ACCESS_CAN_SEEK:
272 case ACCESS_CAN_FASTSEEK:
273 case ACCESS_CAN_PAUSE:
274 case ACCESS_CAN_CONTROL_PACE:
275 *va_arg( args, bool* ) = true;
278 case ACCESS_GET_PTS_DELAY:
279 pi64 = va_arg( args, int64_t * );
280 *pi64 = INT64_C(1000)
281 * var_InheritInteger( p_access, "file-caching" );
284 case ACCESS_SET_PAUSE_STATE:
288 case ACCESS_GET_TITLE_INFO:
289 /* return a copy of our seek points */
290 if( !p_sys->p_marks )
292 ppp_title = va_arg( args, input_title_t*** );
293 *va_arg( args, int* ) = 1;
294 *ppp_title = malloc( sizeof( input_title_t** ) );
297 **ppp_title = vlc_input_title_Duplicate( p_sys->p_marks );
300 case ACCESS_SET_TITLE:
301 /* ignore - only one title */
304 case ACCESS_SET_SEEKPOINT:
305 i = va_arg( args, int );
306 /* Seek updates p_access->info */
307 return Seek( p_access, p_sys->p_marks->seekpoint[i]->i_byte_offset );
309 case ACCESS_GET_META:
312 p_meta = va_arg( args, vlc_meta_t* );
313 vlc_meta_Merge( p_meta, p_sys->p_meta );
316 case ACCESS_SET_PRIVATE_ID_STATE:
317 case ACCESS_GET_CONTENT_TYPE:
321 msg_Warn( p_access, "unimplemented query in control" );
327 /*****************************************************************************
328 * Read and concatenate files
329 *****************************************************************************/
330 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
332 access_sys_t *p_sys = p_access->p_sys;
334 if( p_sys->fd == -1 )
337 p_access->info.b_eof = true;
341 ssize_t i_ret = read( p_sys->fd, p_buffer, i_len );
346 p_access->info.i_pos += i_ret;
347 UpdateFileSize( p_access );
348 FindSeekpoint( p_access );
351 else if( i_ret == 0 )
353 /* check for new files in case the recording is still active */
354 if( p_sys->i_current_file >= FILE_COUNT - 1 )
355 ImportNextFile( p_access );
357 SwitchFile( p_access, p_sys->i_current_file + 1 );
360 else if( errno == EINTR )
362 /* try again later */
367 /* abort on read error */
368 msg_Err( p_access, "failed to read (%m)" );
369 dialog_Fatal( p_access, _("File reading failed"), "%s (%m)",
370 _("VLC could not read the file.") );
371 SwitchFile( p_access, -1 );
376 /*****************************************************************************
377 * Seek to a specific location in a file
378 *****************************************************************************/
379 static int Seek( access_t *p_access, uint64_t i_pos )
381 access_sys_t *p_sys = p_access->p_sys;
383 /* might happen if called by ACCESS_SET_SEEKPOINT */
384 i_pos = __MIN( i_pos, p_access->info.i_size );
386 p_access->info.i_pos = i_pos;
387 p_access->info.b_eof = false;
389 /* find correct chapter */
390 FindSeekpoint( p_access );
392 /* find correct file */
394 while( i_file < FILE_COUNT - 1 &&
395 i_pos >= FILE_SIZE( i_file ) )
397 i_pos -= FILE_SIZE( i_file );
400 if( !SwitchFile( p_access, i_file ) )
403 /* adjust position within that file */
404 return lseek( p_sys->fd, i_pos, SEEK_SET ) != -1 ?
405 VLC_SUCCESS : VLC_EGENERIC;
408 /*****************************************************************************
409 * Change the chapter index to match the current position
410 *****************************************************************************/
411 static void FindSeekpoint( access_t *p_access )
413 access_sys_t *p_sys = p_access->p_sys;
414 if( !p_sys->p_marks )
417 int i_new_seekpoint = p_access->info.i_seekpoint;
418 if( p_access->info.i_pos < (uint64_t)p_sys->p_marks->
419 seekpoint[ p_access->info.i_seekpoint ]->i_byte_offset )
421 /* i_pos moved backwards, start fresh */
425 /* only need to check the following seekpoints */
426 while( i_new_seekpoint + 1 < p_sys->p_marks->i_seekpoint &&
427 p_access->info.i_pos >= (uint64_t)p_sys->p_marks->
428 seekpoint[ i_new_seekpoint + 1 ]->i_byte_offset )
433 /* avoid unnecessary events */
434 if( p_access->info.i_seekpoint != i_new_seekpoint )
436 p_access->info.i_seekpoint = i_new_seekpoint;
437 p_access->info.i_update |= INPUT_UPDATE_SEEKPOINT;
441 /*****************************************************************************
442 * Returns the path of a certain part
443 *****************************************************************************/
444 static char *GetFilePath( access_t *p_access, unsigned i_file )
447 if( asprintf( &psz_path, p_access->p_sys->b_ts_format ?
448 "%s" DIR_SEP "%05u.ts" : "%s" DIR_SEP "%03u.vdr",
449 p_access->psz_filepath, i_file + 1 ) == -1 )
455 /*****************************************************************************
456 * Check if another part exists and import it
457 *****************************************************************************/
458 static bool ImportNextFile( access_t *p_access )
460 access_sys_t *p_sys = p_access->p_sys;
462 char *psz_path = GetFilePath( p_access, FILE_COUNT );
467 if( vlc_stat( psz_path, &st ) )
469 msg_Dbg( p_access, "could not stat %s: %m", psz_path );
473 if( !S_ISREG( st.st_mode ) )
475 msg_Dbg( p_access, "%s is not a regular file", psz_path );
479 msg_Dbg( p_access, "%s exists", psz_path );
482 ARRAY_APPEND( p_sys->file_sizes, st.st_size );
483 p_access->info.i_size += st.st_size;
488 /*****************************************************************************
489 * Close the current file and open another
490 *****************************************************************************/
491 static bool SwitchFile( access_t *p_access, unsigned i_file )
493 access_sys_t *p_sys = p_access->p_sys;
495 /* requested file already open? */
496 if( p_sys->fd != -1 && p_sys->i_current_file == i_file )
500 if( p_sys->fd != -1 )
507 if( i_file >= FILE_COUNT )
509 p_sys->i_current_file = i_file;
512 char *psz_path = GetFilePath( p_access, i_file );
515 p_sys->fd = vlc_open( psz_path, O_RDONLY );
517 if( p_sys->fd == -1 )
519 msg_Err( p_access, "Failed to open %s: %m", psz_path );
523 /* cannot handle anything except normal files */
525 if( fstat( p_sys->fd, &st ) || !S_ISREG( st.st_mode ) )
527 msg_Err( p_access, "%s is not a regular file", psz_path );
531 OptimizeForRead( p_sys->fd );
533 msg_Dbg( p_access, "opened %s", psz_path );
538 dialog_Fatal (p_access, _("File reading failed"), _("VLC could not"
539 " open the file \"%s\". (%m)"), psz_path);
540 if( p_sys->fd != -1 )
549 /*****************************************************************************
550 * Some tweaks to speed up read()
551 *****************************************************************************/
552 static void OptimizeForRead( int fd )
554 /* cf. Open() in file access module */
556 #ifdef HAVE_POSIX_FADVISE
557 posix_fadvise( fd, 0, 4096, POSIX_FADV_WILLNEED );
558 posix_fadvise( fd, 0, 0, POSIX_FADV_NOREUSE );
561 fcntl( fd, F_RDAHEAD, 1 );
564 fcntl( fd, F_NOCACHE, 0 );
568 /*****************************************************************************
569 * Fix size if the (last) part is still growing
570 *****************************************************************************/
571 static void UpdateFileSize( access_t *p_access )
573 access_sys_t *p_sys = p_access->p_sys;
576 if( p_access->info.i_size >= p_access->info.i_pos )
579 /* TODO: not sure if this can happen or what to do in this case */
580 if( fstat( p_sys->fd, &st ) )
582 if( (uint64_t)st.st_size <= CURRENT_FILE_SIZE )
585 p_access->info.i_size -= CURRENT_FILE_SIZE;
586 CURRENT_FILE_SIZE = st.st_size;
587 p_access->info.i_size += CURRENT_FILE_SIZE;
590 /*****************************************************************************
591 * Open file relative to base directory for reading.
592 *****************************************************************************/
593 static FILE *OpenRelativeFile( access_t *p_access, const char *psz_file )
595 /* build path and add extension */
597 if( asprintf( &psz_path, "%s" DIR_SEP "%s%s",
598 p_access->psz_filepath, psz_file,
599 p_access->p_sys->b_ts_format ? "" : ".vdr" ) == -1 )
602 FILE *file = vlc_fopen( psz_path, "rb" );
604 msg_Warn( p_access, "Failed to open %s: %m", psz_path );
610 /*****************************************************************************
611 * Read a line of text. Returns false on error or EOF.
612 *****************************************************************************/
613 static bool ReadLine( char **ppsz_line, size_t *pi_size, FILE *p_file )
615 ssize_t read = getline( ppsz_line, pi_size, p_file );
619 /* automatically free buffer on eof */
625 if( read > 0 && (*ppsz_line)[ read - 1 ] == '\n' )
626 (*ppsz_line)[ read - 1 ] = '\0';
627 EnsureUTF8( *ppsz_line );
632 /*****************************************************************************
634 *****************************************************************************/
635 static void ImportMeta( access_t *p_access )
637 access_sys_t *p_sys = p_access->p_sys;
639 FILE *infofile = OpenRelativeFile( p_access, "info" );
643 vlc_meta_t *p_meta = vlc_meta_New();
644 p_sys->p_meta = p_meta;
653 char *psz_title = NULL, *psz_smalltext = NULL, *psz_date = NULL;
655 while( ReadLine( &line, &line_len, infofile ) )
657 if( !isalpha( (unsigned char)line[0] ) || line[1] != ' ' )
661 char *text = line + 2;
665 char *psz_name = strchr( text, ' ' );
669 vlc_meta_AddExtra( p_meta, "Channel", psz_name + 1 );
671 vlc_meta_AddExtra( p_meta, "Transponder", text );
674 else if( tag == 'E' )
676 unsigned i_id, i_start, i_length;
677 if( sscanf( text, "%u %u %u", &i_id, &i_start, &i_length ) == 3 )
681 time_t start = i_start;
682 localtime_r( &start, &tm );
685 strftime( str, sizeof(str), "%Y-%m-%d %H:%M", &tm );
686 vlc_meta_AddExtra( p_meta, "Date", str );
688 psz_date = strdup( str );
690 /* display in minutes */
691 i_length = ( i_length + 59 ) / 60;
692 snprintf( str, sizeof(str), "%u:%02u", i_length / 60, i_length % 60 );
693 vlc_meta_AddExtra( p_meta, "Duration", str );
697 else if( tag == 'T' )
700 psz_title = strdup( text );
701 vlc_meta_AddExtra( p_meta, "Title", text );
704 else if( tag == 'S' )
706 free( psz_smalltext );
707 psz_smalltext = strdup( text );
708 vlc_meta_AddExtra( p_meta, "Info", text );
711 else if( tag == 'D' )
713 for( char *p = text; *p; ++p )
718 vlc_meta_SetDescription( p_meta, text );
721 /* FPS are required to convert between timestamps and frames */
722 else if( tag == 'F' )
724 float fps = atof( text );
727 vlc_meta_AddExtra( p_meta, "Frame Rate", text );
730 else if( tag == 'P' )
732 vlc_meta_AddExtra( p_meta, "Priority", text );
735 else if( tag == 'L' )
737 vlc_meta_AddExtra( p_meta, "Lifetime", text );
741 /* create a meaningful title */
743 ( psz_title ? strlen( psz_title ) : 0 ) +
744 ( psz_smalltext ? strlen( psz_smalltext ) : 0 ) +
745 ( psz_date ? strlen( psz_date ) : 0 );
746 char *psz_display = malloc( i_len );
752 strcat( psz_display, psz_title );
753 if( psz_title && psz_smalltext )
754 strcat( psz_display, " - " );
756 strcat( psz_display, psz_smalltext );
757 if( ( psz_title || psz_smalltext ) && psz_date )
759 strcat( psz_display, " (" );
760 strcat( psz_display, psz_date );
761 strcat( psz_display, ")" );
764 vlc_meta_SetTitle( p_meta, psz_display );
769 free( psz_smalltext );
775 /*****************************************************************************
776 * Import cut marks and convert them to seekpoints (chapters).
777 *****************************************************************************/
778 static void ImportMarks( access_t *p_access )
780 access_sys_t *p_sys = p_access->p_sys;
782 FILE *marksfile = OpenRelativeFile( p_access, "marks" );
786 FILE *indexfile = OpenRelativeFile( p_access, "index" );
793 /* get the length of this recording (index stores 8 bytes per frame) */
795 if( fstat( fileno( indexfile ), &st ) )
801 int64_t i_frame_count = st.st_size / 8;
803 /* Put all cut marks in a "dummy" title */
804 input_title_t *p_marks = vlc_input_title_New();
811 p_marks->psz_name = strdup( _("VDR Cut Marks") );
812 p_marks->i_length = i_frame_count * (int64_t)( CLOCK_FREQ / p_sys->fps );
813 p_marks->i_size = p_access->info.i_size;
815 /* offset for chapter positions */
816 int i_chapter_offset = p_sys->fps / 1000 *
817 var_InheritInteger( p_access, "vdr-chapter-offset" );
819 /* minimum chapter size in frames */
820 int i_min_chapter_size = p_sys->fps * MIN_CHAPTER_SIZE;
822 /* the last chapter started at this frame (init to 0 so
823 * we skip useless chapters near the beginning as well) */
824 int64_t i_prev_chapter = 0;
826 /* parse lines of the form "0:00:00.00 foobar" */
829 while( ReadLine( &line, &line_len, marksfile ) )
831 int64_t i_frame = ParseFrameNumber( line, p_sys->fps );
833 /* skip chapters which are near the end or too close to each other */
834 if( i_frame - i_prev_chapter < i_min_chapter_size ||
835 i_frame >= i_frame_count - i_min_chapter_size )
837 i_prev_chapter = i_frame;
839 /* move chapters (simple workaround for inaccurate cut marks) */
840 if( i_frame > -i_chapter_offset )
841 i_frame += i_chapter_offset;
846 uint16_t i_file_number;
847 if( !ReadIndexRecord( indexfile, p_sys->b_ts_format,
848 i_frame, &i_offset, &i_file_number ) )
850 if( i_file_number < 1 || i_file_number > FILE_COUNT )
853 /* add file sizes to get the "global" offset */
854 seekpoint_t *sp = vlc_seekpoint_New();
857 sp->i_time_offset = i_frame * (int64_t)( CLOCK_FREQ / p_sys->fps );
858 sp->i_byte_offset = i_offset;
859 for( int i = 0; i + 1 < i_file_number; ++i )
860 sp->i_byte_offset += FILE_SIZE( i );
861 sp->psz_name = strdup( line );
863 TAB_APPEND( p_marks->i_seekpoint, p_marks->seekpoint, sp );
866 /* add a chapter at the beginning if missing */
867 if( p_marks->i_seekpoint > 0 && p_marks->seekpoint[0]->i_byte_offset > 0 )
869 seekpoint_t *sp = vlc_seekpoint_New();
872 sp->i_byte_offset = 0;
873 sp->i_time_offset = 0;
874 sp->psz_name = strdup( _("Start") );
875 TAB_INSERT( p_marks->i_seekpoint, p_marks->seekpoint, sp, 0 );
879 if( p_marks->i_seekpoint > 0 )
880 p_sys->p_marks = p_marks;
882 vlc_input_title_Delete( p_marks );
888 /*****************************************************************************
889 * Lookup frame offset in index file
890 *****************************************************************************/
891 static bool ReadIndexRecord( FILE *p_file, bool b_ts, int64_t i_frame,
892 uint64_t *pi_offset, uint16_t *pi_file_num )
894 uint8_t index_record[8];
895 if( fseek( p_file, sizeof(index_record) * i_frame, SEEK_SET ) != 0 )
897 if( fread( &index_record, sizeof(index_record), 1, p_file ) <= 0 )
900 /* VDR usually (only?) runs on little endian machines, but VLC has a
901 * broader audience. See recording.* in VDR source for data layout. */
904 uint64_t i_index_entry = GetQWLE( &index_record );
905 *pi_offset = i_index_entry & UINT64_C(0xFFFFFFFFFF);
906 *pi_file_num = i_index_entry >> 48;
910 *pi_offset = GetDWLE( &index_record );
911 *pi_file_num = index_record[5];
917 /*****************************************************************************
918 * Convert time stamp from file to frame number
919 *****************************************************************************/
920 static int64_t ParseFrameNumber( const char *psz_line, float fps )
922 unsigned h, m, s, f, n;
924 /* hour:min:sec.frame (frame is optional) */
925 n = sscanf( psz_line, "%u:%u:%u.%u", &h, &m, &s, &f );
930 int64_t i_seconds = (int64_t)h * 3600 + (int64_t)m * 60 + s;
931 return (int64_t)( i_seconds * (double)fps ) + __MAX(1, f) - 1;
934 /* only a frame number */
935 int64_t i_frame = strtoll( psz_line, NULL, 10 );
936 return __MAX(1, i_frame) - 1;
939 /*****************************************************************************
940 * Return the last path component (including trailing separators)
941 *****************************************************************************/
942 static const char *BaseName( const char *psz_path )
944 const char *psz_name = psz_path + strlen( psz_path );
946 /* skip superfluous separators at the end */
947 while( psz_name > psz_path && psz_name[-1] == DIR_SEP_CHAR )
950 /* skip last component */
951 while( psz_name > psz_path && psz_name[-1] != DIR_SEP_CHAR )