Recherche avancée

Médias (2)

Mot : - Tags -/map

Autres articles (68)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

Sur d’autres sites (10985)

  • FFmpeg RTP example error

    20 juillet 2016, par Johnnylin

    Can anyone show me an example code of how to use FFmpeg to encode a ".mp4" video and then output to network stream using RTP(rtp ://127.0.0.1:6666). I have searched for it on google but most of them are just command line. Thanks very much.

    UPDATED :

               extern "C"{
               #include <libavcodec></libavcodec>avcodec.h>
               #include <libavformat></libavformat>avformat.h>
               #include <libswscale></libswscale>swscale.h>
               #include <libavutil></libavutil>avutil.h>
               #include <libavutil></libavutil>opt.h>
               #include <libavutil></libavutil>time.h>

               }
               #include
               #include <iostream>
               #include <string>
               using namespace std;

               // compatibility with newer API
               #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1)
               #define av_frame_alloc avcodec_alloc_frame
               #define av_frame_free avcodec_free_frame
               #endif
               #define RNDTO2(X) ( ( (X) &amp; 0xFFFFFFFE ))
               #define RNDTO32(X) ( ( (X) % 32 ) ? ( ( (X) + 32 ) &amp; 0xFFFFFFE0 ) : (X) )

               //avcodec_alloc_frame is an old name


               int main(int argc, char *argv[]) {
                   // Initalizing these to NULL prevents segfaults!
                   AVFormatContext   *pFormatCtx = NULL;
                   int               i, videoStream;
                   AVCodecContext    *pCodecCtxOrig = NULL;
                   AVCodecContext    *pCodecCtx = NULL;
                   AVCodec           *pCodec = NULL;
                   AVFrame           *pFrame = NULL;
                   AVPacket          packet;
                   int               frameFinished;
                   int               numBytes;
                   struct SwsContext *sws_ctx = NULL;
                   int frame_index=0;

                   if(argc &lt; 2) {
                   printf("Please provide a movie file\n");
                   return -1;
                   }

                   // Register all formats and codecs
                   av_register_all();

                   //initialize network video
                   avformat_network_init();


                   int errorStatus = 0;
                   char errorLog[128] = { 0 };
                   av_log_set_level(AV_LOG_TRACE);


                   //------------------ This is for local video file --------------
                   // Open video file
                   if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, NULL)!=0)
                   return -1; // Couldn't open file

                   // Retrieve stream information
                   if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)
                   return -1; // Couldn't find stream information

                   // Find the first video stream
                   videoStream=-1;
                   for(i=0; inb_streams; i++)
                   if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
                     videoStream=i;
                     break;
                   }

                   // Dump information about file onto standard error
                   av_dump_format(pFormatCtx, 0, argv[1], 0);


                   if(videoStream==-1)
                       return -1; // Didn't find a video stream

                   // Get a pointer to the codec context for the video stream
                   pCodecCtxOrig=pFormatCtx->streams[videoStream]->codec;
                   // Find the decoder for the video stream
                   pCodec=avcodec_find_decoder(pCodecCtxOrig->codec_id);
                   if(pCodec==NULL) {
                   fprintf(stderr, "Unsupported codec!\n");
                   return -1; // Codec not found
                   }

                   // Copy context
                   pCodecCtx = avcodec_alloc_context3(pCodec);
                   if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {
                   fprintf(stderr, "Couldn't copy codec context");
                   return -1; // Error copying codec context
                   }

                   // Open codec
                   if(avcodec_open2(pCodecCtx, pCodec, NULL)&lt;0)
                       return -1; // Could not open codec

                   // Allocate video frame
                   pFrame=av_frame_alloc();


                   // use nvidia codec
                   AVCodec* en_codec = avcodec_find_encoder_by_name("nvenc");
                   //AVCodec* en_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
                   AVCodecContext* nv_codec_context = avcodec_alloc_context3(en_codec);

                   nv_codec_context->bit_rate = 1244179;
                   nv_codec_context->width = 1920;                              
                   nv_codec_context->height = 1080;
                   nv_codec_context->time_base.num = 1;                                
                   nv_codec_context->time_base.den = 30;                              
                   nv_codec_context->gop_size = 10;                                    
                   nv_codec_context->max_b_frames = 1;                                  
                   nv_codec_context->keyint_min = 1;                                    
                   nv_codec_context->i_quant_factor = (float)0.71;                      
                   nv_codec_context->b_frame_strategy = 20;                            
                   nv_codec_context->qcompress = (float)0.6;                              
                   nv_codec_context->qmin = 20;                                      
                   nv_codec_context->qmax = 51;                                        
                   nv_codec_context->max_qdiff = 4;                                      
                   nv_codec_context->refs = 4;                                        
                   nv_codec_context->trellis = 1;                                        
                   nv_codec_context->pix_fmt = AV_PIX_FMT_YUV420P;                      
                   //nv_codec_context->codec_id = AV_CODEC_ID_H264;
                   //nv_codec_context->codec_type = AVMEDIA_TYPE_VIDEO;

                   if (avcodec_open2(nv_codec_context, en_codec,NULL) &lt; 0) {
                       fprintf(stderr, "Could not open codec\n");
                       exit(1);
                   }else printf("\nH264 codec opened\n");


                   /******stream*******/

                   string m_output("rtp://147.8.179.229:6666");
                   AVFormatContext* m_formatContext = NULL;
                   AVStream* m_stream = NULL;
                   if (avformat_alloc_output_context2(&amp;m_formatContext, NULL, "H264", m_output.c_str()) &lt; 0) {
                          cerr &lt;&lt; "Cannot allocate output context: "
                               &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                          return -1;
                   }

                   //AVCodec* tmp_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
                   m_stream = avformat_new_stream(m_formatContext, en_codec);
                     if (!m_stream) {
                         cerr &lt;&lt; "Cannot create a new stream: "
                            &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                       return -1;
                   }


                   av_dump_format(m_formatContext, 0, m_output.c_str(), 1);

                   m_stream->codec->pix_fmt = AV_PIX_FMT_YUV420P;
                   m_stream->codec->width = 1920;
                   m_stream->codec->height = 1080;
                   //m_stream->codec->codec_id = AV_CODEC_ID_H264;
                   m_stream->codec->bit_rate = 40000;
                   m_stream->codec->time_base.den = 30;
                   m_stream->codec->time_base.num = 1;
                   m_stream->time_base.den = 30;
                   m_stream->time_base.num = 1;

                   m_stream->codec->codec_tag = 0;
                   if (m_formatContext->oformat->flags &amp; AVFMT_GLOBALHEADER)
                       m_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;


                   if (!(m_formatContext->oformat->flags &amp; AVFMT_NOFILE))
                       errorStatus = avio_open(&amp;m_formatContext->pb, m_output.c_str(), AVIO_FLAG_WRITE);



                   if ((errorStatus) &lt; 0) {
                       cerr &lt;&lt; "Cannot open output: "
                            &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                       return -1;
                   }


                   if (avformat_write_header(m_formatContext, NULL) &lt; 0) {
                       cerr &lt;&lt; "Cannot write header to stream: "
                            &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                       return -1;
                   }


                   /******stream*******/

                   FILE *fp_yuv = NULL;
                   fp_yuv=fopen("output.yuv","wb+");

                   // Read frames and save first five frames to disk
                   i=0;

                   while(av_read_frame(pFormatCtx, &amp;packet)>=0) {
                   // Is this a packet from the video stream?
                       if(packet.stream_index==videoStream) {

                           // Decode video frame
                           avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);

                           // Did we get a video frame?
                           if(frameFinished) {

                               AVPacket Outpacket;
                               int got_packet_ptr;
                               av_init_packet(&amp;Outpacket);
                               Outpacket.data = NULL;
                               Outpacket.size = 0;
                               int out_size = avcodec_encode_video2(nv_codec_context, &amp;Outpacket, pFrame, &amp;got_packet_ptr);
                               Outpacket.pts = av_rescale_q(pFrame->pts, m_stream->codec->time_base, m_stream->time_base);

                               fwrite(Outpacket.data,1,Outpacket.size,fp_yuv);

                               //av_write_frame(m_formatContext, &amp;Outpacket);
                               av_interleaved_write_frame(m_formatContext, &amp;Outpacket);

                               //Free the packet that was allocated by encoder
                               av_packet_unref(&amp;Outpacket);
                     }
                   }

                   // Free the packet that was allocated by av_read_frame
                   av_packet_unref(&amp;packet);
                   }

                   fclose(fp_yuv);


                   // Free the YUV frame
                   av_frame_free(&amp;pFrame);

                   // Close the codecs
                   avcodec_close(pCodecCtx);
                   avcodec_close(pCodecCtxOrig);
                   avcodec_close(m_stream->codec);
                   avformat_free_context(m_formatContext);

                   // Close the video file
                   avformat_close_input(&amp;pFormatCtx);


                   return 0;
               }
    </string></iostream>

    Above is my code for decoding a .mp4 file, outputting to a network stream through RTP. But it does not work. On the client side, I call VLC library to decode the stream ( VlcMedia(url, _instance) where url is rtp/h264 ://@147.8.179.229:6666 ). When I change the protocal to UDP, it works. However, it is not stable. The frames jumps and probably the frame lost or something wrong with the pts setting ?

    UPDATED :

    When I use UDP, I got this error message.
    enter image description here

    When I use RTP, I got this error message :
    enter image description here

    Not sure about how to solve this problem, Can anyone help ? Thanks very much.

  • ffmpeg concatenation after using drawtext filter

    12 août 2016, par Sven Hoskens

    I’m fairly new to ffmpeg, but after a few days of searching on this issue, I’ve completely hit a brick wall. Any help would be appreciated.

    My use case : Our client wants to upload videos for multiple regions. Each video will be the same format, 1920x1080, mp4. For each region, they want to add a different image at the end of the video, for a few seconds. This image contains their logo, some additional info, and a variable code. They will enter this code alongside the uploaded video. The image stays the same, so is already present on the server.
    So basically, I have an input video, a video of an image, and a small code. I need to add this code to the video of the image (in a predefined position), and then I need to add the resulting video to the end of the input video. Once that is complete, I just need to output the video in 1920x1080 and in 1024x576.

    I have tried several things, but the concatenation step always fails with the manipulated video’s.

    Attempt 1

    In my first attempt, I used ffmpeg to create a video from an image, and add the text in the designated area.

    ffmpeg -y -f lavfi -i image.png -r 30 -t 10 -pix_fmt yuv420p -map 0:v -vf drawtext="fontfile=HelveticaNeue.dfont: text='GLNS/TEST/1234b': fontcolor=black: fontsize=20: box=1: boxcolor=white: boxborderw=7: x=179: y=805" imageVideo.mp4

    This command creates a .mp4 video of the correct size, with a duration of 10 seconds, and adds the text ’GLNS/TEST/1234b’ in the correct location.

    Next, I use the following command to concatenate the two videos. Both have the same resolution and codec.

    ffmpeg -f concat -safe 0 -i config.txt -vf scale=1920:1080 outputHD.mp4 -vf scale=1024:576 outputSD.mp4

    config.txt contains following :

    file my_input_file.mp4
    file ImageVideo.mp4

    This concatenation works with regular videos. However, when I use it with ImageVideo.mp4 (the one created by the first command) I get this error log :

    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f86dc924600] Auto-inserting h264_mp4toannexb bitstream filtereed=0.509x    
    [aac @ 0x7f86dc019e00] Number of bands (31) exceeds limit (5).
    Error while decoding stream #0:1: Invalid data found when processing input
    [aac @ 0x7f86dc019e00] Number of bands (27) exceeds limit (8).
    Error while decoding stream #0:1: Invalid data found when processing input
    [h264 @ 0x7f86dd857200] Error splitting the input into NAL units.
    [h264 @ 0x7f86dd829400] Invalid NAL unit size.
    [h264 @ 0x7f86dd829400] Error splitting the input into NAL units.
    [aac @ 0x7f86dc019e00] Number of bands (10) exceeds limit (1).
    Error while decoding stream #0:1: Invalid data found when processing input
    [h264 @ 0x7f86dd816800] Invalid NAL unit size.
    [h264 @ 0x7f86dd816800] Error splitting the input into NAL units.
    [aac @ 0x7f86dc019e00] Number of bands (24) exceeds limit (1).
    Error while decoding stream #0:1: Invalid data found when processing input

    #this goes on for a few hundred lines

    The resulting output is identical to the input video, but does not contain the desired image video at the end.

    Attempt 2

    Since the above attempt didn’t work, I tried concatenating a video I let our designer make of the image with Adobe After Effects. This video was also saved as a .mp4 with the H264 codec. If I concatenate the input video and this one, I get a correct result. However, as soon as I add the code in the designated area with this command :

    ffmpeg -i new_image_video.mp4 -vf drawtext="fontfile=HelveticaNeue.dfont: text='GLNS/TEST/1234b': fontcolor=black: fontsize=20: box=1: boxcolor=white: boxborderw=7: x=179: y=805" -c:v libx264 imageVideo.mp4

    I get this error :

    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ff94c800000] Auto-inserting h264_mp4toannexb bitstream filter97x    
    [h264 @ 0x7ff94b053800] top block unavailable for requested intra mode -1
    [h264 @ 0x7ff94b053800] error while decoding MB 0 0, bytestream 49526
    [h264 @ 0x7ff94b053e00] number of reference frames (1+3) exceeds max (3; probably corrupt input), discarding one
    [h264 @ 0x7ff94b053e00] chroma_log2_weight_denom 28 is out of range
    [h264 @ 0x7ff94b053e00] illegal long ref in memory management control operation 2
    [h264 @ 0x7ff94b053e00] cabac_init_idc 32 overflow
    [h264 @ 0x7ff94b053e00] decode_slice_header error
    [h264 @ 0x7ff94b053e00] no frame!
    [h264 @ 0x7ff94b053800] concealing 8160 DC, 8160 AC, 8160 MV errors in I frame
    [h264 @ 0x7ff94b072a00] reference overflow 22 > 15 or 0 > 15
    [h264 @ 0x7ff94b072a00] decode_slice_header error
    [h264 @ 0x7ff94b072a00] no frame!
    [h264 @ 0x7ff94b01a400] illegal modification_of_pic_nums_idc 20
    [h264 @ 0x7ff94b01a400] decode_slice_header error
    [h264 @ 0x7ff94b01a400] no frame!
    [h264 @ 0x7ff94b01aa00] illegal modification_of_pic_nums_idc 20
    [h264 @ 0x7ff94b01aa00] decode_slice_header error
    [h264 @ 0x7ff94b01aa00] no frame!
    Error while decoding stream #0:0: Invalid data found when processing input
    [h264 @ 0x7ff94b053800] deblocking_filter_idc 8 out of range
    [h264 @ 0x7ff94b053800] decode_slice_header error
    [h264 @ 0x7ff94b053800] no frame!
    Error while decoding stream #0:0: Invalid data found when processing input
    [h264 @ 0x7ff94b053e00] illegal memory management control operation 8
    [h264 @ 0x7ff94b053e00] co located POCs unavailable
    [h264 @ 0x7ff94b053e00] error while decoding MB 2 0, bytestream -35
    [h264 @ 0x7ff94b053e00] concealing 8160 DC, 8160 AC, 8160 MV errors in B frame
    [h264 @ 0x7ff94b072a00] number of reference frames (1+3) exceeds max (3; probably corrupt input), discarding one

    # this goes on for a while...

    [h264 @ 0x7ff94b01a400] concealing 4962 DC, 4962 AC, 4962 MV errors in B frame
    Error while decoding stream #0:0: Invalid data found when processing input
    frame= 2553 fps= 17 q=-1.0 Lsize=   26995kB time=00:01:42.16 bitrate=2164.6kbits/s dup=0 drop=60 speed=0.697x    
    video:25258kB audio:1661kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.285236%
    [libx264 @ 0x7ff94b810400] frame I:35    Avg QP:17.45  size: 55070
    [libx264 @ 0x7ff94b810400] frame P:711   Avg QP:19.73  size: 18712
    [libx264 @ 0x7ff94b810400] frame B:1807  Avg QP:21.53  size:  5884
    [libx264 @ 0x7ff94b810400] consecutive B-frames:  3.4%  5.0%  4.9% 86.6%
    [libx264 @ 0x7ff94b810400] mb I  I16..4: 38.2% 49.3% 12.5%
    [libx264 @ 0x7ff94b810400] mb P  I16..4: 12.4% 14.0%  1.0%  P16..4: 29.6%  4.8%  1.9%  0.0%  0.0%    skip:36.2%
    [libx264 @ 0x7ff94b810400] mb B  I16..4:  1.5%  1.2%  0.1%  B16..8: 27.3%  1.6%  0.1%  direct: 1.8%  skip:66.4%  L0:45.8% L1:51.4% BI: 2.8%
    [libx264 @ 0x7ff94b810400] 8x8 transform intra:49.5% inter:85.4%
    [libx264 @ 0x7ff94b810400] coded y,uvDC,uvAC intra: 21.2% 22.3% 2.5% inter: 4.6% 7.0% 0.0%
    [libx264 @ 0x7ff94b810400] i16 v,h,dc,p: 23% 26% 10% 41%
    [libx264 @ 0x7ff94b810400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 19% 35%  3%  3%  3%  3%  3%  2%
    [libx264 @ 0x7ff94b810400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 20% 16%  5%  7%  6%  5%  5%  4%
    [libx264 @ 0x7ff94b810400] i8c dc,h,v,p: 67% 16% 15%  2%
    [libx264 @ 0x7ff94b810400] Weighted P-Frames: Y:7.3% UV:4.2%
    [libx264 @ 0x7ff94b810400] ref P L0: 66.3%  8.7% 17.9%  7.0%  0.1%
    [libx264 @ 0x7ff94b810400] ref B L0: 88.2% 10.1%  1.7%
    [libx264 @ 0x7ff94b810400] ref B L1: 94.9%  5.1%
    [libx264 @ 0x7ff94b810400] kb/s:2026.12
    [aac @ 0x7ff94b072400] Qavg: 635.626

    The resulting output is identical to the input video, but does not contain the desired image video at the end.

    One thing I have noticed : When I inspect the video files on mac (Get info) they always contain these lines at ’More info’ :

    Dimensions: 1920 x 1080
    Codecs: H.264, AAC
    Color profile: HD(1-1-1)
    Duration: 01:42
    Audio channels: 2
    Last opened: Today 11:02

    However, the video’s which pass through the drawtext filter have this :

    Dimensions: 1920 x 1080
    Codecs: AAC, H.264
    Duration: 00:10
    Audio channels: 2
    Last opened: Today 11:07

    As you can see, there is no color profile entry, and the codecs have switched places. I assume this is related to my issue, but I can’t seem to find a fix for it.

    PS : The application will run in a php environment (Symfony). I noticed the concat command wasn’t available in the Symfony bundle for ffmpeg, so I’m using the regular terminal commands. I’ll execute these using php.

    EDIT
    Attempt 3

    On advise of a coworker, I tried converting the video to .avi and reconverting to .mp4, in the hopes this would lose any corrupted or extra info included by the drawtext filter. This spits out a completely different error.

    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f812413da00] Auto-inserting h264_mp4toannexb bitstream filtereed=0.516x    
    [concat @ 0x7f8124009a00] DTS 1569260 &lt; 2551000 out of order
    [h264 @ 0x7f8124846800] left block unavailable for requested intra4x4 mode -1
    [h264 @ 0x7f8124846800] error while decoding MB 0 0, bytestream 47919
    [h264 @ 0x7f8124846800] concealing 8160 DC, 8160 AC, 8160 MV errors in I frame
    [aac @ 0x7f8125809a00] Queue input is backward in time
    [aac @ 0x7f8125815a00] Queue input is backward in time
    [h264 @ 0x7f8124846e00] number of reference frames (1+3) exceeds max (3; probably corrupt input), discarding one
    [h264 @ 0x7f8124846e00] chroma_log2_weight_denom 26 is out of range
    [h264 @ 0x7f8124846e00] deblocking_filter_idc 32 out of range
    [h264 @ 0x7f8124846e00] decode_slice_header error
    [h264 @ 0x7f8124846e00] no frame!
    [mp4 @ 0x7f8124802200] Non-monotonous DTS in output stream 0:1; previous: 4902912, current: 4505491; changing to 4902913. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x7f8125813000] Non-monotonous DTS in output stream 1:1; previous: 4902912, current: 4505491; changing to 4902913. This may result in incorrect timestamps in the output file.
    [h264 @ 0x7f8124803400] reference overflow 20 > 15 or 0 > 15
    [h264 @ 0x7f8124803400] decode_slice_header error
    [h264 @ 0x7f8124803400] no frame!
    [mp4 @ 0x7f8124802200] Non-monotonous DTS in output stream 0:1; previous: 4902913, current: 4506515; changing to 4902914. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x7f8125813000] Non-monotonous DTS in output stream 1:1; previous: 4902913, current: 4506515; changing to 4902914. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x7f8124802200] Non-monotonous DTS in output stream 0:1; previous: 4902914, current: 4507539; changing to 4902915. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x7f8125813000] Non-monotonous DTS in output stream 1:1; previous: 4902914, current: 4507539; changing to 4902915. This may result in incorrect timestamps in the output file.

    # Again, this continues for quite a while.
  • App review video ( App Store )

    23 août 2016, par Arnold Mapps

    I want to convert a video recorded with Quick Time ( resolution 750*1334 ) to 1080*1920.
    Apple only accept resolution 1080*1920p for iphone6PLUS for App review video.

    My license key with final cut pro X has expired and
    ffmpeg -i AppPreviewIphone6.mp4 -vf scale=1080:1920 AppPreviewIphone6PLUS.mp4 give me a resolution of 1079*1920 instead 1080*1920

    Have you an idea what software I can use to change video resolution ?