Esempio n. 1
0
bool AdeniumRender::resize(int w, int h)
{ 
    if(!isSizeValid(w, h)) return false;
	if(w==m_imageWidth && h == m_imageHeight) return false;
    m_imageWidth = w;
    m_imageHeight = h;
    std::cout<<" resize render area: "<<w<<" x "<<h<<"\n";
	return true;
}
Esempio n. 2
0
void djvVectorUtilTest::run(int &, char **)
{
    DJV_DEBUG("djvVectorUtilTest::run");
    
    abs();
    swap();
    range();
    isSizeValid();
    length();
    normalize();
    dot();
    aspect();
    convert();
}
Esempio n. 3
0
bool QVideoEncoder::createFile(QString fileName,unsigned width,unsigned height,unsigned bitrate,unsigned gop,unsigned fps)
{
   // If we had an open video, close it.
   close();

   Width=width;
   Height=height;
   Gop=gop;
   Bitrate=bitrate;

   if(!isSizeValid())
   {
      printf("Invalid size\n");
      return false;
   }

   pOutputFormat = ffmpeg::av_guess_format(nullptr, fileName.toStdString().c_str(), nullptr);
   if (!pOutputFormat) {
      printf("Could not deduce output format from file extension: using MPEG.\n");
      pOutputFormat = ffmpeg::av_guess_format("mpeg", nullptr, nullptr);
   }

   pFormatCtx=ffmpeg::avformat_alloc_context();
   if(!pFormatCtx)
   {
      printf("Error allocating format context\n");
      return false;
   }
   pFormatCtx->oformat = pOutputFormat;
   snprintf(pFormatCtx->filename, sizeof(pFormatCtx->filename), "%s", fileName.toStdString().c_str());


   // Add the video stream

   pVideoStream = avformat_new_stream(pFormatCtx,0);
   if(!pVideoStream )
   {
      printf("Could not allocate stream\n");
      return false;
   }


   pCodecCtx=pVideoStream->codec;
   pCodecCtx->codec_id = pOutputFormat->video_codec;
   pCodecCtx->codec_type = ffmpeg::AVMEDIA_TYPE_VIDEO;

   pCodecCtx->bit_rate = Bitrate;
   pCodecCtx->width = getWidth();
   pCodecCtx->height = getHeight();
   pCodecCtx->time_base.den = fps;
   pCodecCtx->time_base.num = 1;
   pCodecCtx->gop_size = Gop;
   pCodecCtx->pix_fmt = ffmpeg::PIX_FMT_YUV420P;


   //avcodec_thread_init(pCodecCtx, 10);
   pCodecCtx->thread_count= 10;

   //if (c->codec_id == CODEC_ID_MPEG2VIDEO)
   //{
      //c->max_b_frames = 2;  // just for testing, we also add B frames
   //}

   // some formats want stream headers to be separate
   if(pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
      pCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;


   av_dump_format(pFormatCtx, 0, fileName.toStdString().c_str(), 1);

   // open_video
   // find the video encoder
   pCodec = avcodec_find_encoder(pCodecCtx->codec_id);
   if (!pCodec)
   {
      printf("codec not found\n");
      return false;
   }
   // open the codec
   if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0)
   {
      printf("could not open codec\n");
      return false;
   }

   // Allocate memory for output
   if(!initOutputBuf())
   {
      printf("Can't allocate memory for output bitstream\n");
      return false;
   }

   // Allocate the YUV frame
   if(!initFrame())
   {
      printf("Can't init frame\n");
      return false;
   }

   if (avio_open(&pFormatCtx->pb, fileName.toStdString().c_str(), AVIO_FLAG_WRITE) < 0)
   {
      printf( "Could not open '%s'\n", fileName.toStdString().c_str());
      return false;
   }

   avformat_write_header(pFormatCtx, nullptr);



   ok=true;

   return true;
}
Esempio n. 4
0
bool ModelIndexInfo::valid() const
{
    return isPositionValid() && isSizeValid() && overallSize.isValid();
}
Esempio n. 5
0
bool QVideoEncoder::open(QString* errorString/*=0*/)
{
	if (m_isOpen)
	{
		//the stream is already opened!
		return false;
	}

	if (!isSizeValid())
	{
		if (errorString)
			*errorString = "Invalid video size";
		return false;
	}

	//Initialize libavcodec, and register all codecs and formats
	av_register_all();

	// find the output format
	avformat_alloc_output_context2(&m_ff->formatContext, NULL, NULL, qPrintable(m_filename));
	if (!m_ff->formatContext)
	{
		if (errorString)
			*errorString = "Could not deduce output format from file extension: using MPEG";
		
		avformat_alloc_output_context2(&m_ff->formatContext, NULL, "mpeg", qPrintable(m_filename));
		if (!m_ff->formatContext)
		{
			if (errorString)
				*errorString = "Codec not found";
			return false;
		}
	}

	// get the codec
	AVCodecID codec_id = m_ff->formatContext->oformat->video_codec;
	//codec_id = AV_CODEC_ID_MPEG1VIDEO;
	//codec_id = AV_CODEC_ID_H264;
	AVCodec *pCodec = avcodec_find_encoder(codec_id);
	if (!pCodec)
	{
		if (errorString)
			*errorString = "Could not load the codec";
		return false;
	}
	m_ff->codecContext = avcodec_alloc_context3(pCodec);

	/* put sample parameters */
	m_ff->codecContext->bit_rate = m_bitrate;
	/* resolution must be a multiple of two */
	m_ff->codecContext->width = m_width;
	m_ff->codecContext->height = m_height;
	/* frames per second */
	m_ff->codecContext->time_base.num = 1;
	m_ff->codecContext->time_base.den = m_fps;
	m_ff->codecContext->gop_size = m_gop;
	m_ff->codecContext->max_b_frames = 1;
	m_ff->codecContext->pix_fmt = AV_PIX_FMT_YUV420P;

	//DGM: doesn't really change anything. We only get different warnings if we enabled this :(
	//m_ff->codecContext->rc_buffer_size = m_bitrate * 2;
	//m_ff->codecContext->rc_max_rate = m_bitrate;

	if (codec_id == AV_CODEC_ID_H264)
	{
		av_opt_set(m_ff->codecContext->priv_data, "preset", "slow", 0);
	}
	else if (codec_id == AV_CODEC_ID_MPEG1VIDEO)
	{
		/* Needed to avoid using macroblocks in which some coeffs overflow.
		* This does not happen with normal video, it just happens here as
		* the motion of the chroma plane does not match the luma plane. */
		m_ff->codecContext->mb_decision = 2;
	}

	//some formats want stream headers to be separate
	if (m_ff->formatContext->oformat->flags & AVFMT_GLOBALHEADER)
	{
		m_ff->codecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;
	}

	// Add the video stream
	m_ff->videoStream = avformat_new_stream(m_ff->formatContext, pCodec);
	if (!m_ff->videoStream )
	{
		if (errorString)
			*errorString = "Failed to allocate the output stream";
		return false;
	}
	m_ff->videoStream->id = m_ff->formatContext->nb_streams-1;
	m_ff->videoStream->codec = m_ff->codecContext;
	m_ff->videoStream->time_base.num = 1;
	m_ff->videoStream->time_base.den = m_fps;

	//av_dump_format(m_ff->formatContext, 0, fileName.toStdString().c_str(), 1);

	// open the codec
	if (avcodec_open2(m_ff->codecContext, pCodec, 0) < 0)
	{
		if (errorString)
			*errorString = "Could not open the codec";
		return false;
	}

	// Allocate the YUV frame
	if (!initFrame())
	{
		if (errorString)
			*errorString = "Could not init the internal frame";
		return false;
	}

	if (avio_open(&m_ff->formatContext->pb, qPrintable(m_filename), AVIO_FLAG_WRITE) < 0)
	{
		if (errorString)
			*errorString = QString("Could not open '%1'").arg(m_filename);
		return false;
	}

	int	err = avformat_write_header(m_ff->formatContext, NULL);
	
	if ( err != 0 )
	{
		if (errorString)
			*errorString = QString("Could not write header for '%1'").arg(m_filename);
		return false;
	}

	m_isOpen = true;

	return true;
}