You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
Implement cmdutils.c:read_file(), and use it in ffmpeg.c for reading
the second pass encoding log file. Originally committed as revision 22769 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
24
cmdutils.c
24
cmdutils.c
@@ -639,3 +639,27 @@ int read_yesno(void)
|
|||||||
|
|
||||||
return yesno;
|
return yesno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int read_file(const char *filename, char **bufptr, size_t *size)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(filename, "r");
|
||||||
|
|
||||||
|
if (!f) {
|
||||||
|
fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno));
|
||||||
|
return AVERROR(errno);
|
||||||
|
}
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
*size = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
*bufptr = av_malloc(*size + 1);
|
||||||
|
if (!*bufptr) {
|
||||||
|
fprintf(stderr, "Could not allocate file buffer\n");
|
||||||
|
fclose(f);
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
fread(*bufptr, 1, *size, f);
|
||||||
|
(*bufptr)[*size++] = '\0';
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
11
cmdutils.h
11
cmdutils.h
@@ -200,4 +200,15 @@ void show_pix_fmts(void);
|
|||||||
*/
|
*/
|
||||||
int read_yesno(void);
|
int read_yesno(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the file with name filename, and puts its content in a newly
|
||||||
|
* allocated 0-terminated buffer.
|
||||||
|
*
|
||||||
|
* @param bufptr puts here the pointer to the newly allocated buffer
|
||||||
|
* @param size puts here the size of the newly allocated buffer
|
||||||
|
* @return 0 in case of success, a negative value corresponding to an
|
||||||
|
* AVERROR error code in case of failure.
|
||||||
|
*/
|
||||||
|
int read_file(const char *filename, char **bufptr, size_t *size);
|
||||||
|
|
||||||
#endif /* FFMPEG_CMDUTILS_H */
|
#endif /* FFMPEG_CMDUTILS_H */
|
||||||
|
21
ffmpeg.c
21
ffmpeg.c
@@ -2072,8 +2072,6 @@ static int av_encode(AVFormatContext **output_files,
|
|||||||
(codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
|
(codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
|
||||||
char logfilename[1024];
|
char logfilename[1024];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int size;
|
|
||||||
char *logbuffer;
|
|
||||||
|
|
||||||
snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
|
snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
|
||||||
pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,
|
pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,
|
||||||
@@ -2086,23 +2084,12 @@ static int av_encode(AVFormatContext **output_files,
|
|||||||
}
|
}
|
||||||
ost->logfile = f;
|
ost->logfile = f;
|
||||||
} else {
|
} else {
|
||||||
/* read the log file */
|
char *logbuffer;
|
||||||
f = fopen(logfilename, "r");
|
size_t logbuffer_size;
|
||||||
if (!f) {
|
if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
|
||||||
fprintf(stderr, "Cannot read log file '%s' for pass-2 encoding: %s\n", logfilename, strerror(errno));
|
fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename);
|
||||||
av_exit(1);
|
av_exit(1);
|
||||||
}
|
}
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
size = ftell(f);
|
|
||||||
fseek(f, 0, SEEK_SET);
|
|
||||||
logbuffer = av_malloc(size + 1);
|
|
||||||
if (!logbuffer) {
|
|
||||||
fprintf(stderr, "Could not allocate log buffer\n");
|
|
||||||
av_exit(1);
|
|
||||||
}
|
|
||||||
size = fread(logbuffer, 1, size, f);
|
|
||||||
fclose(f);
|
|
||||||
logbuffer[size] = '\0';
|
|
||||||
codec->stats_in = logbuffer;
|
codec->stats_in = logbuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user