Skip to content

Commit 5fb9755

Browse files
committed
Fix truncated output filenames in FFmpegWriter
1 parent 90a5610 commit 5fb9755

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

include/FFmpegUtilities.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
#define AV_REGISTER_ALL
150150
#define AVCODEC_REGISTER_ALL
151151
#define AV_FILENAME url
152+
#define AV_SET_FILENAME(oc, f) oc->AV_FILENAME = av_strdup(f)
152153
#define MY_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE
153154
#define AV_ALLOCATE_FRAME() av_frame_alloc()
154155
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1)
@@ -184,6 +185,7 @@
184185
#define AV_REGISTER_ALL av_register_all();
185186
#define AVCODEC_REGISTER_ALL avcodec_register_all();
186187
#define AV_FILENAME filename
188+
#define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f)
187189
#define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
188190
#define AV_ALLOCATE_FRAME() av_frame_alloc()
189191
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1)
@@ -222,6 +224,7 @@
222224
#define AV_REGISTER_ALL av_register_all();
223225
#define AVCODEC_REGISTER_ALL avcodec_register_all();
224226
#define AV_FILENAME filename
227+
#define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f)
225228
#define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
226229
#define AV_ALLOCATE_FRAME() av_frame_alloc()
227230
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height)
@@ -252,6 +255,7 @@
252255
#define AV_REGISTER_ALL av_register_all();
253256
#define AVCODEC_REGISTER_ALL avcodec_register_all();
254257
#define AV_FILENAME filename
258+
#define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f)
255259
#define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
256260
#define AV_ALLOCATE_FRAME() avcodec_alloc_frame()
257261
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height)

src/FFmpegWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,7 @@ void FFmpegWriter::WriteHeader() {
525525
}
526526

527527
// Force the output filename (which doesn't always happen for some reason)
528-
snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", path.c_str());
529-
530-
// Write the stream header, if any
528+
AV_SET_FILENAME(oc, path.c_str());
531529

532530
// Add general metadata (if any)
533531
for (std::map<string, string>::iterator iter = info.metadata.begin(); iter != info.metadata.end(); ++iter) {
@@ -543,6 +541,7 @@ void FFmpegWriter::WriteHeader() {
543541
if (is_mp4 || is_mov)
544542
av_dict_copy(&dict, mux_dict, 0);
545543

544+
// Write the stream header
546545
if (avformat_write_header(oc, &dict) != 0) {
547546
throw InvalidFile("Could not write header to file.", path);
548547
};

0 commit comments

Comments
 (0)