
Recherche avancée
Médias (1)
-
MediaSPIP Simple : futur thème graphique par défaut ?
26 septembre 2013, par
Mis à jour : Octobre 2013
Langue : français
Type : Video
Autres articles (47)
-
Librairies et logiciels spécifiques aux médias
10 décembre 2010, parPour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...) -
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
MediaSPIP v0.2
21 juin 2013, parMediaSPIP 0.2 is the first MediaSPIP stable release.
Its official release date is June 21, 2013 and is announced here.
The zip file provided here only contains the sources of MediaSPIP in its standalone version.
To get a working installation, you must manually install all-software dependencies on the server.
If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)
Sur d’autres sites (8350)
-
Saving multiple public domain livestreams to disk using ffmpeg/vlc some other resource ?
20 mars 2021, par SantinoI am trying to save a few days' worths of video from open webcams to disk, so I can run some analytics on them. (for example this video of an airport. I have a few hundred of these, plus bandwidth & storage aren't an issue, how would I go about saving the streams for say 2-3 days ?


- 

- I have tried to write a small bit of python code using
pyav
(wrapper around ffmpeg) to open the stream and save keyframes. But it seems the connection gets dropped after an hour or so... - I have looked into
ffmpeg -i <some video="video" url="url"> output.mp4</some>
but it exits abruptly without any error message. - I am able to play the videos in vlc, but not sure how I can proceed with saving the videos.








Any ideas ?


- I have tried to write a small bit of python code using
-
FFMPEG using AV_PIX_FMT_D3D11 gives "Error registering the input resource" from NVENC
13 novembre 2024, par nbabcockInput frames start on the GPU as
ID3D11Texture2D
pointers.

I encode them to H264 using FFMPEG + NVENC. NVENC works perfectly if I download the textures to CPU memory as format
AV_PIX_FMT_BGR0
, but I'd like to cut out the CPU texture download entirely, and pass the GPU memory pointer directly into the encoder in native format. I write frames like this :

int write_gpu_video_frame(ID3D11Texture2D* gpuTex, AVFormatContext* oc, OutputStream* ost) {
 AVFrame *hw_frame = ost->hw_frame;

 printf("gpuTex address = 0x%x\n", &gpuTex);

 hw_frame->data[0] = (uint8_t *) gpuTex;
 hw_frame->data[1] = (uint8_t *) (intptr_t) 0;
 hw_frame->pts = ost->next_pts++;

 return write_frame(oc, ost->enc, ost->st, hw_frame);
 // write_frame is identical to sample code in ffmpeg repo
}



Running the code with this modification gives the following error :


gpuTex address = 0x4582f6d0
[h264_nvenc @ 00000191233e1bc0] Error registering an input resource: invalid call (9):
[h264_nvenc @ 00000191233e1bc0] Could not register an input HW frame
Error sending a frame to the encoder: Unknown error occurred




Here's some supplemental code used in setting up and configuring the hw context and encoder :


/* A few config flags */
#define ENABLE_NVENC TRUE
#define USE_D3D11 TRUE // Skip downloading textures to CPU memory and send it straight to NVENC



/* Init hardware frame context */
static int set_hwframe_ctx(AVCodecContext* ctx, AVBufferRef* hw_device_ctx) {
 AVBufferRef* hw_frames_ref;
 AVHWFramesContext* frames_ctx = NULL;
 int err = 0;

 if (!(hw_frames_ref = av_hwframe_ctx_alloc(hw_device_ctx))) {
 fprintf(stderr, "Failed to create HW frame context.\n");
 throw;
 }
 frames_ctx = (AVHWFramesContext*) (hw_frames_ref->data);
 frames_ctx->format = AV_PIX_FMT_D3D11;
 frames_ctx->sw_format = AV_PIX_FMT_NV12;
 frames_ctx->width = STREAM_WIDTH;
 frames_ctx->height = STREAM_HEIGHT;
 //frames_ctx->initial_pool_size = 20;
 if ((err = av_hwframe_ctx_init(hw_frames_ref)) < 0) {
 fprintf(stderr, "Failed to initialize hw frame context. Error code: %s\n", av_err2str(err));
 av_buffer_unref(&hw_frames_ref);
 throw;
 }
 ctx->hw_frames_ctx = av_buffer_ref(hw_frames_ref);
 if (!ctx->hw_frames_ctx)
 err = AVERROR(ENOMEM);

 av_buffer_unref(&hw_frames_ref);
 return err;
}



