diff --git a/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileReader.h b/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileReader.h
index c2c5ed4b4..8ea6a1f2a 100644
--- a/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileReader.h
+++ b/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileReader.h
@@ -2,13 +2,13 @@
// The Accord.NET Framework
// http://accord-framework.net
//
-// Copyright © AForge.NET, 2009-2011
+// Copyright © AForge.NET, 2009-2011
// contacts@aforgenet.com
//
-// Copyright © MelvinGr, 2016-2017
+// Copyright © MelvinGr, 2016-2017
// https://github.com/MelvinGr
//
-// Copyright © César Souza, 2009-2017
+// Copyright © César Souza, 2009-2017
// cesarsouza at gmail.com
//
// This program is free software; you can redistribute it and/or modify
@@ -381,9 +381,9 @@ namespace Accord {
/// Thrown if no video file was open.
/// A error occurred while reading next video frame. See exception message.
///
- void ReadVideoFrame(BitmapData^ output)
+ Bitmap^ ReadVideoFrame(BitmapData^ output)
{
- readVideoFrame(-1, output, nullptr);
+ return readVideoFrame(-1, output, nullptr);
}
///
@@ -396,9 +396,9 @@ namespace Accord {
/// Thrown if no video file was open.
/// A error occurred while reading next video frame. See exception message.
///
- void ReadVideoFrame(int frameIndex, BitmapData^ output)
+ Bitmap^ ReadVideoFrame(int frameIndex, BitmapData^ output)
{
- readVideoFrame(frameIndex, output, nullptr);
+ return readVideoFrame(frameIndex, output, nullptr);
}
@@ -443,9 +443,9 @@ namespace Accord {
/// Thrown if no video file was open.
/// A error occurred while reading next video frame. See exception message.
///
- void ReadVideoFrame(BitmapData^ output, System::Collections::Generic::IList^ audio)
+ Bitmap^ ReadVideoFrame(BitmapData^ output, System::Collections::Generic::IList^ audio)
{
- readVideoFrame(-1, output, audio);
+ return readVideoFrame(-1, output, audio);
}
///
@@ -458,9 +458,9 @@ namespace Accord {
/// Thrown if no video file was open.
/// A error occurred while reading next video frame. See exception message.
///
- void ReadVideoFrame(int frameIndex, BitmapData^ output, System::Collections::Generic::IList^ audio)
+ Bitmap^ ReadVideoFrame(int frameIndex, BitmapData^ output, System::Collections::Generic::IList^ audio)
{
- readVideoFrame(frameIndex, output, audio);
+ return readVideoFrame(frameIndex, output, audio);
}
diff --git a/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileWriter.cpp b/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileWriter.cpp
index 3efc8a53f..c16d15b40 100644
--- a/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileWriter.cpp
+++ b/Sources/Extras/Accord.Video.FFMPEG.GPL/VideoFileWriter.cpp
@@ -372,16 +372,11 @@ namespace Accord {
// encode the image
CHECK(avcodec_encode_video2(c, &pkt, frame, &got_packet), "Error encoding video frame");
- if (got_packet)
- {
- pkt.duration = ost->next_pts - frame->pts;
- pkt.pts = ost->frame->pts;
- pkt.dts = ost->frame->pts;
- CHECK(write_frame(oc, &c->time_base, ost->st, &pkt), "Error while writing video frame");
- return true;
- }
-
- return false;
+ pkt.duration = ost->next_pts - frame->pts;
+ pkt.pts = ost->frame->pts;
+ pkt.dts = ost->frame->pts;
+ CHECK(write_frame(oc, &c->time_base, ost->st, &pkt), "Error while writing video frame");
+ return true;
}
///
@@ -401,16 +396,11 @@ namespace Accord {
// encode the signal
CHECK(avcodec_encode_audio2(c, &pkt, frame, &got_packet), "Error encoding audio frame");
- if (got_packet)
- {
- pkt.duration = ost->next_pts - frame->pts;
- pkt.pts = ost->frame->pts;
- pkt.dts = ost->frame->pts;
- CHECK(write_frame(oc, &c->time_base, ost->st, &pkt), "Error while writing audio frame");
- return true;
- }
-
- return false;
+ pkt.duration = ost->next_pts - frame->pts;
+ pkt.pts = ost->frame->pts;
+ pkt.dts = ost->frame->pts;
+ CHECK(write_frame(oc, &c->time_base, ost->st, &pkt), "Error while writing audio frame");
+ return true;
}
@@ -442,6 +432,27 @@ namespace Accord {
void close()
{
+ if (have_video) {
+ int got_output = 0;
+ int ret = 0;
+
+ for (got_output = 1; got_output;) {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
+ if (got_output) {
+ pkt.duration = 1;
+ pkt.pts = video_st.next_pts;
+ pkt.dts = pkt.pts;
+
+ CHECK(write_frame(oc, &c->time_base, video_st.st, &pkt), "Error while writing video frame");
+ av_free_packet(&pkt);
+
+ video_st.next_pts++;
+ }
+ }
+ }
// Write the trailer, if any. The trailer must be written before you
// close the CodecContexts open when you wrote the header; otherwise
// av_write_trailer() may try to use memory that was freed on
@@ -593,7 +604,7 @@ namespace Accord {
uint8_t* q = (uint8_t*)ost->tmp_frame->data[0];
int remainingNumberOfSamplesPerChannel = length;
- size_t sampleSize = m_input_audio_sample_size;
+ size_t sampleSize = m_input_audio_sample_size * this->m_input_audio_channels;
while (remainingNumberOfSamplesPerChannel > 0)
{