Smaller mp4 file duration time










0














I'm creating an mp4 file at 60 FPS from a measurement which gives me frames at a variable FPS. I've done this by adding the same frame until the timestamp it give's me a new frame. Even the frame count * FPS should give me a specific duration time the final file has a smaller duration time. For example from a duration time of 8 minutes the final file has only 5 minutes. I use opencv 3.4.3 with H264 codec. Why is this happens?



This is the function:



 void ExporterChannel::ProcessMFCImage(Timestamp _timestamp, const std::string& _filename, const std::string& _data)

static bool first = true;
static long long accumulated_time_error = 0;
static long long first_timestamp;

static structs::SensorNearData::MFC::CameraImage mfc_image_struct;
static pb::SensorNearData::MFC::CameraImage mfc_image_pb;

if (first)

first = false;
mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = _timestamp;
Size frameSize(mfc_image_struct.image_width, mfc_image_struct.image_height);
bool color_mode_rgb = (config_.color == "true");
if (color_mode_rgb == true)

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, true);

else

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, false);

// check if we succeeded
if (!video_file.isOpened())

ExporterException("Could not open the output video file for writen");
return;

HandleMFCImage(mfc_image_struct);

else

if ((long long)_timestamp < (first_timestamp + STEP))

accumulated_time_error += first_timestamp + STEP - (long long)_timestamp;

else

while ((long long)_timestamp >= (first_timestamp + 2 * STEP))

HandleMFCImage(mfc_image_struct);
first_timestamp += STEP;

accumulated_time_error += (long long)_timestamp - (first_timestamp + STEP);
if (accumulated_time_error >= STEP)

HandleMFCImage(mfc_image_struct);
accumulated_time_error -= STEP;


mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = (long long)_timestamp;
HandleMFCImage(mfc_image_struct);











share|improve this question



















  • 1




    can you share code or pseudo code on how you detect frame drops and add duplicated frames? Probably there is a bug in it.
    – Micka
    Nov 12 '18 at 19:46










  • Hi Micka. I've added the code. tks. HandleMFCImage just adds the frame to the video.
    – Mihai Muraru
    Nov 13 '18 at 9:47











  • could you change it to something like double currentFps = (currentTimestamp - firstTimestamp)/numberOfRecordedFrames; while(currentFps < FPS) addImage;? Or at least just compute the totalRecordedFPS in this way and check whether this explains the problem.
    – Micka
    Nov 13 '18 at 13:44










  • Thanks. I will try this.
    – Mihai Muraru
    Nov 14 '18 at 14:06















0














I'm creating an mp4 file at 60 FPS from a measurement which gives me frames at a variable FPS. I've done this by adding the same frame until the timestamp it give's me a new frame. Even the frame count * FPS should give me a specific duration time the final file has a smaller duration time. For example from a duration time of 8 minutes the final file has only 5 minutes. I use opencv 3.4.3 with H264 codec. Why is this happens?



This is the function:



 void ExporterChannel::ProcessMFCImage(Timestamp _timestamp, const std::string& _filename, const std::string& _data)

static bool first = true;
static long long accumulated_time_error = 0;
static long long first_timestamp;

static structs::SensorNearData::MFC::CameraImage mfc_image_struct;
static pb::SensorNearData::MFC::CameraImage mfc_image_pb;

if (first)

first = false;
mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = _timestamp;
Size frameSize(mfc_image_struct.image_width, mfc_image_struct.image_height);
bool color_mode_rgb = (config_.color == "true");
if (color_mode_rgb == true)

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, true);

else

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, false);

// check if we succeeded
if (!video_file.isOpened())

ExporterException("Could not open the output video file for writen");
return;

HandleMFCImage(mfc_image_struct);

else

if ((long long)_timestamp < (first_timestamp + STEP))

accumulated_time_error += first_timestamp + STEP - (long long)_timestamp;

else

while ((long long)_timestamp >= (first_timestamp + 2 * STEP))