/* Add an output stream. */
static void add_video_stream(
 OutputStream* ost,
 AVFormatContext* oc,
 const AVCodec** codec,
 enum AVCodecID codec_id,
 int width,
 int height
) {
 AVCodecContext* c;
 int i;
 bool nvenc = false;

 /* find the encoder */
 if (ENABLE_NVENC) {
 printf("Getting nvenc encoder\n");
 *codec = avcodec_find_encoder_by_name("h264_nvenc");
 nvenc = true;
 }
 
 if (!ENABLE_NVENC || *codec == NULL) {
 printf("Getting standard encoder\n");
 avcodec_find_encoder(codec_id);
 nvenc = false;
 }
 if (!(*codec)) {
 fprintf(stderr, "Could not find encoder for '%s'\n",
 avcodec_get_name(codec_id));
 exit(1);
 }

 ost->st = avformat_new_stream(oc, NULL);
 if (!ost->st) {
 fprintf(stderr, "Could not allocate stream\n");
 exit(1);
 }
 ost->st->id = oc->nb_streams - 1;
 c = avcodec_alloc_context3(*codec);
 if (!c) {
 fprintf(stderr, "Could not alloc an encoding context\n");
 exit(1);
 }
 ost->enc = c;

 printf("Using video codec %s\n", avcodec_get_name(codec_id));

 c->codec_id = codec_id;
 c->bit_rate = 4000000;
 /* Resolution must be a multiple of two. */
 c->width = STREAM_WIDTH;
 c->height = STREAM_HEIGHT;
 /* timebase: 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
 * identical to 1. */
 ost->st->time_base = {1, STREAM_FRAME_RATE};
 c->time_base = ost->st->time_base;
 c->gop_size = 12; /* emit one intra frame every twelve frames at most */

 if (nvenc && USE_D3D11) {
 const std::string hw_device_name = "d3d11va";
 AVHWDeviceType device_type = av_hwdevice_find_type_by_name(hw_device_name.c_str());

 // set up hw device context
 AVBufferRef *hw_device_ctx;
 // const char* device = "0"; // Default GPU (may be integrated in the case of switchable graphics!)
 const char* device = "1";
 ret = av_hwdevice_ctx_create(&hw_device_ctx, device_type, device, nullptr, 0);

 if (ret < 0) {
 fprintf(stderr, "Could not create hwdevice context; %s", av_err2str(ret));
 }

 set_hwframe_ctx(c, hw_device_ctx);
 c->pix_fmt = AV_PIX_FMT_D3D11;
 } else if (nvenc && !USE_D3D11)
 c->pix_fmt = AV_PIX_FMT_BGR0;
 else
 c->pix_fmt = STREAM_PIX_FMT;

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

 if (c->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. */
 c->mb_decision = 2;
 }

 /* Some formats want stream headers to be separate. */
 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
 c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}



-
cuda invalid resource handle when using h264_cuvid decoder in my C program [closed]
29 juillet 2021, par ChrisFisherI try to use GPU acceleration in my ffmpeg decode program, and I check the codecs of ffmpeg by command :
ffmpeg -codecs | grep nv
, and it shows that I can use h264_cuvid decoder(In fact, I have already used ffmpeg command line to encode and decode a test video with hardware acceleration and it turned out everything was all fine), but when I use the decoder in my program

AVCodec *pCodec = avcodec_find_decoder_by_name("h264_cuvid");


here is part of my program


