2003-02-16 17:04:39 +00:00
|
|
|
/*
|
|
|
|
mkvmerge -- utility for splicing together matroska files
|
|
|
|
from component media subtypes
|
|
|
|
|
|
|
|
p_video.h
|
|
|
|
|
|
|
|
Written by Moritz Bunkus <moritz@bunkus.org>
|
|
|
|
|
|
|
|
Distributed under the GPL
|
|
|
|
see the file COPYING for details
|
|
|
|
or visit http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\file
|
2003-04-20 19:32:11 +00:00
|
|
|
\version \$Id: p_video.cpp,v 1.26 2003/04/20 19:32:11 mosu Exp $
|
2003-02-16 17:04:39 +00:00
|
|
|
\brief video output module
|
|
|
|
\author Moritz Bunkus <moritz @ bunkus.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
2003-04-18 10:28:14 +00:00
|
|
|
#include "pr_generic.h"
|
2003-02-16 17:04:39 +00:00
|
|
|
#include "p_video.h"
|
2003-04-18 12:00:46 +00:00
|
|
|
#include "matroska.h"
|
2003-02-16 17:04:39 +00:00
|
|
|
|
|
|
|
#ifdef DMALLOC
|
|
|
|
#include <dmalloc.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-05 17:44:32 +00:00
|
|
|
video_packetizer_c::video_packetizer_c(double nfps, int nwidth,
|
2003-02-16 17:04:39 +00:00
|
|
|
int nheight, int nbpp,
|
2003-03-05 13:51:20 +00:00
|
|
|
int navi_compat_mode, track_info_t *nti)
|
2003-04-18 10:28:14 +00:00
|
|
|
throw (error_c) : generic_packetizer_c(nti) {
|
2003-02-16 17:04:39 +00:00
|
|
|
fps = nfps;
|
|
|
|
width = nwidth;
|
|
|
|
height = nheight;
|
|
|
|
bpp = nbpp;
|
|
|
|
avi_compat_mode = navi_compat_mode;
|
|
|
|
frames_output = 0;
|
2003-02-25 14:24:43 +00:00
|
|
|
avi_compat_mode = 1;
|
2003-04-18 13:08:04 +00:00
|
|
|
ref_timecode = -1;
|
2003-04-20 14:59:33 +00:00
|
|
|
if (get_cue_creation() == CUES_UNSPECIFIED)
|
|
|
|
set_cue_creation(CUES_IFRAMES);
|
2003-02-16 17:04:39 +00:00
|
|
|
set_header();
|
|
|
|
}
|
|
|
|
|
|
|
|
void video_packetizer_c::set_header() {
|
|
|
|
using namespace LIBMATROSKA_NAMESPACE;
|
2003-04-18 12:00:46 +00:00
|
|
|
|
|
|
|
set_serial(-1);
|
|
|
|
set_track_type(track_video);
|
|
|
|
set_codec_id(MKV_V_MSCOMP);
|
|
|
|
set_codec_private(ti->private_data, ti->private_size);
|
2003-02-16 17:04:39 +00:00
|
|
|
|
2003-04-17 16:19:38 +00:00
|
|
|
// Set MinCache and MaxCache to 1 for I- and P-frames. If you only
|
|
|
|
// have I-frames then both can be set to 0 (e.g. MJPEG). 2 is needed
|
|
|
|
// if there are B-frames as well.
|
2003-04-18 12:00:46 +00:00
|
|
|
set_track_min_cache(1);
|
|
|
|
set_track_max_cache(1);
|
2003-02-16 17:04:39 +00:00
|
|
|
|
2003-04-18 12:00:46 +00:00
|
|
|
set_video_pixel_width(width);
|
|
|
|
set_video_pixel_height(height);
|
|
|
|
set_video_frame_rate(fps);
|
2003-02-16 17:04:39 +00:00
|
|
|
|
2003-04-18 12:00:46 +00:00
|
|
|
generic_packetizer_c::set_header();
|
2003-02-16 17:04:39 +00:00
|
|
|
}
|
|
|
|
|
2003-04-11 11:27:14 +00:00
|
|
|
int video_packetizer_c::process(unsigned char *buf, int size,
|
2003-04-20 19:32:11 +00:00
|
|
|
int64_t old_timecode, int64_t, int64_t bref,
|
2003-04-18 13:21:11 +00:00
|
|
|
int64_t) {
|
2003-04-13 15:23:03 +00:00
|
|
|
int64_t timecode;
|
2003-03-01 16:59:59 +00:00
|
|
|
|
2003-03-03 17:08:16 +00:00
|
|
|
if (old_timecode == -1)
|
2003-04-13 15:23:03 +00:00
|
|
|
timecode = (int64_t)(1000.0 * frames_output / fps);
|
2003-03-01 16:59:59 +00:00
|
|
|
else
|
|
|
|
timecode = old_timecode;
|
|
|
|
|
2003-04-20 19:32:11 +00:00
|
|
|
if (bref == -1) {
|
2003-04-18 13:08:04 +00:00
|
|
|
// Add a key frame and save its timecode so that we can reference it later.
|
|
|
|
add_packet(buf, size, timecode);
|
|
|
|
ref_timecode = timecode;
|
|
|
|
} else {
|
2003-03-04 09:27:05 +00:00
|
|
|
// This is a P frame - let's reference the last frame.
|
2003-04-18 13:08:04 +00:00
|
|
|
add_packet(buf, size, timecode, ref_timecode);
|
|
|
|
ref_timecode = timecode;
|
|
|
|
}
|
2003-04-11 11:27:14 +00:00
|
|
|
|
2003-04-20 19:32:11 +00:00
|
|
|
frames_output++;
|
2003-02-16 17:04:39 +00:00
|
|
|
|
|
|
|
return EMOREDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
video_packetizer_c::~video_packetizer_c() {
|
|
|
|
}
|