HandleMFCImage(mfc_image_struct);
first_timestamp += STEP;

accumulated_time_error += (long long)_timestamp - (first_timestamp + STEP);
if (accumulated_time_error >= STEP)

HandleMFCImage(mfc_image_struct);
accumulated_time_error -= STEP;


mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = (long long)_timestamp;
HandleMFCImage(mfc_image_struct);











share|improve this question



















  • 1




    can you share code or pseudo code on how you detect frame drops and add duplicated frames? Probably there is a bug in it.
    – Micka
    Nov 12 '18 at 19:46










  • Hi Micka. I've added the code. tks. HandleMFCImage just adds the frame to the video.
    – Mihai Muraru
    Nov 13 '18 at 9:47











  • could you change it to something like double currentFps = (currentTimestamp - firstTimestamp)/numberOfRecordedFrames; while(currentFps < FPS) addImage;? Or at least just compute the totalRecordedFPS in this way and check whether this explains the problem.
    – Micka
    Nov 13 '18 at 13:44










  • Thanks. I will try this.
    – Mihai Muraru
    Nov 14 '18 at 14:06













0












0








0







I'm creating an mp4 file at 60 FPS from a measurement which gives me frames at a variable FPS. I've done this by adding the same frame until the timestamp it give's me a new frame. Even the frame count * FPS should give me a specific duration time the final file has a smaller duration time. For example from a duration time of 8 minutes the final file has only 5 minutes. I use opencv 3.4.3 with H264 codec. Why is this happens?



This is the function:



 void ExporterChannel::ProcessMFCImage(Timestamp _timestamp, const std::string& _filename, const std::string& _data)

static bool first = true;
static long long accumulated_time_error = 0;
static long long first_timestamp;

static structs::SensorNearData::MFC::CameraImage mfc_image_struct;
static pb::SensorNearData::MFC::CameraImage mfc_image_pb;

if (first)

first = false;
mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = _timestamp;
Size frameSize(mfc_image_struct.image_width, mfc_image_struct.image_height);
bool color_mode_rgb = (config_.color == "true");
if (color_mode_rgb == true)

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, true);

else

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, false);

// check if we succeeded
if (!video_file.isOpened())

ExporterException("Could not open the output video file for writen");
return;

HandleMFCImage(mfc_image_struct);

else

if ((long long)_timestamp < (first_timestamp + STEP))

accumulated_time_error += first_timestamp + STEP - (long long)_timestamp;

else

while ((long long)_timestamp >= (first_timestamp + 2 * STEP))

HandleMFCImage(mfc_image_struct);
first_timestamp += STEP;

accumulated_time_error += (long long)_timestamp - (first_timestamp + STEP);
if (accumulated_time_error >= STEP)

HandleMFCImage(mfc_image_struct);
accumulated_time_error -= STEP;


mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = (long long)_timestamp;
HandleMFCImage(mfc_image_struct);











share|improve this question















I'm creating an mp4 file at 60 FPS from a measurement which gives me frames at a variable FPS. I've done this by adding the same frame until the timestamp it give's me a new frame. Even the frame count * FPS should give me a specific duration time the final file has a smaller duration time. For example from a duration time of 8 minutes the final file has only 5 minutes. I use opencv 3.4.3 with H264 codec. Why is this happens?



This is the function:



 void ExporterChannel::ProcessMFCImage(Timestamp _timestamp, const std::string& _filename, const std::string& _data)

static bool first = true;
static long long accumulated_time_error = 0;
static long long first_timestamp;

static structs::SensorNearData::MFC::CameraImage mfc_image_struct;
static pb::SensorNearData::MFC::CameraImage mfc_image_pb;

if (first)

first = false;
mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = _timestamp;
Size frameSize(mfc_image_struct.image_width, mfc_image_struct.image_height);
bool color_mode_rgb = (config_.color == "true");
if (color_mode_rgb == true)

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, true);

else