void FFMPEGCodec::initDecoder()
{
 AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
 if (!pCodec) {
 LOG("Codec decoder not found\n");
 exit(1);
 }

 pCodecCtx = avcodec_alloc_context3(pCodec);
 if (!pCodecCtx) {
 LOG("Could not allocate video codec context\n");
 exit(1);
 }

 pCodecCtx->width = gConfig->totalWidth;
 pCodecCtx->height = gConfig->totalHeight;
 pCodecCtx->has_b_frames = 0;

 if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
 LOG("Could not open codec\n");
 exit(1);
 }

 if(_x264rgb){
 //used to convert GBRP frame to RGB image.
 convertCtx = sws_getContext(gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_GBRP, 
 gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL); 
 } else {
 //used to convert YUV frame to RGB image.
 convertCtx = sws_getContext(gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_YUV420P, 
 gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL); 
 }

 if(convertCtx == NULL){
 LOG("Failed to get SwsContext\n");
 exit(1);
 }

 //when using x264rgb, it's actually GBRP frame, 
 //just don't want to define another variable
 yuvFrame = av_frame_alloc();
 if (!yuvFrame) {
 LOG("Failed to allocate yuv frame\n");
 exit(1);
 }

 rgbFrame = av_frame_alloc();
 if (!rgbFrame) {
 LOG("Failed to allocate rgb frame\n");
 exit(1);
 }

 rgbFrame->format = AV_PIX_FMT_RGB24;
 rgbFrame->width = pCodecCtx->width;
 rgbFrame->height = pCodecCtx->height;
 
 int ret = av_image_alloc(rgbFrame->data, rgbFrame->linesize, rgbFrame->width, rgbFrame->height,
 AV_PIX_FMT_RGB24, 32);
 if (ret < 0) {
 LOG("Failed to allocate raw picture buffer\n");
 exit(1);
 }
} 



and


int FFMPEGCodec::decode(byte* pktData, int pktSize, byte* imgData)
{
 int ret = 0, got_packet = 0;
 AVPacket pkt;
 av_init_packet(&pkt);
 pkt.data = pktData;
 pkt.size = pktSize;

 // decode video frame
 ret = avcodec_decode_video2(pCodecCtx, yuvFrame, &got_packet, &pkt);
 if (ret < 0) {
 LOG("Error decoding frame\n");
 return -1;
 }

 sws_scale(convertCtx, yuvFrame->data, yuvFrame->linesize, 0, pCodecCtx->height, rgbFrame->data, rgbFrame->linesize);
 
 if (got_packet) {
 int width = pCodecCtx->width, height = pCodecCtx->height;
 int fsize = rgbFrame->linesize[0] * rgbFrame->height;
 int size = 54 + fsize;

 byte bmp_file_header[14] = { 'B', 'M', 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, };
 byte bmp_info_header[40] = { 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0, };
 byte bmp_pad[3] = { 0, 0, 0 };

 bmp_file_header[2] = (unsigned char)size;
 bmp_file_header[3] = (unsigned char)(size >> 8);
 bmp_file_header[4] = (unsigned char)(size >> 16);
 bmp_file_header[5] = (unsigned char)(size >> 24);

 bmp_info_header[4] = (unsigned char)(width);
 bmp_info_header[5] = (unsigned char)(width >> 8);
 bmp_info_header[6] = (unsigned char)(width >> 16);
 bmp_info_header[7] = (unsigned char)(width >> 24);
 bmp_info_header[8] = (unsigned char)(height);
 bmp_info_header[9] = (unsigned char)(height >> 8);
 bmp_info_header[10] = (unsigned char)(height >> 16);
 bmp_info_header[11] = (unsigned char)(height >> 24);

 memcpy(imgData, bmp_file_header, 14);
 memcpy(imgData + 14, bmp_info_header, 40);
 memcpy(imgData + 54, rgbFrame->data[0], fsize);
 ret = size;
 }
 av_free_packet(&pkt);

 return ret;
}




after compiling, I ran the program, and the decoder throw me a error :


ctx->cvdl->cuvidDecodePicture(ctx->cudecoder, picparams) failed -> CUDA_ERROR_INVALID_HANDLE: invalid resource handle

when calling the functionavcodec_decode_video2


I don't know why this error occurred, by the way, I use a GTX1060 6G(Sorry I'm not a native English speaker)