Recherche avancée

Médias (3)

Mot : - Tags -/plugin

Autres articles (111)

  • Script d’installation automatique de MediaSPIP

    25 avril 2011, par

    Afin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
    Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
    La documentation de l’utilisation du script d’installation (...)

  • Keeping control of your media in your hands

    13 avril 2011, par

    The vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
    While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
    MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
    MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...)

  • Activation de l’inscription des visiteurs

    12 avril 2011, par

    Il est également possible d’activer l’inscription des visiteurs ce qui permettra à tout un chacun d’ouvrir soit même un compte sur le canal en question dans le cadre de projets ouverts par exemple.
    Pour ce faire, il suffit d’aller dans l’espace de configuration du site en choisissant le sous menus "Gestion des utilisateurs". Le premier formulaire visible correspond à cette fonctionnalité.
    Par défaut, MediaSPIP a créé lors de son initialisation un élément de menu dans le menu du haut de la page menant (...)

Sur d’autres sites (9797)

  • cuda invalid resource handle when using h264_cuvid decoder to decode video in my C program

    29 juillet 2021, par ChrisFisher

    I 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 function avcodec_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)

    


  • cuda invalid resource handle when using h264_cuvid decoder in my C program [closed]

    29 juillet 2021, par ChrisFisher

    I 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 function avcodec_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)

    


  • HLS encoded video (ffmpeg) breaks in Safari when segmented via byte-range

    15 juin 2019, par eschie

    Some of my HLS encoded videos via ffmpeg drop the audio when seeking past the buffer. The only way to sync the audio and video up again is to restart the video. What would be causing this ?

    Example Profile :

    bitrate: 4800, profile: 'high', level: '4.1', resolution: 1080, framerate: '24000/1001'
    ffmpeg
       '-y'
       '-i' input_file.mov                                                
       '-v' error
       '-map' '0:0'                                                        
       '-c:v' libx264                                                  
       '-x264opts' f'
           keyint=23:                  
           min-keyint=23:          
           no-scenecut                                                    
       '
       '-vf' f'scale=-1:1080'
       '-preset' 'slow'
       '-profile:v' 'high'
       '-level' '4.1'
       '-b:v' '4800k'
       '-maxrate' '4800k'
       '-movflags' 'faststart'
       '-bufsize' '9600k'
       '-write_tmcd', '0'
       '-r' '24000/1001'                                  
       output_dir                                                      

    Segmentation CMD :

    FFMPEG
       '-i' output_dir
       '-v' 'error'
       '-acodec' 'copy'
       '-vcodec' 'copy'
       '-hls_time' '4' #seconds
       '-hls_list_size' '0'
       '-hls_flags' 'single_file'
       os.path.join(output_dir, f'{run_id}_{bitrate}.m3u8'

    Added : apple’s mediastreamvalidator outputs a few different errors :

    Error: Playlist vs segment duration mismatch
    --> Detail:  Segment duration 98.0146, Playlist duration: 4.7968
    --> Source:  1559962503399_2200k.m3u8 - 1559962503399_2200k.ts:1746520@0
    Error: Measured peak bitrate compared to master playlist declared value exceeds error tolerance
    --> Detail:  Measured: 3182.61 kb/s, Master playlist: 2173.82 kb/s, Error: 46.41%, Combined rendition name: English
    --> Source:  ...playlist.m3u8
    --> Compare: 1559962503399_2200k.m3u8
    Error: Different target durations detected
    --> Detail:  Target duration: 5 vs Target duration: 4
    --> Source:  1559962503399_64k.m3u8
    --> Compare: 1559962503399_128k.m3u8

    UPDATE 1 :
    I modified the encoding command to utilize tee pseudo-muxer, but it seems the same issue still exists when segmenting HLS as byte-ranges rather than in separate .ts files :

    $ ffmpeg
    -hide_banner
    -report
    -benchmark
    -vstats
    -i "../Jane_shallowing_Top_v08.mp4"
    -dn
    -sn
    -filter_complex "[0:v]fps=fps=24.000,setpts=(PTS-STARTPTS),split=[vsplit1][vsplit2];[vsplit1]scale=-1:144[video_144];[vsplit2]scale=-1:1080[video_1080]"
    -map "[video_144]"
    -r:v:0 "24.000"
    -c:v:0 "libx264"
    -x264-params "keyint=144:min-keyint=144:scenecut=0:open_gop=0"
    -preset:v:0 "slow"
    -profile:v:0 "baseline"
    -refs:v:0 "2"
    -b-pyramid:v:0 "strict"
    -tune:v:0 "film"
    -b:v:0 "96000"
    -maxrate:v:0 "56000"
    -bufsize:v:0 "6*56000/8"
    -vsync:v:0 "cfr"
    -bsf:v:0 "h264_metadata=fixed_frame_rate_flag=1"
    -map "[video_1080]"
    -r:v:1 "24.000"
    -c:v:1 "libx264"
    -x264-params "keyint=144:min-keyint=144:scenecut=0:open_gop=0"
    -preset:v:1 "slow"
    -profile:v:1 "high"
    -refs:v:1 "2"
    -b-pyramid:v:1 "strict"
    -tune:v:1 "film"
    -b:v:1 "4800000"
    -maxrate:v:1 "4800000"
    -bufsize:v:1 "6*4800000/8"
    -vsync:v:1 "cfr"
    -bsf:v:1 "h264_metadata=fixed_frame_rate_flag=1"
    -map a:0 -map a:0
    -c:a "libfdk_aac"
    -ar "48000"
    -ab "128k"
    -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0"
    -f "hls"
    -var_stream_map "v:1,a:0 v:0,a:1"
    -hls_time "6.000"
    -hls_segment_type "mpegts"
    -hls_flags "discont_start+temp_file+single_file"
    -hls_list_size "0"
    -master_pl_name "playlist.m3u8"
    -hls_segment_filename "out_%v.ts" "out_%v.m3u8"
    Segment duration 98.0267, Playlist duration: 6.0000