video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, false);

// check if we succeeded
if (!video_file.isOpened())

ExporterException("Could not open the output video file for writen");
return;

HandleMFCImage(mfc_image_struct);

else

if ((long long)_timestamp < (first_timestamp + STEP))

accumulated_time_error += first_timestamp + STEP - (long long)_timestamp;

else

while ((long long)_timestamp >= (first_timestamp + 2 * STEP))

HandleMFCImage(mfc_image_struct);
first_timestamp += STEP;

accumulated_time_error += (long long)_timestamp - (first_timestamp + STEP);
if (accumulated_time_error >= STEP)

HandleMFCImage(mfc_image_struct);
accumulated_time_error -= STEP;


mfc_image_pb.ParseFromString(_data);
pb2structs::convert(mfc_image_pb, mfc_image_struct);
first_timestamp = (long long)_timestamp;
HandleMFCImage(mfc_image_struct);








opencv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 9:47

























asked Nov 12 '18 at 19:16









Mihai Muraru

11




11







  • 1




    can you share code or pseudo code on how you detect frame drops and add duplicated frames? Probably there is a bug in it.
    – Micka
    Nov 12 '18 at 19:46










  • Hi Micka. I've added the code. tks. HandleMFCImage just adds the frame to the video.
    – Mihai Muraru
    Nov 13 '18 at 9:47











  • could you change it to something like double currentFps = (currentTimestamp - firstTimestamp)/numberOfRecordedFrames; while(currentFps < FPS) addImage;? Or at least just compute the totalRecordedFPS in this way and check whether this explains the problem.
    – Micka
    Nov 13 '18 at 13:44










  • Thanks. I will try this.
    – Mihai Muraru
    Nov 14 '18 at 14:06












  • 1




    can you share code or pseudo code on how you detect frame drops and add duplicated frames? Probably there is a bug in it.
    – Micka
    Nov 12 '18 at 19:46










  • Hi Micka. I've added the code. tks. HandleMFCImage just adds the frame to the video.
    – Mihai Muraru
    Nov 13 '18 at 9:47











  • could you change it to something like double currentFps = (currentTimestamp - firstTimestamp)/numberOfRecordedFrames; while(currentFps < FPS) addImage;? Or at least just compute the totalRecordedFPS in this way and check whether this explains the problem.
    – Micka
    Nov 13 '18 at 13:44










  • Thanks. I will try this.
    – Mihai Muraru
    Nov 14 '18 at 14:06







1




1




can you share code or pseudo code on how you detect frame drops and add duplicated frames? Probably there is a bug in it.
– Micka
Nov 12 '18 at 19:46




can you share code or pseudo code on how you detect frame drops and add duplicated frames? Probably there is a bug in it.
– Micka
Nov 12 '18 at 19:46












Hi Micka. I've added the code. tks. HandleMFCImage just adds the frame to the video.
– Mihai Muraru
Nov 13 '18 at 9:47





Hi Micka. I've added the code. tks. HandleMFCImage just adds the frame to the video.
– Mihai Muraru
Nov 13 '18 at 9:47













could you change it to something like double currentFps = (currentTimestamp - firstTimestamp)/numberOfRecordedFrames; while(currentFps < FPS) addImage;? Or at least just compute the totalRecordedFPS in this way and check whether this explains the problem.
– Micka
Nov 13 '18 at 13:44




could you change it to something like double currentFps = (currentTimestamp - firstTimestamp)/numberOfRecordedFrames; while(currentFps < FPS) addImage;? Or at least just compute the totalRecordedFPS in this way and check whether this explains the problem.
– Micka
Nov 13 '18 at 13:44












Thanks. I will try this.
– Mihai Muraru
Nov 14 '18 at 14:06




Thanks. I will try this.
– Mihai Muraru
Nov 14 '18 at 14:06












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268680%2fsmaller-mp4-file-duration-time%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268680%2fsmaller-mp4-file-duration-time%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto