[FFmpeg-devel] Image sequence file names
Michael Niedermayer
michaelni at gmx.at
Sat Sep 3 23:31:08 CEST 2011
Hi robert
On Wed, Aug 31, 2011 at 10:43:17PM +0200, Robert Petka wrote:
> Dňa 31. 8. 2011 0:59, Michael Niedermayer wrote / napísal(a):
>> On Wed, Aug 31, 2011 at 12:08:56AM +0200, Robert Petka wrote:
>> when you do, please write the implementation so as to avoid known
>> bugs in dirname.
>>
>> the manpage says (dunno if you have the manpages on msys)
>> BUGS
>> In the glibc implementation of the POSIX versions of these functions they modify their argument, and segfault when called with a static string like "/usr/". Before glibc 2.2.1, the glibc version
>> of dirname() did not correctly handle pathnames with trailing '/' characters, and generated a segfault if given a NULL argument.
>>
>>
>> [...]
>>
>>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> Here's the modified patch file with dirname usage.
>
> Robert
> img2.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 61 insertions(+), 10 deletions(-)
> 3d2e9a948755cdeb1b940f8f86381bb5982ee492 image_range.diff
> diff --git a/libavformat/img2.c b/libavformat/img2.c
> index 77145cb..2b2c37c 100644
> --- a/libavformat/img2.c
> +++ b/libavformat/img2.c
> @@ -30,6 +30,10 @@
> #include "avio_internal.h"
> #include "internal.h"
> #include <strings.h>
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <dirent.h>
> +#include <libgen.h>
>
> typedef struct {
> const AVClass *class; /**< Class for private options. */
> @@ -133,27 +137,74 @@ static enum CodecID av_str2id(const IdStrMap *tags, const char *str)
> return CODEC_ID_NONE;
> }
>
> +static int get_index_for_file(const char* path)
> +{
> + int i, last_digit, first_digit, index;
> +
> + first_digit = -1;
> + last_digit = -1;
> +
> + for (i=strlen(path)-1;i>=0;i--) {
> + if (last_digit == -1) {
> + if (isdigit(path[i]))
> + last_digit = i;
> + } else {
> + if (isdigit(path[i])) {
> + first_digit = i;
> + } else
> + break;
> + }
> + }
> +
> + index = -1;
> + if (first_digit != -1) {
> + sscanf(path + first_digit,"%d",&index);
> + }
> +
> + return index;
> +}
> +
> /* return -1 if no image found */
> static int find_image_range(int *pfirst_index, int *plast_index,
> const char *path)
> {
> char buf[1024];
> int range, last_index, range1, first_index;
> + DIR *dp = 0;
> + struct dirent *ep = 0;
> + char dirPath[MAX_PATH], pathCopy[MAX_PATH];
> + char *directory = 0;
>
> /* find the first image */
> - for(first_index = 0; first_index < 5; first_index++) {
> - if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
> - *pfirst_index =
> - *plast_index = 1;
> - if (avio_check(buf, AVIO_FLAG_READ) > 0)
> - return 0;
> - return -1;
> + first_index = -1;
> +
> + /* get files directory */
> + av_strlcpy(pathCopy, path, FFMIN(sizeof(pathCopy),strlen(path) + 1));
> + directory = dirname(pathCopy);
> + av_strlcpy(dirPath, directory, FFMIN(sizeof(dirPath),strlen(directory) + 1));
the FFMIN and strlen seem unneeded
> +
> + dp = opendir (dirPath);
this code should only be run when the underlaying protocol is file,
it should for example not be used with http://
> + if (dp) {
> + int min_index;
> + min_index = INT_MAX;
could be merged
> +
> + while (ep = readdir (dp)) {
> + int file_index;
> + file_index = get_index_for_file(ep->d_name);
> +
> + if (file_index != -1) {
> + min_index = FFMIN(min_index, file_index);
> + }
if the "fail" value is INT_MAX instead of -1 then the if() is unneeded
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110903/8c77faf8/attachment.asc>
More information about the ffmpeg-devel
mailing list