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
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 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 General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, 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 ) && !defined( UNDER_CE )
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 ) )
208 /*****************************************************************************
209 * Close files and free resources
210 *****************************************************************************/
211 static void Close( vlc_object_t * p_this )
213 access_t *p_access = (access_t*)p_this;
214 access_sys_t *p_sys = p_access->p_sys;
216 if( p_sys->fd != -1 )
218 ARRAY_RESET( p_sys->file_sizes );
221 vlc_meta_Delete( p_sys->p_meta );
223 vlc_input_title_Delete( p_sys->p_marks );
227 /*****************************************************************************
228 * Determine format and import files
229 *****************************************************************************/
230 static bool ScanDirectory( access_t *p_access )
232 access_sys_t *p_sys = p_access->p_sys;
234 /* find first part and determine directory format */
235 p_sys->b_ts_format = true;
236 if( !ImportNextFile( p_access ) )
238 p_sys->b_ts_format = !p_sys->b_ts_format;
239 if( !ImportNextFile( p_access ) )
243 /* get all remaining parts */
244 while( ImportNextFile( p_access ) )
247 /* import meta data etc. */
248 ImportMeta( p_access );
250 /* cut marks depend on meta data and file sizes */
251 ImportMarks( p_access );
256 /*****************************************************************************
257 * Control input stream
258 *****************************************************************************/
259 static int Control( access_t *p_access, int i_query, va_list args )
261 access_sys_t *p_sys = p_access->p_sys;
262 input_title_t ***ppp_title;
269 case ACCESS_CAN_SEEK:
270 case ACCESS_CAN_FASTSEEK:
271 case ACCESS_CAN_PAUSE:
272 case ACCESS_CAN_CONTROL_PACE:
273 *va_arg( args, bool* ) = true;
276 case ACCESS_GET_PTS_DELAY:
277 pi64 = va_arg( args, int64_t * );
278 *pi64 = INT64_C(1000)
279 * var_InheritInteger( p_access, "file-caching" );
282 case ACCESS_SET_PAUSE_STATE:
286 case ACCESS_GET_TITLE_INFO:
287 /* return a copy of our seek points */
288 if( !p_sys->p_marks )
290 ppp_title = va_arg( args, input_title_t*** );
291 *va_arg( args, int* ) = 1;
292 *ppp_title = malloc( sizeof( input_title_t** ) );
295 **ppp_title = vlc_input_title_Duplicate( p_sys->p_marks );
298 case ACCESS_SET_TITLE:
299 /* ignore - only one title */
302 case ACCESS_SET_SEEKPOINT:
303 i = va_arg( args, int );
304 /* Seek updates p_access->info */
305 return Seek( p_access, p_sys->p_marks->seekpoint[i]->i_byte_offset );
307 case ACCESS_GET_META:
310 p_meta = va_arg( args, vlc_meta_t* );
311 vlc_meta_Merge( p_meta, p_sys->p_meta );
314 case ACCESS_SET_PRIVATE_ID_STATE:
315 case ACCESS_GET_CONTENT_TYPE:
319 msg_Warn( p_access, "unimplemented query in control" );
325 /*****************************************************************************
326 * Read and concatenate files
327 *****************************************************************************/
328 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
330 access_sys_t *p_sys = p_access->p_sys;
332 if( p_sys->fd == -1 )
335 p_access->info.b_eof = true;
339 ssize_t i_ret = read( p_sys->fd, p_buffer, i_len );
344 p_access->info.i_pos += i_ret;
345 UpdateFileSize( p_access );
346 FindSeekpoint( p_access );
349 else if( i_ret == 0 )
351 /* check for new files in case the recording is still active */
352 if( p_sys->i_current_file >= FILE_COUNT - 1 )
353 ImportNextFile( p_access );
355 SwitchFile( p_access, p_sys->i_current_file + 1 );
358 else if( errno == EINTR )
360 /* try again later */
365 /* abort on read error */
366 msg_Err( p_access, "failed to read (%m)" );
367 dialog_Fatal( p_access, _("File reading failed"), "%s (%m)",
368 _("VLC could not read the file.") );
369 SwitchFile( p_access, -1 );
374 /*****************************************************************************
375 * Seek to a specific location in a file
376 *****************************************************************************/
377 static int Seek( access_t *p_access, uint64_t i_pos )
379 access_sys_t *p_sys = p_access->p_sys;
381 /* might happen if called by ACCESS_SET_SEEKPOINT */
382 i_pos = __MIN( i_pos, p_access->info.i_size );
384 p_access->info.i_pos = i_pos;
385 p_access->info.b_eof = false;
387 /* find correct chapter */
388 FindSeekpoint( p_access );
390 /* find correct file */
392 while( i_file < FILE_COUNT - 1 &&
393 i_pos >= FILE_SIZE( i_file ) )
395 i_pos -= FILE_SIZE( i_file );
398 if( !SwitchFile( p_access, i_file ) )
401 /* adjust position within that file */
402 return lseek( p_sys->fd, i_pos, SEEK_SET ) != -1 ?
403 VLC_SUCCESS : VLC_EGENERIC;
406 /*****************************************************************************
407 * Change the chapter index to match the current position
408 *****************************************************************************/
409 static void FindSeekpoint( access_t *p_access )
411 access_sys_t *p_sys = p_access->p_sys;
412 if( !p_sys->p_marks )
415 int i_new_seekpoint = p_access->info.i_seekpoint;
416 if( p_access->info.i_pos < (uint64_t)p_sys->p_marks->
417 seekpoint[ p_access->info.i_seekpoint ]->i_byte_offset )
419 /* i_pos moved backwards, start fresh */
423 /* only need to check the following seekpoints */
424 while( i_new_seekpoint + 1 < p_sys->p_marks->i_seekpoint &&
425 p_access->info.i_pos >= (uint64_t)p_sys->p_marks->
426 seekpoint[ i_new_seekpoint + 1 ]->i_byte_offset )
431 /* avoid unnecessary events */
432 if( p_access->info.i_seekpoint != i_new_seekpoint )
434 p_access->info.i_seekpoint = i_new_seekpoint;
435 p_access->info.i_update |= INPUT_UPDATE_SEEKPOINT;
439 /*****************************************************************************
440 * Returns the path of a certain part
441 *****************************************************************************/
442 static char *GetFilePath( access_t *p_access, unsigned i_file )
445 if( asprintf( &psz_path, p_access->p_sys->b_ts_format ?
446 "%s" DIR_SEP "%05u.ts" : "%s" DIR_SEP "%03u.vdr",
447 p_access->psz_filepath, i_file + 1 ) == -1 )
453 /*****************************************************************************
454 * Check if another part exists and import it
455 *****************************************************************************/
456 static bool ImportNextFile( access_t *p_access )
458 access_sys_t *p_sys = p_access->p_sys;
460 char *psz_path = GetFilePath( p_access, FILE_COUNT );
465 if( vlc_stat( psz_path, &st ) )
467 msg_Dbg( p_access, "could not stat %s: %m", psz_path );
471 if( !S_ISREG( st.st_mode ) )
473 msg_Dbg( p_access, "%s is not a regular file", psz_path );
477 msg_Dbg( p_access, "%s exists", psz_path );
480 ARRAY_APPEND( p_sys->file_sizes, st.st_size );
481 p_access->info.i_size += st.st_size;
482 p_access->info.i_update |= INPUT_UPDATE_SIZE;
487 /*****************************************************************************
488 * Close the current file and open another
489 *****************************************************************************/
490 static bool SwitchFile( access_t *p_access, unsigned i_file )
492 access_sys_t *p_sys = p_access->p_sys;
494 /* requested file already open? */
495 if( p_sys->fd != -1 && p_sys->i_current_file == i_file )
499 if( p_sys->fd != -1 )
506 if( i_file >= FILE_COUNT )
508 p_sys->i_current_file = i_file;
511 char *psz_path = GetFilePath( p_access, i_file );
514 p_sys->fd = vlc_open( psz_path, O_RDONLY );
516 if( p_sys->fd == -1 )
518 msg_Err( p_access, "Failed to open %s: %m", psz_path );
522 /* cannot handle anything except normal files */
524 if( fstat( p_sys->fd, &st ) || !S_ISREG( st.st_mode ) )
526 msg_Err( p_access, "%s is not a regular file", psz_path );
530 OptimizeForRead( p_sys->fd );
532 msg_Dbg( p_access, "opened %s", psz_path );
537 dialog_Fatal (p_access, _("File reading failed"), _("VLC could not"
538 " open the file \"%s\". (%m)"), psz_path);
539 if( p_sys->fd != -1 )
548 /*****************************************************************************
549 * Some tweaks to speed up read()
550 *****************************************************************************/
551 static void OptimizeForRead( int fd )
553 /* cf. Open() in file access module */
555 #ifdef HAVE_POSIX_FADVISE
556 posix_fadvise( fd, 0, 4096, POSIX_FADV_WILLNEED );
557 posix_fadvise( fd, 0, 0, POSIX_FADV_NOREUSE );
561 fcntl( fd, F_RDAHEAD, 1 );
564 fcntl( fd, F_NOCACHE, 1 );
569 /*****************************************************************************
570 * Fix size if the (last) part is still growing
571 *****************************************************************************/
572 static void UpdateFileSize( access_t *p_access )
574 access_sys_t *p_sys = p_access->p_sys;
577 if( p_access->info.i_size >= p_access->info.i_pos )
580 /* TODO: not sure if this can happen or what to do in this case */
581 if( fstat( p_sys->fd, &st ) )
583 if( (uint64_t)st.st_size <= CURRENT_FILE_SIZE )
586 p_access->info.i_size -= CURRENT_FILE_SIZE;
587 CURRENT_FILE_SIZE = st.st_size;
588 p_access->info.i_size += CURRENT_FILE_SIZE;
589 p_access->info.i_update |= INPUT_UPDATE_SIZE;
592 /*****************************************************************************
593 * Open file relative to base directory for reading.
594 *****************************************************************************/
595 static FILE *OpenRelativeFile( access_t *p_access, const char *psz_file )
597 /* build path and add extension */
599 if( asprintf( &psz_path, "%s" DIR_SEP "%s%s",
600 p_access->psz_filepath, psz_file,
601 p_access->p_sys->b_ts_format ? "" : ".vdr" ) == -1 )
604 FILE *file = vlc_fopen( psz_path, "rb" );
606 msg_Warn( p_access, "Failed to open %s: %m", psz_path );
612 /*****************************************************************************
613 * Read a line of text. Returns false on error or EOF.
614 *****************************************************************************/
615 static bool ReadLine( char **ppsz_line, size_t *pi_size, FILE *p_file )
617 ssize_t read = getline( ppsz_line, pi_size, p_file );
621 /* automatically free buffer on eof */
627 if( read > 0 && (*ppsz_line)[ read - 1 ] == '\n' )
628 (*ppsz_line)[ read - 1 ] = '\0';
629 EnsureUTF8( *ppsz_line );
634 /*****************************************************************************
636 *****************************************************************************/
637 static void ImportMeta( access_t *p_access )
639 access_sys_t *p_sys = p_access->p_sys;
641 FILE *infofile = OpenRelativeFile( p_access, "info" );
645 vlc_meta_t *p_meta = vlc_meta_New();
646 p_sys->p_meta = p_meta;
655 char *psz_title = NULL, *psz_smalltext = NULL, *psz_date = NULL;
657 while( ReadLine( &line, &line_len, infofile ) )
659 if( !isalpha( (unsigned char)line[0] ) || line[1] != ' ' )
663 char *text = line + 2;
667 char *psz_name = strchr( text, ' ' );
671 vlc_meta_AddExtra( p_meta, "Channel", psz_name + 1 );
673 vlc_meta_AddExtra( p_meta, "Transponder", text );
676 else if( tag == 'E' )
678 unsigned i_id, i_start, i_length;
679 if( sscanf( text, "%u %u %u", &i_id, &i_start, &i_length ) == 3 )
683 time_t start = i_start;
684 localtime_r( &start, &tm );
687 strftime( str, sizeof(str), "%Y-%m-%d %H:%M", &tm );
688 vlc_meta_AddExtra( p_meta, "Date", str );
690 psz_date = strdup( str );
692 /* display in minutes */
693 i_length = ( i_length + 59 ) / 60;
694 snprintf( str, sizeof(str), "%u:%02u", i_length / 60, i_length % 60 );
695 vlc_meta_AddExtra( p_meta, "Duration", str );
699 else if( tag == 'T' )
702 psz_title = strdup( text );
703 vlc_meta_AddExtra( p_meta, "Title", text );
706 else if( tag == 'S' )
708 free( psz_smalltext );
709 psz_smalltext = strdup( text );
710 vlc_meta_AddExtra( p_meta, "Info", text );
713 else if( tag == 'D' )
715 for( char *p = text; *p; ++p )
720 vlc_meta_SetDescription( p_meta, text );
723 /* FPS are required to convert between timestamps and frames */
724 else if( tag == 'F' )
726 float fps = atof( text );
729 vlc_meta_AddExtra( p_meta, "Frame Rate", text );
732 else if( tag == 'P' )
734 vlc_meta_AddExtra( p_meta, "Priority", text );
737 else if( tag == 'L' )
739 vlc_meta_AddExtra( p_meta, "Lifetime", text );
743 /* create a meaningful title */
745 ( psz_title ? strlen( psz_title ) : 0 ) +
746 ( psz_smalltext ? strlen( psz_smalltext ) : 0 ) +
747 ( psz_date ? strlen( psz_date ) : 0 );
748 char *psz_display = malloc( i_len );
754 strcat( psz_display, psz_title );
755 if( psz_title && psz_smalltext )
756 strcat( psz_display, " - " );
758 strcat( psz_display, psz_smalltext );
759 if( ( psz_title || psz_smalltext ) && psz_date )
761 strcat( psz_display, " (" );
762 strcat( psz_display, psz_date );
763 strcat( psz_display, ")" );
766 vlc_meta_SetTitle( p_meta, psz_display );
771 free( psz_smalltext );
777 /*****************************************************************************
778 * Import cut marks and convert them to seekpoints (chapters).
779 *****************************************************************************/
780 static void ImportMarks( access_t *p_access )
782 access_sys_t *p_sys = p_access->p_sys;
784 FILE *marksfile = OpenRelativeFile( p_access, "marks" );
788 FILE *indexfile = OpenRelativeFile( p_access, "index" );
795 /* get the length of this recording (index stores 8 bytes per frame) */
797 if( fstat( fileno( indexfile ), &st ) )
803 int64_t i_frame_count = st.st_size / 8;
805 /* Put all cut marks in a "dummy" title */
806 input_title_t *p_marks = vlc_input_title_New();
813 p_marks->psz_name = strdup( _("VDR Cut Marks") );
814 p_marks->i_length = i_frame_count * (int64_t)( CLOCK_FREQ / p_sys->fps );
815 p_marks->i_size = p_access->info.i_size;
817 /* offset for chapter positions */
818 int i_chapter_offset = p_sys->fps / 1000 *
819 var_InheritInteger( p_access, "vdr-chapter-offset" );
821 /* minimum chapter size in frames */
822 int i_min_chapter_size = p_sys->fps * MIN_CHAPTER_SIZE;
824 /* the last chapter started at this frame (init to 0 so
825 * we skip useless chapters near the beginning as well) */
826 int64_t i_prev_chapter = 0;
828 /* parse lines of the form "0:00:00.00 foobar" */
831 while( ReadLine( &line, &line_len, marksfile ) )
833 int64_t i_frame = ParseFrameNumber( line, p_sys->fps );
835 /* skip chapters which are near the end or too close to each other */
836 if( i_frame - i_prev_chapter < i_min_chapter_size ||
837 i_frame >= i_frame_count - i_min_chapter_size )
839 i_prev_chapter = i_frame;
841 /* move chapters (simple workaround for inaccurate cut marks) */
842 if( i_frame > -i_chapter_offset )
843 i_frame += i_chapter_offset;
848 uint16_t i_file_number;
849 if( !ReadIndexRecord( indexfile, p_sys->b_ts_format,
850 i_frame, &i_offset, &i_file_number ) )
852 if( i_file_number < 1 || i_file_number > FILE_COUNT )
855 /* add file sizes to get the "global" offset */
856 seekpoint_t *sp = vlc_seekpoint_New();
859 sp->i_time_offset = i_frame * (int64_t)( CLOCK_FREQ / p_sys->fps );
860 sp->i_byte_offset = i_offset;
861 for( int i = 0; i + 1 < i_file_number; ++i )
862 sp->i_byte_offset += FILE_SIZE( i );
863 sp->psz_name = strdup( line );
865 TAB_APPEND( p_marks->i_seekpoint, p_marks->seekpoint, sp );
868 /* add a chapter at the beginning if missing */
869 if( p_marks->i_seekpoint > 0 && p_marks->seekpoint[0]->i_byte_offset > 0 )
871 seekpoint_t *sp = vlc_seekpoint_New();
874 sp->i_byte_offset = 0;
875 sp->i_time_offset = 0;
876 sp->psz_name = strdup( _("Start") );
877 TAB_INSERT( p_marks->i_seekpoint, p_marks->seekpoint, sp, 0 );
881 if( p_marks->i_seekpoint > 0 )
882 p_sys->p_marks = p_marks;
884 vlc_input_title_Delete( p_marks );
890 /*****************************************************************************
891 * Lookup frame offset in index file
892 *****************************************************************************/
893 static bool ReadIndexRecord( FILE *p_file, bool b_ts, int64_t i_frame,
894 uint64_t *pi_offset, uint16_t *pi_file_num )
896 uint8_t index_record[8];
897 if( fseek( p_file, sizeof(index_record) * i_frame, SEEK_SET ) != 0 )
899 if( fread( &index_record, sizeof(index_record), 1, p_file ) <= 0 )
902 /* VDR usually (only?) runs on little endian machines, but VLC has a
903 * broader audience. See recording.* in VDR source for data layout. */
906 uint64_t i_index_entry = GetQWLE( &index_record );
907 *pi_offset = i_index_entry & UINT64_C(0xFFFFFFFFFF);
908 *pi_file_num = i_index_entry >> 48;
912 *pi_offset = GetDWLE( &index_record );
913 *pi_file_num = index_record[5];
919 /*****************************************************************************
920 * Convert time stamp from file to frame number
921 *****************************************************************************/
922 static int64_t ParseFrameNumber( const char *psz_line, float fps )
924 unsigned h, m, s, f, n;
926 /* hour:min:sec.frame (frame is optional) */
927 n = sscanf( psz_line, "%u:%u:%u.%u", &h, &m, &s, &f );
932 int64_t i_seconds = (int64_t)h * 3600 + (int64_t)m * 60 + s;
933 return (int64_t)( i_seconds * (double)fps ) + __MAX(1, f) - 1;
936 /* only a frame number */
937 int64_t i_frame = strtoll( psz_line, NULL, 10 );
938 return __MAX(1, i_frame) - 1;
941 /*****************************************************************************
942 * Return the last path component (including trailing separators)
943 *****************************************************************************/
944 static const char *BaseName( const char *psz_path )
946 const char *psz_name = psz_path + strlen( psz_path );
948 /* skip superfluous separators at the end */
949 while( psz_name > psz_path && psz_name[-1] == DIR_SEP_CHAR )
952 /* skip last component */
953 while( psz_name > psz_path && psz_name[-1] != DIR_SEP_CHAR )