Page Menu
Home
Search
Configure Global Search
Log In
Files
F18455
avi-file-size.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Jason Wilkins (jwilkins)
Nov 13 2013, 4:09 PM
Size
5 KB
Subscribers
None
avi-file-size.patch
View Options
Index: source/blender/avi/AVI_avi.h
===================================================================
--- source/blender/avi/AVI_avi.h (revision 44217)
+++ source/blender/avi/AVI_avi.h (working copy)
@@ -157,12 +157,6 @@
int Size;
} AviIndexEntry;
-typedef struct _AviIndex {
- int fcc;
- int size;
- AviIndexEntry *entrys;
-} AviIndex;
-
typedef enum {
AVI_FORMAT_RGB24, /* The most basic of forms, 3 bytes per pixel, 1 per r, g, b */
AVI_FORMAT_RGB32, /* The second most basic of forms, 4 bytes per pixel, 1 per r, g, b, alpha */
Index: source/blender/avi/intern/avi.c
===================================================================
--- source/blender/avi/intern/avi.c (revision 44217)
+++ source/blender/avi/intern/avi.c (working copy)
@@ -727,7 +727,7 @@
AviList list;
AviChunk chunk;
int i;
- int64_t header_pos1, header_pos2;
+ int64_t header_pos1, header_pos2, header_pos_junk;
int64_t stream_pos1, stream_pos2;
movie->type = AVI_MOVIE_WRITE;
@@ -884,10 +884,14 @@
fseek (movie->fp, stream_pos2, SEEK_SET);
}
- if (ftell(movie->fp) < 2024 - 8) {
+ header_pos_junk = ftell(movie->fp);
+
+ if (header_pos_junk < 2024 - 8) {
chunk.fcc = FCC("JUNK");
- chunk.size = 2024-8-ftell(movie->fp);
+ /* pos is known small here, so cast is safe */
+ chunk.size = 2024-8-(int)header_pos_junk;
+
awrite (movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK);
for (i=0; i < chunk.size; i++)
@@ -911,6 +915,25 @@
return AVI_ERROR_NONE;
}
+/* Determines how big AVI file will be after writing */
+static int64_t compute_final_offset(AviMovie * movie, va_list ap)
+{
+ int64_t offset = ftell(movie->fp);
+ int i;
+
+ offset += sizeof(AviList);
+
+ for (i = 0; i < movie->header->Streams; i++) {
+ offset += sizeof(AviChunk);
+ offset += va_arg(ap, int);
+
+ if (offset%4)
+ offset += (4 - offset%4);
+ }
+
+ return offset;
+}
+
AviError AVI_write_frame (AviMovie *movie, int frame_num, ...)
{
AviList list;
@@ -922,10 +945,19 @@
AviFormat format;
void *buffer;
int size;
+ int64_t final_off;
+ int index;
if (frame_num < 0)
return AVI_ERROR_OPTION;
+ va_start (ap, frame_num);
+ final_off = compute_final_offset(movie, ap);
+ va_end (ap);
+
+ if (final_off-12L-movie->movi_offset > INT_MAX)
+ return AVI_ERROR_WRITING;
+
/* Allocate the new memory for the index entry */
if (frame_num+1 > movie->index_entries) {
@@ -969,7 +1001,7 @@
/* Write the header info for this data chunk */
- fseek (movie->fp, 0L, SEEK_END);
+ /* note: following code assumes file pointer is at the end of file */
chunk.fcc = avi_get_data_id (format, stream);
chunk.size = size;
@@ -979,12 +1011,12 @@
awrite (movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK);
/* Write the index entry for this data chunk */
+ index = frame_num * (movie->header->Streams+1) + stream + 1;
+ movie->entries[index].ChunkId = chunk.fcc;
+ movie->entries[index].Flags = AVIIF_KEYFRAME;
+ movie->entries[index].Offset = (int)(ftell(movie->fp)-12L-movie->movi_offset);
+ movie->entries[index].Size = chunk.size;
- movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].ChunkId = chunk.fcc;
- movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Flags = AVIIF_KEYFRAME;
- movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Offset = ftell(movie->fp)-12L-movie->movi_offset;
- movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Size = chunk.size;
-
/* Write the chunk */
awrite (movie, buffer, 1, size, movie->fp, AVI_RAW);
MEM_freeN (buffer);
@@ -995,21 +1027,24 @@
movie->streams[stream].sh.Length++;
fseek (movie->fp, movie->offset_table[1+stream*2], SEEK_SET);
awrite (movie, &movie->streams[stream].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH);
+
+ fseek (movie->fp, 0L, SEEK_END);
}
va_end (ap);
/* Record the entry for the new record */
- fseek (movie->fp, 0L, SEEK_END);
+ /* note: following code assumes file pointer is at the end of file */
- movie->entries[frame_num * (movie->header->Streams+1)].ChunkId = FCC("rec ");
- movie->entries[frame_num * (movie->header->Streams+1)].Flags = AVIIF_LIST;
- movie->entries[frame_num * (movie->header->Streams+1)].Offset = rec_off-8L-movie->movi_offset;
- movie->entries[frame_num * (movie->header->Streams+1)].Size = ftell(movie->fp)-(rec_off+4L);
+ index = frame_num * (movie->header->Streams+1);
+ movie->entries[index].ChunkId = FCC("rec ");
+ movie->entries[index].Flags = AVIIF_LIST;
+ movie->entries[index].Offset = (int)(rec_off-8L-movie->movi_offset);
+ movie->entries[index].Size = (int)(ftell(movie->fp)-(rec_off+4L));
/* Update the record size */
fseek (movie->fp, rec_off, SEEK_SET);
- PUT_FCCN (movie->entries[frame_num * (movie->header->Streams+1)].Size, movie->fp);
+ PUT_FCCN (movie->entries[index].Size, movie->fp);
/* Update the main header information in the file */
movie->header->TotalFrames++;
@@ -1021,7 +1056,8 @@
AviError AVI_close_compress (AviMovie *movie)
{
- int temp, movi_size, i;
+ int64_t temp, movi_size;
+ int i;
fseek (movie->fp, 0L, SEEK_END);
movi_size = ftell (movie->fp);
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3a/68/31949d098a2ee612ebbd2d3fbd7c
Event Timeline
Log In to Comment