예제 #1
0
static int
recurse(const char * path)
{
  FTS *fts;
  FTSENT *ftsent;
  char * const apath[] = { strdup(path), NULL };
  fts = fts_open(apath,FTS_NOCHDIR|FTS_NOSTAT|FTS_COMFOLLOW, NULL);
  if ( NULL == fts)
    {
      ERROR("fts_open(%s) failed", path);
      return EXIT_FAILURE;
    }
  while ((ftsent = fts_read(fts)))
    switch (ftsent->fts_info)
      {
      case FTS_F:
	if ( is_video(ftsent) )
	  if ( convert_video(ftsent) )
	    ERROR("conversion failed: %s", ftsent->fts_path);
	break;
      case FTS_SLNONE:
      case FTS_NS:
      case FTS_ERR:
	ERROR("fts_read: %s (%s)", ftsent->fts_path, strerror(errno));
      default:(void)0;
      }
  fts_close(fts);
  free(apath[0]);
  return EXIT_SUCCESS;
}
예제 #2
0
	void encode_video_frame(core::read_frame& frame)
	{ 
		auto c = video_st_->codec;
		
		auto in_time  = static_cast<double>(in_frame_number_) / format_desc_.fps;
		auto out_time = static_cast<double>(out_frame_number_) / (static_cast<double>(c->time_base.den) / static_cast<double>(c->time_base.num));
		
		in_frame_number_++;

		if(out_time - in_time > 0.01)
			return;
 
		auto av_frame = convert_video(frame, c);
		av_frame->interlaced_frame	= format_desc_.field_mode != core::field_mode::progressive;
		av_frame->top_field_first	= format_desc_.field_mode == core::field_mode::upper;
		av_frame->pts				= out_frame_number_++;

		int out_size = THROW_ON_ERROR2(avcodec_encode_video(c, video_outbuf_.data(), video_outbuf_.size(), av_frame.get()), "[ffmpeg_consumer]");
		if(out_size == 0)
			return;
				
		safe_ptr<AVPacket> pkt(new AVPacket, [](AVPacket* p)
		{
			av_free_packet(p);
			delete p;
		});
		av_init_packet(pkt.get());
 
		if (c->coded_frame->pts != AV_NOPTS_VALUE)
			pkt->pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st_->time_base);

		if(c->coded_frame->key_frame)
			pkt->flags |= AV_PKT_FLAG_KEY;

		pkt->stream_index	= video_st_->index;
		pkt->data			= video_outbuf_.data();
		pkt->size			= out_size;
 			
		av_interleaved_write_frame(oc_.get(), pkt.get());		
	}