Recherche avancée

Médias (91)

Autres articles (68)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Mise à disposition des fichiers

    14 avril 2011, par

    Par défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
    Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
    Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

Sur d’autres sites (5160)

  • 9 Form Optimisation Tips to Convert More Visitors

    15 février 2024, par Erin

    Forms might seem boring — that is, until you realise how powerful they are.

    No forms mean no leads.

    No leads mean no sales.

    No sales means you’ll run out of business.

    So, what do you do ?

    Optimise forms to land more leads.

    They’re a critical part of the sales funnel.

    Forms have many different purposes and can be used to :

    • Contact a company
    • Sign up for a newsletter
    • Request a demo
    • Start a free trial
    • And more

    If you want to get more leads (and ultimately more sales), then you need to optimise your forms.

    This guide will show you exactly how to do that (so you can start getting more conversions today). 

    What is form optimisation ?

    Before we dive into form optimisation, let’s back up a bit.

    Form conversion is our primary focus.

    Your form conversion rate is the percentage of visitors who submit a form divided by the total number of visitors who started the form times one hundred.

    For example, if 5,000 people started filling out your form this month and 350 submitted the form, the conversion rate would be : 

    350 / 5,000 x 100 = 7%

    So, what’s form optimisation ?

    What is form optimisation?

    It’s simply improving your forms to increase conversion rates.

    For most people, form conversion is all about increasing leads.

    Before you begin optimising your forms, it’s important you understand what’s good (and what’s not good) when it comes to form conversions.

    The average form conversion rate across all industries is 2.9%.

    This means you should expect about 3 out of every 100 visitors who start your form to submit it.

    If your form conversion is lower — or hovering around this number — then it’s important to start optimising now.

    With Matomo, you can track your form conversions with Matomo Form Analytics. Gain powerful insights into how your visitors interact with your forms with our intuitive dashboard.

    Why it’s important to optimise your forms

    Most people hear the word “forms” and think it’s boring.

    But forms are the doorway to leads.

    If you want to generate more sales, then you need to generate great forms.

    Here are five reasons you need to optimise your forms today :

    1. Improve conversions

    Form optimisation is really just conversion optimisation.

    But, instead of optimising and improving your site to directly improve sales conversions, you’re increasing lead conversions.

    Every smart website owner uses forms to draw people in further.

    The reality is that most of your website visitors will never return to your site.

    This means you need to do everything you can to grab their contact information so you can continue marketing to them day in and day out.

    Otherwise, you’ll lose them forever.

    When you know how to optimise your forms, you’ll be able to get a higher percentage of form viewers to fill it out.

    Higher conversions mean you get more leads, more customers, and ultimately more revenue.

    2. Capture more leads

    When you can increase your form conversion rate from 1% to 2%, it may seem insignificant.

    What’s a measly percentage point in conversions ?

    It’s a lot.

    When you’re dealing with traffic in the tens or hundreds of thousands each month, an increase in conversion rate by a whole percentile is massive.

    Let’s say you take your conversion rate from 2% to 3% on your form, and you have 70,000 visitors view the form each month.

    Well, if 1,400 people used to sign up to your email list each month at a 2% conversion rate, then at a 3% conversion rate, you’d get 2,100 new email signups every month.

    That’s a major difference.

    When you can improve your signup forms, you improve your lead generation (which is conversion rate optimisation). And the more leads you have, the more sales you’ll make in the long run.

    3. Get the most out of your traffic

    If your forms don’t perform well, then you’re wasting your time (and your traffic).

    By analysing your form data, you can quickly see what’s working and what’s not so you can optimise and improve the user experience (and your forms).

    For most people, this means getting more form viewers to fill out the form with their email and name.

    If 50,000 people visit your site each month, but only 1% of them fill out your form, you’re only getting 500 email signups per month.

    Rather than paying money to generate more traffic, why not just work on improving your website by implementing a better form ?

    If you can increase your form conversion rate to 2%, you will immediately go from 500 new subscribers per month to 1,000 per month.

    4. Spend less on acquisition

    If you’re able to get more form signups without having to generate more traffic, you just solved a pricey problem : acquisition costs.

    If you can now get 1,000 of your 50,000 visitors to sign up to your email list through a better form, then you doubled your signups.

    But that’s not all. You just cut your acquisition costs in half.

    If you spend $2,000 per month on acquisition but you’re able to get twice as many leads, then your acquisition costs are at 50% of what they used to be.

    This means you can pay the same amount but get twice as many leads.

    Or, you can pour even more money into acquisition since it’s now twice as effective so you can fuel growth even more.

    5. Grow revenue

    Forms generate revenue. It may not be direct (although, in some cases, it is). 

    But, forms will lead to sales.

    By placing optimised forms throughout your website at the right places, you will be able to capture a percentage of your visitors as leads, which means you’ll eventually make more sales.

    13 tips to optimise your forms for more conversions

    Now that you know what forms can do and why they’re important to grow your business, it’s time to dive into the best practices.

    Follow these 13 tips to ensure you’re getting the most out of your forms :

    1. Set form goals

    Your forms are hopeless without a goal.

    Before you set up a form on your website, ask yourself, “What am I trying to accomplish with this form ?”

    It could be :

    • Encouraging customers to reach out through a contact form
    • To get visitors to leave feedback on your product/service
    • Convert visitors into leads by giving you their email

    No matter what your goal is, make sure you’re clear on it ; otherwise, you won’t be as targeted and specific with your forms.

    Matomo Goals helps you set specific objectives for your marketing campaigns so you’re able to easily track conversions. Whether you’re looking to capture feedback or generate leads, you can leverage Matomo to see what’s working and what’s not in seconds.

    2. Remove or improve fields with high average time spent and high drop-off rates

    Delving into your Form Analytics provides invaluable insights into individual field performance. A crucial metric to focus on is the Average Time Spent. 

    If a field stands out with a significantly higher average time spent and experiences a high drop-off rate compared to others in the form, it’s a clear indicator that it’s causing frustration or confusion for your visitors.

    To address this, consider improving the field by converting it into a dropdown menu for easier completion or providing helpful text prompts. Alternatively, if the field isn’t essential, you might opt to remove it altogether.

    When you cut down on time spent and drop-offs, you’ll see your conversion rates go up.

    Matomo's Form Analytics dashboard displaying field timings

    Here’s a standout example from Matomo’s Form Analytics feature : the “Overview of your needs” field is taking on average 1 minute and 37 seconds to complete. 

    To streamline this, we might want to consider a simple fix like converting it into a dropdown menu. This change would offer visitors a clearer and quicker way to select from options.

    Screenshot of drop-off fields report in Matomo's Form Analytics feature

    Likewise, we observe that the “Overview of your needs” field experiences the highest drop-off rate, totaling 1,732 drop-offs. 

    With Form Analytics, it becomes clear what is needed to optimise forms and increase conversions.

    Try Matomo for Free

    Get the web insights you need, without compromising data accuracy.

    No credit card required

    3. Start with the CTA

    When crafting and optimising your forms, you need to start with the end in mind. That’s why you need to start with your business goals.

    What are you trying to do with this form ? If you want to capture more emails, then make sure that’s very clear with the call to action (CTA).

    Start building your form by beginning with the CTA.

    For example : “Sign Up Now.”

    Once you have the action you want your potential customers to take, place it on the form. Then, you can work towards crafting the rest of the form.

    4. Put it above the fold

    If your visitors can’t find your form, they won’t fill it out. It’s plain and simple.

    You need to make sure your form is visible above the fold. This is the part of the screen that’s visible to your visitors once they land on your site (without needing to scroll down).

    Always remember to test this out on both desktop and mobile to ensure anyone (using laptops or a mobile device) will see your form upon landing on your site or page.

    Don’t forget about your mobile users. More people view mobile forms than desktop forms. 

    5. Put a CTA in the headline

    Your form needs to be clear.

    You have 1-3 seconds to communicate with your site visitors what your form is all about.

    For example, if you’re trying to get email signups with a lead magnet, then tell them the benefit quickly and concisely with a CTA in the headline, like this one :

    “Subscribe to Save 10% On Your Next Order”

    This is a great example of a headline-CTA combo that tells the visitor what to do and what they get out of it.

    Matomo’s behaviour analytics features like Session Recordings let you see where visitors are clicking and spending time. For example, if people are reading the headline, but not scrolling down to read the form, it’s probably a sign you need to test a different headline.

    6. Ensure you have the right fields

    Your form fields matter.

    What information are you trying to capture from your audience ?

    One beginner mistake people make is requiring too much information and including many fields in a form.

    You want to get as much data on your audience as possible, right ? Wrong.

    If you ask for too much information, people won’t fill it out, and it will harm the user experience. You need to make it super easy.

    If you want more emails to grow your list, then stick with someone’s email (and possibly their name as well). One line for a name. One line for an email address. Keep it simple.

    If you’re after SMS as well, don’t include it on the form. Instead, create a two-step form that pops up an SMS form after someone fills out the email form.

    Multi-step forms enable you to capture those emails easily (and still get a percentage to fill out the second form) without making it seem like too much work for your audience.

    Another path is to include optional fields (that users don’t have to fill out to click submit).

    Just keep in mind that shorter forms perform better than longer ones.

    If you make them too long, it feels like work for the user and will lead to lower completion rates.

    7. Always capture email address

    If you’re unsure of what information to capture (i.e. name, number, email, occupation, age, etc.), always stick to email.

    Email is used by over 4 billion people every single day, and it’s not going away anytime soon.

    When determining which fields to include, start with email.

    Capture more leads with quality forms.

    8. Test different buttons and copy

    You need to track your form performance if you want to get the best conversions.

    One of the best form elements to start testing is your button copy.

    In most cases, form completion buttons will have the word “submit” on them.

    But you don’t have to stick with this word.

    You can (and should) experiment with different submit button copy.

    Here are a few examples of replacement words for your action button :

    • Complete
    • Sign Up
    • Join now
    • Get started

    Remember to experiment with your action button. Try a different copy. Just keep it short.

    You can also try A/B testing your form by experimenting with different colours, copy, and more.

    Matomo's A/B testing dashboard displaying results of CTA experiment

    In the example above from Matomo’s A/B testing feature, we found that changing the wording of our call to action made a big difference. The new “Apply Now” button performed much better, with a 3.6% conversion rate compared to just 1.7% for the original one.

    Try Matomo for Free

    Get the web insights you need, without compromising data accuracy.

    No credit card required

    9. Test static vs. popup

    There are various types of online forms.

    The most common is the static form that just sits in one place and is always there.

    Another popular form type is the popup.

    This is where a form will appear based on a certain trigger like :

    • A certain amount of time on page
    • A certain distance scrolling down the page
    • If someone is a new or returning visitor

    Depending on the form software you use, you may be able to add conditional logic.

    Start tracking your form conversions

    Form optimisation is all about conversion rate optimisation.

    If you want to increase your conversions and generate more revenue, then you need to test out different forms and know how to optimise them.

    With Matomo, you can easily track, manage, and A/B test your forms so you can improve your conversions. 

    Try Matomo free for 21 days. No credit card required.

  • 10 Customer Segments Examples and Their Benefits

    9 mai 2024, par Erin

    Now that companies can segment buyers, the days of mass marketing are behind us. Customer segmentation offers various benefits for marketing, content creation, sales, analytics teams and more. Without customer segmentation, your personalised marketing efforts may fall flat. 

    According to the Twilio 2023 state of personalisation report, 69% of business leaders have increased their investment in personalisation. There’s a key reason for this — customer retention and loyalty directly benefit from personalisation. In fact, 62% of businesses have cited improved customer retention due to personalisation efforts. The numbers don’t lie. 

    Keep reading to learn how customer segments can help you fine-tune your personalised marketing campaigns. This article will give you a better understanding of customer segmentation and real-world customer segment examples. You’ll leave with the knowledge to empower your marketing strategies with effective customer segmentation. 

    What are customer segments ?

    Customer segments are distinct groups of people or organisations with similar characteristics, needs and behaviours. Like different species of plants in a garden, each customer segment has specific needs and care requirements. Customer segments are useful for tailoring personalised marketing campaigns for specific groups.

    Personalised marketing has been shown to have significant benefits — with 56% of consumers saying that a personalised experience would make them become repeat buyers

    Successful marketing teams typically focus on these types of customer segmentation :

    A chart with icons representing the different customer segmentation categories
    1. Geographic segmentation : groups buyers based on their physical location — country, city, region or climate — and language.
    2. Purchase history segmentation : categorises buyers based on their purchasing habits — how often they make purchases — and allows brands to distinguish between frequent, occasional and one-time buyers. 
    3. Product-based segmentation : groups buyers according to the products they prefer or end up purchasing. 
    4. Customer lifecycle segmentation : segments buyers based on where they are in the customer journey. Examples include new, repeat and lapsed buyers. This segmentation category is also useful for understanding the behaviour of loyal buyers and those at risk of churning. 
    5. Technographic segmentation : focuses on buyers’ technology preferences, including device type, browser type, and operating system. 
    6. Channel preference segmentation : helps us understand why buyers prefer to purchase via specific channels — whether online channels, physical stores or a combination of both. 
    7. Value-based segmentation : categorises buyers based on their average purchase value and sensitivity to pricing, for example. This type of segmentation can provide insights into the behaviours of price-conscious buyers and those willing to pay premium prices. 

    Customer segmentation vs. market segmentation

    Customer segmentation and market segmentation are related concepts, but they refer to different aspects of the segmentation process in marketing. 

    Market segmentation is the broader process of dividing the overall market into homogeneous groups. Market segmentation helps marketers identify different groups based on their characteristics or needs. These market segments make it easier for businesses to connect with new buyers by offering relevant products or new features. 

    On the other hand, customer segmentation is used to help you dig deep into the behaviour and preferences of your current customer base. Marketers use customer segmentation insights to create buyer personas. Buyer personas are essential for ensuring your personalised marketing efforts are relevant to the target audience. 

    10 customer segments examples

    Now that you better understand different customer segmentation categories, we’ll provide real-world examples of how customer segmentation can be applied. You’ll be able to draw a direct connection between the segmentation category or categories each example falls under.

    One thing to note is that you’ll want to consider privacy and compliance when you are considering collecting and analysing types of data such as gender, age, income level, profession or personal interests. Instead, you can focus on these privacy-friendly, ethical customer segmentation types :

    1. Geographic location (category : geographic segmentation)

    The North Face is an outdoor apparel and equipment company that relies on geographic segmentation to tailor its products toward buyers in specific regions and climates. 

    For instance, they’ll send targeted advertisements for insulated jackets and snow gear to buyers in colder climates. For folks in seasonal climates, The North Face may send personalised ads for snow gear in winter and ads for hiking or swimming gear in summer. 

    The North Face could also use geographic segmentation to determine buyers’ needs based on location. They can use this information to send targeted ads to specific customer segments during peak ski months to maximise profits.

    2. Preferred language (category : geographic segmentation)

    Your marketing approach will likely differ based on where your customers are and the language they speak. So, with that in mind, language may be another crucial variable you can introduce when identifying your target customers. 

    Language-based segmentation becomes even more important when one of your main business objectives is to expand into new markets and target international customers — especially now that global reach is made possible through digital channels. 

    Coca-Cola’s “Share a Coke” is a multi-national campaign with personalised cans and bottles featuring popular names from countries around the globe. It’s just one example of targeting customers based on language.

    3. Repeat users and loyal customers (category : customer lifecycle segmentation)

    Sephora, a large beauty supply company, is well-known for its Beauty Insider loyalty program. 

    It segments customers based on their purchase history and preferences and rewards their loyalty with gifts, discounts, exclusive offers and free samples. And since customers receive personalised product recommendations and other perks, it incentivises them to remain members of the Beauty Insider program — adding a boost to customer loyalty.

    By creating a memorable customer experience for this segment of their customer base, staying on top of beauty trends and listening to feedback, Sephora is able to keep buyers coming back.

    All customers on the left and their respective segments on the right

    4. New customers (category : customer lifecycle segmentation)

    Subscription services use customer lifecycle segmentation to offer special promotions and trials for new customers. 

    HBO Max is a great example of a real company that excels at this strategy : 

    They offer 40% savings on an annual ad-free plan, which targets new customers who may be apprehensive about the added monthly cost of a recurring subscription.

    This marketing strategy prioritises fostering long-term customer relationships with new buyers to avoid high churn rates. 

    5. Cart abandonment (category : purchase history segmentation)

    With a rate of 85% among US-based mobile users, cart abandonment is a huge issue for ecommerce businesses. One way to deal with this is to segment inactive customers and cart abandoners — those who showed interest by adding products to their cart but haven’t converted yet — and send targeted emails to remind them about their abandoned carts.

    E-commerce companies like Ipsy, for example, track users who have added items to their cart but haven’t followed through on the purchase. The company’s messaging often contains incentives — like free shipping or a limited-time discount — to encourage passive users to return to their carts. 

    Research has found that cart abandonment emails with a coupon code have a high 44.37% average open rate. 

    6. Website activity (category : technographic segmentation)

    It’s also possible to segment customers based on website activity. Now, keep in mind that this is a relatively broad approach ; it covers every interaction that may occur while the customer is browsing your website. As such, it leaves room for many different types of segmentation. 

    For instance, you can segment your audience based on the pages they visited, the elements they interacted with — like CTAs and forms — how long they stayed on each page and whether they added products to their cart. 

    Matomo’s Event Tracking can provide additional context to each website visit and tell you more about the specific interactions that occur, making it particularly useful for segmenting customers based on how they spend their time on your website. 

    Try Matomo for Free

    Get the web insights you need, while respecting user privacy.

    No credit card required

    Amazon segments its customers based on browsing behaviour — recently viewed products and categories, among other things — which, in turn, allows them to improve the customer’s experience and drive sales.

    7. Traffic source (category : channel segmentation) 

    You can also segment your audience based on traffic sources. For example, you can determine if your website visitors arrived through Google and other search engines, email newsletters, social media platforms or referrals. 

    In other words, you’ll create specific audience segments based on the original source. Matomo’s Acquisition feature can provide insights into five different types of traffic sources — search engines, social media, external websites, direct traffic and campaigns — to help you understand how users enter your website.

    You may find that most visitors arrive at your website through social media ads or predominantly discover your brand through search engines. Either way, by learning where they’re coming from, you’ll be able to determine which conversion paths you should prioritise and optimise further. 

    8. Device type (category : technographic segmentation)

    Device type is customer segmentation based on the devices that potential customers may use to access your website and view your content. 

    It’s worth noting that, on a global level, most people (96%) use mobile devices — primarily smartphones — for internet access. So, there’s a high chance that most of your website visitors are coming from mobile devices, too. 

    However, it’s best not to assume anything. Matomo can detect the operating system and the type of device — desktop, mobile device, tablet, console or TV, for example. 

    By introducing the device type variable into your customer segmentation efforts, you’ll be able to determine if there’s a preference for mobile or desktop devices. In return, you’ll have a better idea of how to optimise your website — and whether you should consider developing an app to meet the needs of mobile users.

    Try Matomo for Free

    Get the web insights you need, while respecting user privacy.

    No credit card required

    9. Browser type (category : technographic segmentation)

    Besides devices, another type of segmentation that belongs to the technographic category and can provide valuable insights is browser-related. In this case, you’re tracking the internet browser your customers use. 

    Many browser types are available — including Google Chrome, Microsoft Edge, Safari, Firefox and Brave — and each may display your website and other content differently. 

    So, keeping track of your customers’ preferred choices is important. Otherwise, you won’t be able to fully understand their online experience — or ensure that these browsers are displaying your content properly. 

    Browser type in Matomo

    10. Ecommerce activity (category : purchase history, value based, channel or product based segmentation) 

    Similar to website activity, looking at ecommerce activity can tell your sales teams more about which pages the customer has seen and how they have interacted with them. 

    With Matomo’s Ecommerce Tracking, you’ll be able to keep an eye on customers’ on-site behaviours, conversion rates, cart abandonment, purchased products and transaction data — including total revenue and average order value.

    Considering that the focus is on sales channels — such as your online store — this approach to customer segmentation can help you improve the sales experience and increase profitability. 

    Start implementing these customer segments examples

    With ever-evolving demographics and rapid technological advancements, customer segmentation is increasingly complex. The tips and real-world examples in this article break down and simplify customer segmentation so that you can adapt to your customer base. 

    Customer segmentation lays the groundwork for your personalised marketing campaigns to take off. By understanding your users better, you can effectively tailor each campaign to different segments. 

    If you’re ready to see how Matomo can elevate your personalised marketing campaigns, try it for free for 21 days. No credit card required.

  • Sending raw h264 video and aac audio frames to an RTMP server using ffmpeg

    15 août 2016, par codeimpaler

    I am receiving raw h264 and aac audio frames from an even driven source. I am trying to send these frames to an rtmp server.
    I started working from the ffmpeg example muxing.c which successfully sends a custom stream to the rtmp server. I figure I just need to replace their frame data with my own.I found this suggestion online. I have tried How to pack raw h264 stream to flv container and send over rtmp using ffmpeg (not command)
    and
    How to publish selfmade stream with ffmpeg and c++ to rtmp server ?
    and a few other suggestions but none have worked for me.
    I have tried to directly memcpy my byte buffer but my code keeps failing
    at ret = avcodec_encode_video2(c, &pkt, frame, &got_packet).
    Specifically, I get an invalid access error.
    For a little more context, anytime I receive a frame (which is event driven), void RTMPWriter::WriteVideoFrame(...) is called. Assume the constructor has already been called before the first frame is received.
    I am not that familiar with ffmpeg and there could be several things wrong with the code. Any input will be really appreciated.

       #define STREAM_FRAME_RATE 25 /* 25 images/s */
       #define STREAM_PIX_FMT    AV_PIX_FMT_YUV420P /* default pix_fmt */
       #define SCALE_FLAGS SWS_BICUBIC
       RTMPWriter::RTMPWriter()
         : seenKeyFrame(false),
           video_st({ 0 }),
           audio_st({ 0 }),
           have_video(0),
           have_audio(0)
       {

           const char *filename;
           AVCodec *audio_codec = NULL, *video_codec = NULL;
           int ret;

           int encode_video = 0, encode_audio = 0;
           AVDictionary *opt = NULL;
           int i;

           /* Initialize libavcodec, and register all codecs and formats. */
           av_register_all();

           avformat_network_init();

          String^ StreamURL = "StreamURL";
          String^ out_uri = safe_cast(ApplicationData::Current->LocalSettings->Values->Lookup(StreamURL));
          std::wstring out_uriW(out_uri->Begin());
          std::string out_uriA(out_uriW.begin(), out_uriW.end());
          filename = out_uriA.c_str();  

          /* allocate the output media context */
          avformat_alloc_output_context2(&oc, NULL, "flv", filename);
          if (!oc)
          {
              OutputDebugString(L"Could not deduce output format from file extension: using MPEG.\n");
              avformat_alloc_output_context2(&oc, NULL, "mpeg", filename);
          }
          if (!oc)
          {
              OutputDebugString(L"Could not allocate  using MPEG.\n");
          }


          fmt = oc->oformat;

          /* Add the audio and video streams using the default format codecs
          * and initialize the codecs. */
          if (fmt->video_codec != AV_CODEC_ID_NONE) {
              add_stream(&video_st, oc, &video_codec, fmt->video_codec);
              have_video = 1;
              encode_video = 1;
          }
          if (fmt->audio_codec != AV_CODEC_ID_NONE) {
              add_stream(&audio_st, oc, &audio_codec, fmt->audio_codec);
              have_audio = 1;
              encode_audio = 1;
          }

          /* Now that all the parameters are set, we can open the audio and
           * video codecs and allocate the necessary encode buffers. */
          if (have_video)
          {
              open_video(oc, video_codec, &video_st, opt);
          }

          if (have_audio)
          {
              open_audio(oc, audio_codec, &audio_st, opt);
          }

          av_dump_format(oc, 0, filename, 1);

          /* open the output file, if needed */
          if (!(fmt->flags & AVFMT_NOFILE))
          {
              ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE);
              if (ret < 0)
              {
                  OutputDebugString(L"Could not open ");
                  OutputDebugString(out_uri->Data());
              }
          }

          /* Write the stream header, if any. */
          ret = avformat_write_header(oc, &opt);
          if (ret < 0)
          {
              OutputDebugString(L"Error occurred when writing stream header \n");
          }

       }

       void RTMPWriter::WriteVideoFrame(
           boolean isKeyFrame,
           boolean hasDiscontinuity,
           UINT64 frameId,
           UINT32 videoBufferLength,
           BYTE *videoBytes)
       {

           int ret;
           AVCodecContext *c;
           AVFrame* frame;
           int got_packet = 0;
           AVPacket pkt = { 0 };

           c = video_st.enc;

           frame = get_video_frame(videoBufferLength, videoBytes);

           /* encode the image */
           ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
           if (ret < 0) {
                OutputDebugString(L"Error encoding video frame: \n")
           }

           if (got_packet)
           {
               ret = write_frame(oc, &c->time_base, video_st.st, &pkt);
           }
           else {
               ret = 0;
           }

           if (ret < 0) {
                OutputDebugString(L"Error while writing video frame: %s\n");
           }
       }

       AVFrame * RTMPWriter::get_video_frame(
          UINT32 videoBufferLength,
          BYTE *videoBytes)
       {
           AVCodecContext *c = video_st.enc;

           if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
               /* as we only generate a YUV420P picture, we must convert it
               * to the codec pixel format if needed */
               if (!video_st.sws_ctx) {
                   video_st.sws_ctx = sws_getContext(c->width, c->height,
                       AV_PIX_FMT_YUV420P,
                       c->width, c->height,
                       c->pix_fmt,
                       SCALE_FLAGS, NULL, NULL, NULL);
                   if (!video_st.sws_ctx) {
                       fprintf(stderr,
                           "Could not initialize the conversion context\n");
                           exit(1);
                   }
               }
               fill_yuv_image(video_st.tmp_frame, video_st.next_pts, c->width, c->height, videoBufferLength, videoBytes);
               sws_scale(video_st.sws_ctx,
               (const uint8_t * const *)video_st.tmp_frame->data, video_st.tmp_frame->linesize,
               0, c->height, video_st.frame->data, video_st.frame->linesize);
           }
           else {
               fill_yuv_image(video_st.frame, video_st.next_pts, c->width, c->height, videoBufferLength, videoBytes);
           }

           video_st.frame->pts = video_st.next_pts++;

           return video_st.frame;
       }

       /* Prepare a dummy image. */
       void  RTMPWriter::fill_yuv_image(
            AVFrame *pict,
            int frame_index,
            int width,
            int height,
            UINT32 videoBufferLength,
            BYTE *videoBytes)
       {
           //int x, y, i, ret;

           /* when we pass a frame to the encoder, it may keep a reference to it
           * internally;
           * make sure we do not overwrite it here
           */
           ret = av_frame_make_writable(pict);
           if (ret < 0)
           {
                OutputDebugString(L"Unable to make piture writable");
           }

           memcpy(pict->data, videoBytes, videoBufferLength);

           //i = frame_index;

           ///* Y */
           //for (y = 0; y < height; y++)
           //  for (x = 0; x < width; x++)
           //      pict->data[0][y * pict->linesize[0] + x] = x + y + i * 3;

           ///* Cb and Cr */
           //for (y = 0; y < height / 2; y++) {
           //  for (x = 0; x < width / 2; x++) {
           //      pict->data[1][y * pict->linesize[1] + x] = 128 + y + i * 2;
           //      pict->data[2][y * pict->linesize[2] + x] = 64 + x + i * 5;
           //  }
           //}
       }

       void RTMPWriter::WriteAudioFrame()
       {

       }

       /* Add an output stream. */
       void  RTMPWriter::add_stream(
           OutputStream *ost,
           AVFormatContext *oc,
           AVCodec **codec,
           enum AVCodecID codec_id)
      {
       AVCodecContext *c;
       int i;

       /* find the encoder */
       *codec = avcodec_find_encoder(codec_id);
       if (!(*codec)) {
           OutputDebugString(L"Could not find encoder for '%s'\n");
           //avcodec_get_name(codec_id));
           exit(1);
       }

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

       switch ((*codec)->type) {
       case AVMEDIA_TYPE_AUDIO:
           c->sample_fmt = (*codec)->sample_fmts ?
               (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
           c->bit_rate = 64000;
           c->sample_rate = 44100;
           if ((*codec)->supported_samplerates) {
               c->sample_rate = (*codec)->supported_samplerates[0];
               for (i = 0; (*codec)->supported_samplerates[i]; i++) {
                   if ((*codec)->supported_samplerates[i] == 44100)
                       c->sample_rate = 44100;
               }
           }
           c->channels = av_get_channel_layout_nb_channels(c->channel_layout);
           c->channel_layout = AV_CH_LAYOUT_STEREO;
           if ((*codec)->channel_layouts) {
               c->channel_layout = (*codec)->channel_layouts[0];
               for (i = 0; (*codec)->channel_layouts[i]; i++) {
                   if ((*codec)->channel_layouts[i] == AV_CH_LAYOUT_STEREO)
                       c->channel_layout = AV_CH_LAYOUT_STEREO;
               }
           }
           c->channels = av_get_channel_layout_nb_channels(c->channel_layout);
           ost->st->time_base = /*(AVRational)*/{ 1, c->sample_rate };
           break;

       case AVMEDIA_TYPE_VIDEO:
           c->codec_id = codec_id;

           c->bit_rate = 400000;
           /* Resolution must be a multiple of two. */
           c->width = 352;
           c->height = 288;
           /* 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 = /*(AVRational)*/{ 1, STREAM_FRAME_RATE };
           c->time_base = ost->st->time_base;

           c->gop_size = 12; /* emit one intra frame every twelve frames at most */
           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;
               }
               break;

           default:
               break;
           }

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

    AVFrame * RTMPWriter::alloc_audio_frame(
       enum AVSampleFormat sample_fmt,
       uint64_t channel_layout,
       int sample_rate, int nb_samples)
    {
       AVFrame *frame = av_frame_alloc();
       int ret;

       if (!frame) {
           OutputDebugString(L"Error allocating an audio frame\n");
           exit(1);
       }

       frame->format = sample_fmt;
       frame->channel_layout = channel_layout;
       frame->sample_rate = sample_rate;
       frame->nb_samples = nb_samples;

       if (nb_samples) {
           ret = av_frame_get_buffer(frame, 0);
           if (ret < 0) {
               OutputDebugString(L"Error allocating an audio buffer\n");
               exit(1);
           }
       }

           return frame;
       }




    void  RTMPWriter::open_audio(
       AVFormatContext *oc,
       AVCodec *codec,
       OutputStream *ost,
       AVDictionary *opt_arg)
    {
       AVCodecContext *c;
       int nb_samples;
       int ret;
       AVDictionary *opt = NULL;

       c = ost->enc;

       /* open it */
       av_dict_copy(&opt, opt_arg, 0);
       ret = avcodec_open2(c, codec, &opt);
       av_dict_free(&opt);
       if (ret < 0) {
           OutputDebugString(L"Could not open audio codec: %s\n");// , av_err2str(ret));
           exit(1);
       }

       /* init signal generator */
       ost->t = 0;
       ost->tincr = 2 * M_PI * 110.0 / c->sample_rate;
       /* increment frequency by 110 Hz per second */
       ost->tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;

       if (c->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
           nb_samples = 10000;
       else
           nb_samples = c->frame_size;

       ost->frame = alloc_audio_frame(c->sample_fmt, c->channel_layout,
           c->sample_rate, nb_samples);
       ost->tmp_frame = alloc_audio_frame(AV_SAMPLE_FMT_S16, c->channel_layout,
           c->sample_rate, nb_samples);

       /* copy the stream parameters to the muxer */
       ret = avcodec_parameters_from_context(ost->st->codecpar, c);
       if (ret < 0) {
           OutputDebugString(L"Could not copy the stream parameters\n");
           exit(1);
       }

       /* create resampler context */
       ost->swr_ctx = swr_alloc();
       if (!ost->swr_ctx) {
           OutputDebugString(L"Could not allocate resampler context\n");
           exit(1);
       }

       /* set options */
       av_opt_set_int(ost->swr_ctx, "in_channel_count", c->channels, 0);
       av_opt_set_int(ost->swr_ctx, "in_sample_rate", c->sample_rate, 0);
       av_opt_set_sample_fmt(ost->swr_ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
       av_opt_set_int(ost->swr_ctx, "out_channel_count", c->channels, 0);
       av_opt_set_int(ost->swr_ctx, "out_sample_rate", c->sample_rate, 0);
       av_opt_set_sample_fmt(ost->swr_ctx, "out_sample_fmt", c->sample_fmt, 0);

       /* initialize the resampling context */
       if ((ret = swr_init(ost->swr_ctx)) < 0) {
           OutputDebugString(L"Failed to initialize the resampling context\n");
           exit(1);
       }
    }

    int RTMPWriter::write_frame(
       AVFormatContext *fmt_ctx,
       const AVRational *time_base,
       AVStream *st,
       AVPacket *pkt)
    {
       /* rescale output packet timestamp values from codec to stream timebase */
       av_packet_rescale_ts(pkt, *time_base, st->time_base);
       pkt->stream_index = st->index;

       /* Write the compressed frame to the media file. */
       //log_packet(fmt_ctx, pkt);
       OutputDebugString(L"Actually sending video frame: %s\n");
       return av_interleaved_write_frame(fmt_ctx, pkt);
    }


    AVFrame  *RTMPWriter::alloc_picture(
       enum AVPixelFormat pix_fmt,
       int width,
       int height)
    {
       AVFrame *picture;
       int ret;

       picture = av_frame_alloc();
       if (!picture)
           return NULL;

       picture->format = pix_fmt;
       picture->width = width;
       picture->height = height;

       /* allocate the buffers for the frame data */
       ret = av_frame_get_buffer(picture, 32);
       if (ret < 0) {
           fprintf(stderr, "Could not allocate frame data.\n");
           exit(1);
       }

       return picture;
    }

    void RTMPWriter::open_video(
       AVFormatContext *oc,
       AVCodec *codec,
       OutputStream *ost,
       AVDictionary *opt_arg)
    {
       int ret;
       AVCodecContext *c = ost->enc;
       AVDictionary *opt = NULL;

       av_dict_copy(&opt, opt_arg, 0);

       /* open the codec */
       ret = avcodec_open2(c, codec, &opt);
       av_dict_free(&opt);
       if (ret < 0) {
           OutputDebugString(L"Could not open video codec: %s\n");// , av_err2str(ret));
           exit(1);
       }

       /* allocate and init a re-usable frame */
       ost->frame = alloc_picture(c->pix_fmt, c->width, c->height);
       if (!ost->frame) {
           OutputDebugString(L"Could not allocate video frame\n");
           exit(1);
       }

       /* If the output format is not YUV420P, then a temporary YUV420P
       * picture is needed too. It is then converted to the required
       * output format. */
       ost->tmp_frame = NULL;
       if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
           ost->tmp_frame = alloc_picture(AV_PIX_FMT_YUV420P, c->width, c->height);
           if (!ost->tmp_frame) {
               OutputDebugString(L"Could not allocate temporary picture\n");
               exit(1);
           }
       }

       /* copy the stream parameters to the muxer */
       ret = avcodec_parameters_from_context(ost->st->codecpar, c);
       if (ret < 0) {
           OutputDebugString(L"Could not copy the stream parameters\n");
           exit(1);
       }
    }

    void RTMPWriter::close_stream(AVFormatContext *oc, OutputStream *ost)
    {
       avcodec_free_context(&ost->enc);
       av_frame_free(&ost->frame);
       av_frame_free(&ost->tmp_frame);
       sws_freeContext(ost->sws_ctx);
       swr_free(&ost->swr_ctx);
    }

    RTMPWriter::~RTMPWriter()
    {
       av_write_trailer(oc);
       /* Close each codec. */
       if (have_video)
           close_stream(oc, &video_st);
       if (have_audio)
           close_stream(oc, &audio_st);

       if (!(fmt->flags & AVFMT_NOFILE))
           /* Close the output file. */
           avio_closep(&oc->pb);

       /* free the stream */
       avformat_free_context(oc);
    }