static av_cold int raw_init_encoder(AVCodecContext *avctx) { avctx->coded_frame = (AVFrame *)avctx->priv_data; avctx->coded_frame->pict_type = FF_I_TYPE; avctx->coded_frame->key_frame = 1; if(!avctx->codec_tag) avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; }
static av_cold int raw_init_encoder(AVCodecContext *avctx) { avctx->coded_frame = (AVFrame *)avctx->priv_data; avctx->coded_frame->pict_type = FF_I_TYPE; avctx->coded_frame->key_frame = 1; avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]); if(!avctx->codec_tag) avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; }
static av_cold int raw_init_encoder(AVCodecContext *avctx) { avctx->coded_frame = avctx->priv_data; avcodec_get_frame_defaults(avctx->coded_frame); avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]); if(!avctx->codec_tag) avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; }
static av_cold int raw_encode_init(AVCodecContext *avctx) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); avctx->coded_frame = av_frame_alloc(); avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc); if(!avctx->codec_tag) avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; }
static AVStream *add_video_stream(AVFormatContext *oc, enum AVCodecID codec_id) { AVCodecContext *c; AVCodec *codec; AVStream *st; st = avformat_new_stream(oc, NULL); if (!st) { fprintf(stderr, "Could not alloc stream\n"); exit(1); } c = st->codec; c->codec_id = codec_id; c->codec_type = AVMEDIA_TYPE_VIDEO; /* put sample parameters */ // c->bit_rate = 400000; /* resolution must be a multiple of two */ c->width = displayMode->GetWidth(); c->height = displayMode->GetHeight(); /* time base: this is the fundamental unit of time (in seconds) in terms * of which frame timestamps are represented. for fixed-fps content, * timebase should be 1/framerate and timestamp increments should be * identically 1.*/ displayMode->GetFrameRate(&frameRateDuration, &frameRateScale); c->time_base.den = frameRateScale; c->time_base.num = frameRateDuration; c->pix_fmt = pix_fmt; if (codec_id == AV_CODEC_ID_V210 || codec_id == AV_CODEC_ID_R210) c->bits_per_raw_sample = 10; if (codec_id == AV_CODEC_ID_RAWVIDEO) c->codec_tag = avcodec_pix_fmt_to_codec_tag(c->pix_fmt); // some formats want stream headers to be separate if (oc->oformat->flags & AVFMT_GLOBALHEADER) { c->flags |= CODEC_FLAG_GLOBAL_HEADER; } /* find the video encoder */ //codec = avcodec_find_encoder(c->codec_id); //if (!codec) { // fprintf(stderr, "codec not found\n"); // exit(1); //} /* open the codec */ // if (avcodec_open2(c, codec, NULL) < 0) { // fprintf(stderr, "could not open codec\n"); // exit(1); //} return st; }
enum PixelFormat avcodec_codec_tag_to_pix_fmt (unsigned int codec_tag) { enum PixelFormat fmt; gint i; for (i = 0; i < PIX_FMT_NB; i++) { if (codec_tag == avcodec_pix_fmt_to_codec_tag (i)) { return i; } } return PIX_FMT_NONE; }
static av_cold int raw_encode_init(AVCodecContext *avctx) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; FF_ENABLE_DEPRECATION_WARNINGS #endif avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc); if(!avctx->codec_tag) avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; }
static void player_av_load (Player *self, Entry *entry) { gint i; PlayerAVPrivate *priv = PLAYER_AV (self)->priv; player_av_close (self); if (av_open_input_file (&priv->fctx, entry_get_location (entry), NULL, 0, NULL) != 0) return; if (av_find_stream_info (priv->fctx) < 0) return; priv->fctx->flags = AVFMT_FLAG_GENPTS; dump_format(priv->fctx, 0, entry_get_location (entry), 0); priv->astream = priv->vstream = -1; for (i = 0; i < priv->fctx->nb_streams; i++) { if (priv->fctx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) { priv->vstream = i; } if (priv->fctx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) { priv->astream = i; } if (priv->vstream != -1 && priv->astream != -1) break; } // Setup Audio Stream if (priv->astream != -1) { priv->actx = priv->fctx->streams[priv->astream]->codec; AVCodec *acodec = avcodec_find_decoder (priv->actx->codec_id); if (acodec && avcodec_open (priv->actx, acodec) < 0) { g_print ("Error opening audio stream\n"); return; } } else { priv->actx = NULL; } // Setup Video Stream if (priv->vstream != -1) { priv->vctx = priv->fctx->streams[priv->vstream]->codec; AVCodec *vcodec = avcodec_find_decoder (priv->vctx->codec_id); if(vcodec && avcodec_open (priv->vctx, vcodec) < 0) { g_print ("Error opening video stream\n"); return; } } else { priv->vctx = NULL; } if (priv->vctx) { priv->vctx->get_buffer = player_av_av_get_buffer; priv->vctx->release_buffer = player_av_av_release_buffer; priv->display = gdk_x11_display_get_xdisplay (gdk_display_get_default ()); priv->root = DefaultRootWindow (priv->display); priv->win = GDK_WINDOW_XID (priv->em_da->window); XSetWindowBackgroundPixmap (priv->display, priv->win, None); int nb_adaptors; XvAdaptorInfo *adaptors; XvQueryAdaptors (priv->display, priv->root, &nb_adaptors, &adaptors); int adaptor_no = 0, j, res; priv->xv_port_id = 0; for (i = 0; i < nb_adaptors && !priv->xv_port_id; i++) { adaptor_no = i; for (j = 0; j < adaptors[adaptor_no].num_ports && !priv->xv_port_id; j++) { res = XvGrabPort (priv->display, adaptors[adaptor_no].base_id + j, 0); if (Success == res) { priv->xv_port_id = adaptors[adaptor_no].base_id + j; } } } XvFreeAdaptorInfo (adaptors); int nb_formats; XvImageFormatValues *formats = XvListImageFormats (priv->display, priv->xv_port_id, &nb_formats); unsigned int vfmt = avcodec_pix_fmt_to_codec_tag (priv->vctx->pix_fmt); for (i = 0; i < nb_formats; i++) { if (vfmt == formats[i].id) { break; } } enum PixelFormat ofmt = PIX_FMT_NONE; priv->vframe = avcodec_alloc_frame (); priv->vframe_xv = avcodec_alloc_frame(); if (i < nb_formats) { ofmt = priv->vctx->pix_fmt; } else { for (i = 0; i < nb_formats; i++) { ofmt = avcodec_codec_tag_to_pix_fmt (formats[i].id); if (ofmt != PIX_FMT_NONE) { break; } } } int num_bytes = avpicture_get_size (ofmt, priv->vctx->width + priv->vctx->width % 4, priv->vctx->height); priv->vbuffer_xv = (uint8_t*) av_malloc (num_bytes * sizeof (uint8_t)); avpicture_fill ((AVPicture*) priv->vframe_xv, priv->vbuffer_xv, ofmt, priv->vctx->width + priv->vctx->width % 4, priv->vctx->height); priv->sws_ctx = sws_getContext ( priv->vctx->width, priv->vctx->height, priv->vctx->pix_fmt, priv->vctx->width, priv->vctx->height, ofmt, SWS_POINT, NULL, NULL, NULL); priv->xvimage = XvCreateImage ( priv->display, priv->xv_port_id, formats[i].id, priv->vbuffer_xv, priv->vctx->width, priv->vctx->height); XFree (formats); priv->xv_gc = XCreateGC (priv->display, priv->win, 0, &priv->values); } priv->entry = entry; g_object_ref (entry); priv->vpos = 0; priv->start_time = -1; priv->stop_time = -1; }