void vidout_set(int fd) { int ret; if (options[OptSetVideoOutFormat] || options[OptTryVideoOutFormat]) { struct v4l2_format in_vfmt; in_vfmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt) == 0) { if (set_fmts_out & FmtWidth) in_vfmt.fmt.pix.width = vfmt_out.fmt.pix.width; if (set_fmts_out & FmtHeight) in_vfmt.fmt.pix.height = vfmt_out.fmt.pix.height; if (set_fmts_out & FmtPixelFormat) { in_vfmt.fmt.pix.pixelformat = vfmt_out.fmt.pix.pixelformat; if (in_vfmt.fmt.pix.pixelformat < 256) { in_vfmt.fmt.pix.pixelformat = find_pixel_format(fd, in_vfmt.fmt.pix.pixelformat, false); } } if (options[OptSetVideoOutFormat]) ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt); else ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt); if (ret == 0 && verbose) printfmt(in_vfmt); } } if (options[OptSetVideoOutMplaneFormat] || options[OptTryVideoOutMplaneFormat]) { struct v4l2_format in_vfmt; in_vfmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt) == 0) { if (set_fmts_out & FmtWidth) in_vfmt.fmt.pix_mp.width = vfmt_out.fmt.pix_mp.width; if (set_fmts_out & FmtHeight) in_vfmt.fmt.pix_mp.height = vfmt_out.fmt.pix_mp.height; if (set_fmts_out & FmtPixelFormat) { in_vfmt.fmt.pix_mp.pixelformat = vfmt_out.fmt.pix_mp.pixelformat; if (in_vfmt.fmt.pix_mp.pixelformat < 256) { in_vfmt.fmt.pix_mp.pixelformat = find_pixel_format(fd, in_vfmt.fmt.pix_mp.pixelformat, true); } } if (options[OptSetVideoOutMplaneFormat]) ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt); else ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt); if (ret == 0 && verbose) printfmt(in_vfmt); } } }
Renderer* GtkAggVaapiGlue::createRenderHandler() { dprintf("GtkAggVaapiGlue::createRenderHandler()\n"); VaapiGlobalContext * const gvactx = VaapiGlobalContext::get(); if (!gvactx) return NULL; std::vector<VaapiImageFormat> formats = gvactx->getSubpictureFormats(); for (unsigned int i = 0; i < formats.size(); i++) { if (vaapi_image_format_is_rgb(formats[i])) { _vaapi_image_format = formats[i]; break; } } if (_vaapi_image_format == VAAPI_IMAGE_NONE) return NULL; const char *agg_pixel_format; agg_pixel_format = find_pixel_format(_vaapi_image_format); if (!agg_pixel_format) { log_debug("GTK-AGG: Unknown RGB format %s reported by VA-API." " Please report this to the gnash-dev " "mailing list.", string_of_FOURCC(_vaapi_image_format)); return NULL; } Renderer * const renderer = create_Renderer_agg(agg_pixel_format); _agg_renderer = static_cast<Renderer_agg_base *>(renderer); return renderer; }
/* add a video output stream */ AVStream* CEncoder::add_video_stream(enum AVCodecID codec_id, char *name) { AVCodec *codec; AVStream *st; AVCodecContext *video_enc; /* find the video encoder */ if (name) { codec = avcodec_find_encoder_by_name(name); if (!codec) { av_log(NULL, AV_LOG_ERROR, "codec not found video encoder:%s\n", name); return NULL; } } else { codec = avcodec_find_encoder(codec_id); if (!codec) { av_log(NULL, AV_LOG_ERROR, "codec not found video by ID=%d\n", codec_id); return NULL; } } if(codec->type != AVMEDIA_TYPE_VIDEO) { av_log(NULL, AV_LOG_ERROR, "Invalid video encoder type '%s'\n", name); return NULL; } if (frame_pix_fmt == AV_PIX_FMT_NONE) { frame_pix_fmt = find_pixel_format(codec->pix_fmts); if (frame_pix_fmt == AV_PIX_FMT_NONE) frame_pix_fmt = codec->pix_fmts[0]; } st = avformat_new_stream(oc, NULL); if (!st) { av_log(NULL, AV_LOG_ERROR, "Could not alloc stream\n"); return NULL; } st->id = 0; video_enc = st->codec; video_enc->codec_type = AVMEDIA_TYPE_VIDEO; if (codec_id) video_enc->codec_id = codec_id; else video_enc->codec_id = codec->id; avcodec_get_context_defaults3(video_enc, codec); if (video_rc_max_rate != NO_VALUE) if (video_bit_rate > video_rc_max_rate) video_bit_rate = video_rc_max_rate; if ((sample_aspect_ratio.num != 1) && (sample_aspect_ratio.den != 1)) { sample_aspect_ratio = av_d2q((double)sample_aspect_ratio.num / (double)sample_aspect_ratio.den * (double)video_height/(double)video_width, 255); } if ((video_bit_rate == 0) && (video_qscale == 0)) video_qscale = 4; st->sample_aspect_ratio = sample_aspect_ratio; if (video_bit_rate) video_enc->bit_rate = video_bit_rate; video_enc->width = video_width; video_enc->height = video_height; video_enc->time_base.num = g_enc_opt.m_FrameNum; video_enc->time_base.den = g_enc_opt.m_FrameDen; if (video_gop_size) video_enc->gop_size = video_gop_size; /* emit one intra frame every twelve frames at most */ video_enc->pix_fmt = frame_pix_fmt; video_enc->sample_aspect_ratio = sample_aspect_ratio; if (video_codec_tag) video_enc->codec_tag = video_codec_tag; if (video_qscale) { video_enc->flags |= CODEC_FLAG_QSCALE; video_enc->global_quality = FF_QP2LAMBDA * video_qscale; } if (video_rc_max_rate != NO_VALUE) video_enc->rc_max_rate = video_rc_max_rate; if (video_rc_min_rate != NO_VALUE) video_enc->rc_min_rate = video_rc_min_rate; if (video_rc_buffer_size != NO_VALUE) video_enc->rc_buffer_size = video_rc_buffer_size; if (video_coder_type != NO_VALUE) video_enc->coder_type = video_coder_type; if (video_max_b_frames != NO_VALUE) video_enc->max_b_frames = video_max_b_frames; if (video_level != NO_VALUE) video_enc->level = video_level; if (video_sc_threshold != NO_VALUE) video_enc->scenechange_threshold = video_sc_threshold; if (video_qmin != NO_VALUE) video_enc->qmin = video_qmin; if (video_qmax != NO_VALUE) video_enc->qmax = video_qmax; if (video_qdiff != NO_VALUE) video_enc->max_qdiff = video_qdiff; if (video_i_qfactor != NO_VALUE) video_enc->b_quant_factor = video_i_qfactor; if (video_rc_eq) video_enc->rc_eq = av_strdup(video_rc_eq); if (video_qcomp != NO_VALUE) video_enc->qcompress = video_qcomp; if (video_me_range != NO_VALUE) video_enc->me_range = video_me_range; if (thread_count) video_enc->thread_count = thread_count; switch(video_enc->codec_id) { case CODEC_ID_MPEG2VIDEO: video_enc->max_b_frames = 2; break; case CODEC_ID_MPEG1VIDEO: video_enc->mb_decision = 2; break; default: break; } // some formats want stream headers to be separate if(oc->oformat->flags & AVFMT_GLOBALHEADER) video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; /* open the codec */ if (avcodec_open2(video_enc, codec, &video_options) < 0) { av_log(NULL, AV_LOG_ERROR, "could not open video codec\n"); return NULL; } if (oc->oformat->flags & AVFMT_RAWPICTURE) { av_log(NULL, AV_LOG_ERROR, "Raw Picture ?\n"); return NULL; } video_outbuf_size = video_width * video_height * 16; if (video_outbuf_size < FF_MIN_BUFFER_SIZE) video_outbuf_size = FF_MIN_BUFFER_SIZE; video_outbuf = (uint8_t *)av_malloc(video_outbuf_size); return st; }
void vidcap_set(int fd) { int ret; if (options[OptSetVideoFormat] || options[OptTryVideoFormat]) { struct v4l2_format vfmt; memset(&vfmt, 0, sizeof(vfmt)); vfmt.fmt.pix.priv = priv_magic; vfmt.type = vidcap_buftype; if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0) { if (is_multiplanar) { if (set_fmts & FmtWidth) vfmt.fmt.pix_mp.width = width; if (set_fmts & FmtHeight) vfmt.fmt.pix_mp.height = height; if (set_fmts & FmtPixelFormat) { vfmt.fmt.pix_mp.pixelformat = pixfmt; if (vfmt.fmt.pix_mp.pixelformat < 256) { vfmt.fmt.pix_mp.pixelformat = find_pixel_format(fd, vfmt.fmt.pix_mp.pixelformat, false, true); } } if (set_fmts & FmtField) vfmt.fmt.pix_mp.field = field; if (set_fmts & FmtFlags) vfmt.fmt.pix_mp.flags = flags; if (set_fmts & FmtBytesPerLine) { for (unsigned i = 0; i < VIDEO_MAX_PLANES; i++) vfmt.fmt.pix_mp.plane_fmt[i].bytesperline = bytesperline[i]; } else { /* G_FMT might return bytesperline values > width, * reset them to 0 to force the driver to update them * to the closest value for the new width. */ for (unsigned i = 0; i < vfmt.fmt.pix_mp.num_planes; i++) vfmt.fmt.pix_mp.plane_fmt[i].bytesperline = 0; } } else { if (set_fmts & FmtWidth) vfmt.fmt.pix.width = width; if (set_fmts & FmtHeight) vfmt.fmt.pix.height = height; if (set_fmts & FmtPixelFormat) { vfmt.fmt.pix.pixelformat = pixfmt; if (vfmt.fmt.pix.pixelformat < 256) { vfmt.fmt.pix.pixelformat = find_pixel_format(fd, vfmt.fmt.pix.pixelformat, false, false); } } if (set_fmts & FmtField) vfmt.fmt.pix.field = field; if (set_fmts & FmtFlags) vfmt.fmt.pix.flags = flags; if (set_fmts & FmtBytesPerLine) { vfmt.fmt.pix.bytesperline = bytesperline[0]; } else { /* G_FMT might return a bytesperline value > width, * reset this to 0 to force the driver to update it * to the closest value for the new width. */ vfmt.fmt.pix.bytesperline = 0; } } if (options[OptSetVideoFormat]) ret = doioctl(fd, VIDIOC_S_FMT, &vfmt); else ret = doioctl(fd, VIDIOC_TRY_FMT, &vfmt); if (ret == 0 && (verbose || options[OptTryVideoFormat])) printfmt(vfmt); } } }