Recherche avancée

Médias (0)

Mot : - Tags -/upload

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (53)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-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

Sur d’autres sites (9999)

  • The use cases for a element in HTML

    1er janvier 2014, par silvia

    The W3C HTML WG and the WHATWG are currently discussing the introduction of a <main> element into HTML.

    The <main> element has been proposed by Steve Faulkner and is specified in a draft extension spec which is about to be accepted as a FPWD (first public working draft) by the W3C HTML WG. This implies that the W3C HTML WG will be looking for implementations and for feedback by implementers on this spec.

    I am supportive of the introduction of a <main> element into HTML. However, I believe that the current spec and use case list don’t make a good enough case for its introduction. Here are my thoughts.

    Main use case : accessibility

    In my opinion, the main use case for the introduction of <main> is accessibility.

    Like any other users, when blind users want to perceive a Web page/application, they need to have a quick means of grasping the content of a page. Since they cannot visually scan the layout and thus determine where the main content is, they use accessibility technology (AT) to find what is known as “landmarks”.

    “Landmarks” tell the user what semantic content is on a page : a header (such as a banner), a search box, a navigation menu, some asides (also called complementary content), a footer, …. and the most important part : the main content of the page. It is this main content that a blind user most often wants to skip to directly.

    In the days of HTML4, a hidden “skip to content” link at the beginning of the Web page was used as a means to help blind users access the main content.

    In the days of ARIA, the aria @role=main enables authors to avoid a hidden link and instead mark the element where the main content begins to allow direct access to the main content. This attribute is supported by AT – in particular screen readers – by making it part of the landmarks that AT can directly skip to.

    Both the hidden link and the ARIA @role=main approaches are, however, band aids : they are being used by those of us that make “finished” Web pages accessible by adding specific extra markup.

    A world where ARIA is not necessary and where accessibility developers would be out of a job because the normal markup that everyone writes already creates accessible Web sites/applications would be much preferable over the current world of band-aids.

    Therefore, to me, the primary use case for a <main> element is to achieve exactly this better world and not require specialized markup to tell a user (or a tool) where the main content on a page starts.

    An immediate effect would be that pages that have a <main> element will expose a “main” landmark to blind and vision-impaired users that will enable them to directly access that main content on the page without having to wade through other text on the page. Without a <main> element, this functionality can currently only be provided using heuristics to skip other semantic and structural elements and is for this reason not typically implemented in AT.

    Other use cases

    The <main> element is a semantic element not unlike other new semantic elements such as <header>, <footer>, <aside>, <article>, <nav>, or <section>. Thus, it can also serve other uses where the main content on a Web page/Web application needs to be identified.

    Data mining

    For data mining of Web content, the identification of the main content is one of the key challenges. Many scholarly articles have been published on this topic. This stackoverflow article references and suggests a multitude of approaches, but the accepted answer says “there’s no way to do this that’s guaranteed to work”. This is because Web pages are inherently complex and many <div>, <p>, <iframe> and other elements are used to provide markup for styling, notifications, ads, analytics and other use cases that are necessary to make a Web page complete, but don’t contribute to what a user consumes as semantically rich content. A <main> element will allow authors to pro-actively direct data mining tools to the main content.

    Search engines

    One particularly important “data mining” tool are search engines. They, too, have a hard time to identify which sections of a Web page are more important than others and employ many heuristics to do so, see e.g. this ACM article. Yet, they still disappoint with poor results pointing to findings of keywords in little relevant sections of a page rather than ranking Web pages higher where the keywords turn up in the main content area. A <main> element would be able to help search engines give text in main content areas a higher weight and prefer them over other areas of the Web page. It would be able to rank different Web pages depending on where on the page the search words are found. The <main> element will be an additional hint that search engines will digest.

    Visual focus

    On small devices, the display of Web pages designed for Desktop often causes confusion as to where the main content can be found and read, in particular when the text ends up being too small to be readable. It would be nice if browsers on small devices had a functionality (maybe a default setting) where Web pages would start being displayed as zoomed in on the main content. This could alleviate some of the headaches of responsive Web design, where the recommendation is to show high priority content as the first content. Right now this problem is addressed through stylesheets that re-layout the page differently depending on device, but again this is a band-aid solution. Explicit semantic markup of the main content can solve this problem more elegantly.

    Styling

    Finally, naturally, <main> would also be used to style the main content differently from others. You can e.g. replace a semantically meaningless <div id=”main”> with a semantically meaningful <main> where their position is identical. My analysis below shows, that this is not always the case, since oftentimes <div id=”main”> is used to group everything together that is not the header – in particular where there are multiple columns. Thus, the ease of styling a <main> element is only a positive side effect and not actually a real use case. It does make it easier, however, to adapt the style of the main content e.g. with media queries.

    Proposed alternative solutions

    It has been proposed that existing markup serves to satisfy the use cases that <main> has been proposed for. Let’s analyse these on some of the most popular Web sites. First let’s list the propsed algorithms.

    Proposed solution No 1 : Scooby-Doo

    On Sat, Nov 17, 2012 at 11:01 AM, Ian Hickson <ian@hixie.ch> wrote :
    | The main content is whatever content isn’t
    | marked up as not being main content (anything not marked up with <header>,
    | <aside>, <nav>, etc).
    

    This implies that the first element that is not a <header>, <aside>, <nav>, or <footer> will be the element that we want to give to a blind user as the location where they should start reading. The algorithm is implemented in https://gist.github.com/4032962.

    Proposed solution No 2 : First article element

    On Sat, Nov 17, 2012 at 8:01 AM, Ian Hickson  wrote :
    | On Thu, 15 Nov 2012, Ian Yang wrote :
    | >
    | > That’s a good idea. We really need an element to wrap all the <p>s,
    | > <ul>s, <ol>s, <figure>s, <table>s ... etc of a blog post.
    |
    | That’s called <article>.
    

    This approach identifies the first <article> element on the page as containing the main content. Here’s the algorithm for this approach.

    Proposed solution No 3 : An example heuristic approach

    The readability plugin has been developed to make Web pages readable by essentially removing all the non-main content from a page. An early source of readability is available. This demonstrates what a heuristic approach can perform.

    Analysing alternative solutions

    Comparison

    I’ve picked 4 typical Websites (top on Alexa) to analyse how these three different approaches fare. Ideally, I’d like to simply apply the above three scripts and compare pictures. However, since the semantic HTML5 elements <header>, <aside>, <nav>, and <footer> are not actually used by any of these Web sites, I don’t actually have this choice.

    So, instead, I decided to make some assumptions of where these semantic elements would be used and what the outcome of applying the first two algorithms would be. I can then compare it to the third, which is a product so we can take screenshots.

    Google.com

    http://google.com – search for “Scooby Doo”.

    The search results page would likely be built with :

    • a <nav> menu for the Google bar
    • a <header> for the search bar
    • another <header> for the login section
    • another <nav> menu for the search types
    • a <div> to contain the rest of the page
    • a <div> for the app bar with the search number
    • a few <aside>s for the left and right column
    • a set of <article>s for the search results
    “Scooby Doo” would find the first element after the headers as the “main content”. This is the element before the app bar in this case. Interestingly, there is a <div @id=main> already in the current Google results page, which “Scooby Doo” would likely also pick. However, there are a nav bar and two asides in this div, which clearly should not be part of the “main content”. Google actually placed a @role=main on a different element, namely the one that encapsulates all the search results.

    “First Article” would find the first search result as the “main content”. While not quite the same as what Google intended – namely all search results – it is close enough to be useful.

    The “readability” result is interesting, since it is not able to identify the main text on the page. It is actually aware of this problem and brings a warning before displaying this page :

    Readability of google.com

    Facebook.com

    https://facebook.com

    A user page would likely be built with :

    • a <header> bar for the search and login bar
    • a <div> to contain the rest of the page
    • an <aside> for the left column
    • a <div> to contain the center and right column
    • an <aside> for the right column
    • a <header> to contain the center column “megaphone”
    • a <div> for the status posting
    • a set of <article>s for the home stream
    “Scooby Doo” would find the first element after the headers as the “main content”. This is the element that contains all three columns. It’s actually a <div @id=content> already in the current Facebook user page, which “Scooby Doo” would likely also pick. However, Facebook selected a different element to place the @role=main : the center column.

    “First Article” would find the first news item in the home stream. This is clearly not what Facebook intended, since they placed the @role=main on the center column, above the first blog post’s title. “First Article” would miss that title and the status posting.

    The “readability” result again disappoints but warns that it failed :

    YouTube.com

    http://youtube.com

    A video page would likely be built with :

    • a <header> bar for the search and login bar
    • a <nav> for the menu
    • a <div> to contain the rest of the page
    • a <header> for the video title and channel links
    • a <div> to contain the video with controls
    • a <div> to contain the center and right column
    • an <aside> for the right column with an <article> per related video
    • an <aside> for the information below the video
    • a <article> per comment below the video
    “Scooby Doo” would find the first element after the headers as the “main content”. This is the element that contains the rest of the page. It’s actually a <div @id=content> already in the current YouTube video page, which “Scooby Doo” would likely also pick. However, YouTube’s related videos and comments are unlikely to be what the user would regard as “main content” – it’s the video they are after, which generously has a <div id=watch-player>.

    “First Article” would find the first related video or comment in the home stream. This is clearly not what YouTube intends.

    The “readability” result is not quite as unusable, but still very bare :

    Wikipedia.com

    http://wikipedia.com (“Overscan” page)

    A Wikipedia page would likely be built with :

    • a <header> bar for the search, login and menu items
    • a <div> to contain the rest of the page
    • an &ls ; article> with title and lots of text
    • <article> an <aside> with the table of contents
    • several <aside>s for the left column
    Good news : “Scooby Doo” would find the first element after the headers as the “main content”. This is the element that contains the rest of the page. It’s actually a <div id=”content” role=”main”> element on Wikipedia, which “Scooby Doo” would likely also pick.

    “First Article” would find the title and text of the main element on the page, but it would also include an <aside>.

    The “readability” result is also in agreement.

    Results

    In the following table we have summarised the results for the experiments :

    Site Scooby-Doo First article Readability
    Google.com FAIL SUCCESS FAIL
    Facebook.com FAIL FAIL FAIL
    YouTube.com FAIL FAIL FAIL
    Wikipedia.com SUCCESS SUCCESS SUCCESS

    Clearly, Wikipedia is the prime example of a site where even the simple approaches find it easy to determine the main content on the page. WordPress blogs are similarly successful. Almost any other site, including news sites, social networks and search engine sites are petty hopeless with the proposed approaches, because there are too many elements that are used for layout or other purposes (notifications, hidden areas) such that the pre-determined list of semantic elements that are available simply don’t suffice to mark up a Web page/application completely.

    Conclusion

    It seems that in general it is impossible to determine which element(s) on a Web page should be the “main” piece of content that accessibility tools jump to when requested, that a search engine should put their focus on, or that should be highlighted to a general user to read. It would be very useful if the author of the Web page would provide a hint through a <main> element where that main content is to be found.

    I think that the <main> element becomes particularly useful when combined with a default keyboard shortcut in browsers as proposed by Steve : we may actually find that non-accessibility users will also start making use of this shortcut, e.g. to get to videos on YouTube pages directly without having to tab over search boxes and other interactive elements, etc. Worthwhile markup indeed.

  • Use ffmpeg to extract picture from m4v file

    31 octobre 2017, par Brian

    I used a program called MetaZ on my mac to tag all my video files (m4v). I am now trying to use these m4v files in Kodi which requires .nfo files and separate picture files for movie posters, etc. I want to extract the picture that is already in the m4v file.

    When I use ffprobe -show_streams, I can see that index4 is a png file (codec_name=png). How do I extract it ? I believe ffmpeg can do it, but can’t figure out how.

    Here is the output from ffprobe :

    Brians-Mac-mini:PythonScript brianjhille$ ffprobe -show_streams badwords.m4v
    ffprobe version N-88046-g0cb8369-tessus Copyright (c) 2007-2017 the FFmpeg developers
     built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
     configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
     libavutil      56.  0.100 / 56.  0.100
     libavcodec     58.  0.100 / 58.  0.100
     libavformat    58.  0.100 / 58.  0.100
     libavdevice    58.  0.100 / 58.  0.100
     libavfilter     7.  0.100 /  7.  0.100
     libswscale      5.  0.100 /  5.  0.100
     libswresample   3.  0.100 /  3.  0.100
     libpostproc    55.  0.100 / 55.  0.100
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd67b002a00] stream 0, timescale not set
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'badwords.m4v':
     Metadata:
       major_brand     : mp42
       minor_version   : 0
       compatible_brands: mp42isomavc1
       creation_time   : 2014-10-20T13:01:06.000000Z
       iTunEXTC        : mpaa|R|400|
       title           : Bad Words
       artist          : Jason Bateman, Kathryn Hahn, Allison Janney, Philip Baker Hall, Rohan Chand, Ben Falcone, Patricia Belcher, Beth Grant, Rachel Harris, Steve Witting, Greg Cromer
       date            : 2013-09-06T11:00:00Z
       track           : 0
       disc            : 0
       season_number   : 0
       episode_sort    : 0
       description     : A spelling bee loser sets out to exact revenge by finding a loophole and attempting to win as an adult.
       synopsis        : A spelling bee loser sets out to exact revenge by finding a loophole and attempting to win as an adult.
       encoder         : HandBrake 0.9.9 2013052900
       hd_video        : 0
       media_type      : 9
       genre           : Comedy
       iTunMOVI        : &lt;?xml version="1.0" encoding="UTF-8"?>
                       :
                       : <plist version="1.0">
                       : <dict>
                       :   <key>cast</key>
                       :   <array>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Jason Bateman</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Kathryn Hahn</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Allison Janney</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Philip Baker Hall</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Rohan Chand</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Ben Falcone</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Patricia Belcher</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Beth Grant</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Rachel Harris</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Steve Witting</string>
                       :       </dict>
                       :       <dict>
                       :           <key>name</key>
                       :           <string>Greg Cromer</string>
                       :       </dict>
                       :   </array>
                       : </dict>
                       : </plist>
                       :
     Duration: 01:29:02.84, start: 0.000000, bitrate: 1339 kb/s
       Chapter #0:0: start 0.000000, end 348.214000
       Metadata:
         title           : Chapter 1
       Chapter #0:1: start 348.214000, end 676.542000
       Metadata:
         title           : Chapter 2
       Chapter #0:2: start 676.542000, end 860.058000
       Metadata:
         title           : Chapter 3
       Chapter #0:3: start 860.058000, end 1171.836000
       Metadata:
         title           : Chapter 4
       Chapter #0:4: start 1171.836000, end 1441.839000
       Metadata:
         title           : Chapter 5
       Chapter #0:5: start 1441.839000, end 1632.129000
       Metadata:
         title           : Chapter 6
       Chapter #0:6: start 1632.129000, end 1925.422000
       Metadata:
         title           : Chapter 7
       Chapter #0:7: start 1925.422000, end 2167.030000
       Metadata:
         title           : Chapter 8
       Chapter #0:8: start 2167.030000, end 2409.605000
       Metadata:
         title           : Chapter 9
       Chapter #0:9: start 2409.605000, end 2748.276000
       Metadata:
         title           : Chapter 10
       Chapter #0:10: start 2748.276000, end 2917.945000
       Metadata:
         title           : Chapter 11
       Chapter #0:11: start 2917.945000, end 3309.502000
       Metadata:
         title           : Chapter 12
       Chapter #0:12: start 3309.502000, end 3634.660000
       Metadata:
         title           : Chapter 13
       Chapter #0:13: start 3634.660000, end 3942.434000
       Metadata:
         title           : Chapter 14
       Chapter #0:14: start 3942.434000, end 4101.626000
       Metadata:
         title           : Chapter 15
       Chapter #0:15: start 4101.626000, end 4336.193000
       Metadata:
         title           : Chapter 16
       Chapter #0:16: start 4336.193000, end 4620.643000
       Metadata:
         title           : Chapter 17
       Chapter #0:17: start 4620.643000, end 4873.729000
       Metadata:
         title           : Chapter 18
       Chapter #0:18: start 4873.729000, end 5153.341000
       Metadata:
         title           : Chapter 19
       Chapter #0:19: start 5153.341000, end 5342.796000
       Metadata:
         title           : Chapter 20
       Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 720x356 [SAR 32:27 DAR 640:267], 716 kb/s, 23.98 fps, 59.94 tbr, 90k tbn, 180k tbc (default)
       Metadata:
         creation_time   : 2014-10-20T13:01:06.000000Z
         encoder         : JVT/AVC Coding
       Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 159 kb/s (default)
       Metadata:
         creation_time   : 2014-10-20T13:01:06.000000Z
       Stream #0:2(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 448 kb/s
       Metadata:
         creation_time   : 2014-10-20T13:01:06.000000Z
       Side data:
         audio service type: main
       Stream #0:3(und): Data: bin_data (text / 0x74786574)
       Metadata:
         creation_time   : 2014-10-21T13:42:00.000000Z
       Stream #0:4: Video: png, rgb24(pc), 1400x2100, 90k tbr, 90k tbn, 90k tbc
    Unsupported codec with id 100359 for input stream 3
    [STREAM]
    index=0
    codec_name=h264
    codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
    profile=Constrained Baseline
    codec_type=video
    codec_time_base=40071281/1921695000
    codec_tag_string=avc1
    codec_tag=0x31637661
    width=720
    height=356
    coded_width=720
    coded_height=356
    has_b_frames=0
    sample_aspect_ratio=32:27
    display_aspect_ratio=640:267
    pix_fmt=yuv420p
    level=30
    color_range=tv
    color_space=smpte170m
    color_transfer=bt709
    color_primaries=smpte170m
    chroma_location=left
    field_order=unknown
    timecode=N/A
    refs=1
    is_avc=true
    nal_length_size=4
    id=N/A
    r_frame_rate=60000/1001
    avg_frame_rate=960847500/40071281
    time_base=1/90000
    start_pts=0
    start_time=0.000000
    duration_ts=480855372
    duration=5342.837467
    bit_rate=716167
    max_bit_rate=N/A
    bits_per_raw_sample=8
    nb_frames=128113
    nb_read_frames=N/A
    nb_read_packets=N/A
    DISPOSITION:default=1
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=0
    DISPOSITION:timed_thumbnails=0
    TAG:creation_time=2014-10-20T13:01:06.000000Z
    TAG:language=und
    TAG:encoder=JVT/AVC Coding
    [/STREAM]
    [STREAM]
    index=1
    codec_name=aac
    codec_long_name=AAC (Advanced Audio Coding)
    profile=LC
    codec_type=audio
    codec_time_base=1/48000
    codec_tag_string=mp4a
    codec_tag=0x6134706d
    sample_fmt=fltp
    sample_rate=48000
    channels=2
    channel_layout=stereo
    bits_per_sample=0
    id=N/A
    r_frame_rate=0/0
    avg_frame_rate=0/0
    time_base=1/48000
    start_pts=0
    start_time=0.000000
    duration_ts=256454656
    duration=5342.805333
    bit_rate=159788
    max_bit_rate=321176
    bits_per_raw_sample=N/A
    nb_frames=250444
    nb_read_frames=N/A
    nb_read_packets=N/A
    DISPOSITION:default=1
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=0
    DISPOSITION:timed_thumbnails=0
    TAG:creation_time=2014-10-20T13:01:06.000000Z
    TAG:language=eng
    [/STREAM]
    [STREAM]
    index=2
    codec_name=ac3
    codec_long_name=ATSC A/52A (AC-3)
    profile=unknown
    codec_type=audio
    codec_time_base=1/48000
    codec_tag_string=ac-3
    codec_tag=0x332d6361
    sample_fmt=fltp
    sample_rate=48000
    channels=6
    channel_layout=5.1(side)
    bits_per_sample=0
    dmix_mode=-1
    ltrt_cmixlev=-1.000000
    ltrt_surmixlev=-1.000000
    loro_cmixlev=-1.000000
    loro_surmixlev=-1.000000
    id=N/A
    r_frame_rate=0/0
    avg_frame_rate=0/0
    time_base=1/48000
    start_pts=0
    start_time=0.000000
    duration_ts=256453632
    duration=5342.784000
    bit_rate=448000
    max_bit_rate=N/A
    bits_per_raw_sample=N/A
    nb_frames=166962
    nb_read_frames=N/A
    nb_read_packets=N/A
    DISPOSITION:default=0
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=0
    DISPOSITION:timed_thumbnails=0
    TAG:creation_time=2014-10-20T13:01:06.000000Z
    TAG:language=eng
    [SIDE_DATA]
    side_data_type=Audio Service Type
    [/SIDE_DATA]
    [/STREAM]
    [STREAM]
    index=3
    codec_name=bin_data
    codec_long_name=binary data
    profile=unknown
    codec_type=data
    codec_tag_string=text
    codec_tag=0x74786574
    id=N/A
    r_frame_rate=0/0
    avg_frame_rate=0/0
    time_base=1/1000
    start_pts=0
    start_time=0.000000
    duration_ts=5342837
    duration=5342.837000
    bit_rate=N/A
    max_bit_rate=N/A
    bits_per_raw_sample=N/A
    nb_frames=20
    nb_read_frames=N/A
    nb_read_packets=N/A
    DISPOSITION:default=0
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=0
    DISPOSITION:timed_thumbnails=0
    TAG:creation_time=2014-10-21T13:42:00.000000Z
    TAG:language=und
    [/STREAM]
    [STREAM]
    index=4
    codec_name=png
    codec_long_name=PNG (Portable Network Graphics) image
    profile=unknown
    codec_type=video
    codec_time_base=0/1
    codec_tag_string=[0][0][0][0]
    codec_tag=0x0000
    width=1400
    height=2100
    coded_width=1400
    coded_height=2100
    has_b_frames=0
    sample_aspect_ratio=0:1
    display_aspect_ratio=0:1
    pix_fmt=rgb24
    level=-99
    color_range=pc
    color_space=unknown
    color_transfer=unknown
    color_primaries=unknown
    chroma_location=unspecified
    field_order=unknown
    timecode=N/A
    refs=1
    id=N/A
    r_frame_rate=90000/1
    avg_frame_rate=0/0
    time_base=1/90000
    start_pts=0
    start_time=0.000000
    duration_ts=480855372
    duration=5342.837467
    bit_rate=N/A
    max_bit_rate=N/A
    bits_per_raw_sample=N/A
    nb_frames=N/A
    nb_read_frames=N/A
    nb_read_packets=N/A
    DISPOSITION:default=0
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=1
    DISPOSITION:timed_thumbnails=0
    [/STREAM]

    Thanks. Brian

  • Record rtsp stream with ffmpeg in iOS

    27 janvier 2017, par Wei Wen Hsiao

    I’ve followed iFrameExtractor to successfully stream rtsp in my swift project. In this project, it also has recording function. It basically use avformat_write_header
    , av_interleaved_write_frame and av_write_trailer to save the rtsp source into mp4 file.

    When I used this project in my device, the rtsp streaming works fine, but recording function will always generate a blank mp4 file with no image and sound.

    Could anyone tell me what step that I miss ?

    I’m using iPhone5 with iOS 9.1 and XCode 7.1.1.
    The ffmpeg is 2.8.3 version and followed the compile instruction by CompilationGuide – FFmpeg

    Following is the sample code in this project

    The function that generate every frame :

    -(BOOL)stepFrame {
    // AVPacket packet;
    int frameFinished=0;
    static bool bFirstIFrame=false;
    static int64_t vPTS=0, vDTS=0, vAudioPTS=0, vAudioDTS=0;

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

           // 20130525 albert.liao modified start

           // Initialize a new format context for writing file
           if(veVideoRecordState!=eH264RecIdle)
           {
               switch(veVideoRecordState)
               {
                   case eH264RecInit:
                   {                        
                       if ( !pFormatCtx_Record )
                       {
                           int bFlag = 0;
                           //NSString *videoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.mp4"];
                           NSString *videoPath = @"/Users/liaokuohsun/iFrameTest.mp4";

                           const char *file = [videoPath UTF8String];
                           pFormatCtx_Record = avformat_alloc_context();
                           bFlag = h264_file_create(file, pFormatCtx_Record, pCodecCtx, pAudioCodecCtx,/*fps*/0.0, packet.data, packet.size );

                           if(bFlag==true)
                           {
                               veVideoRecordState = eH264RecActive;
                               fprintf(stderr, "h264_file_create success\n");                                
                           }
                           else
                           {
                               veVideoRecordState = eH264RecIdle;
                               fprintf(stderr, "h264_file_create error\n");
                           }
                       }
                   }
                   //break;

                   case eH264RecActive:
                   {
                       if((bFirstIFrame==false) &amp;&amp;(packet.flags&amp;AV_PKT_FLAG_KEY)==AV_PKT_FLAG_KEY)
                       {
                           bFirstIFrame=true;
                           vPTS = packet.pts ;
                           vDTS = packet.dts ;
    #if 0
                           NSRunLoop *pRunLoop = [NSRunLoop currentRunLoop];
                           [pRunLoop addTimer:RecordingTimer forMode:NSDefaultRunLoopMode];
    #else
                           [NSTimer scheduledTimerWithTimeInterval:5.0//2.0
                                                            target:self
                                                          selector:@selector(StopRecording:)
                                                          userInfo:nil
                                                           repeats:NO];
    #endif
                       }

                       // Record audio when 1st i-Frame is obtained
                       if(bFirstIFrame==true)
                       {
                           if ( pFormatCtx_Record )
                           {
    #if PTS_DTS_IS_CORRECT==1
                               packet.pts = packet.pts - vPTS;
                               packet.dts = packet.dts - vDTS;

    #endif
                                   h264_file_write_frame( pFormatCtx_Record, packet.stream_index, packet.data, packet.size, packet.dts, packet.pts);

                           }
                           else
                           {
                               NSLog(@"pFormatCtx_Record no exist");
                           }
                       }
                   }
                   break;

                   case eH264RecClose:
                   {
                       if ( pFormatCtx_Record )
                       {
                           h264_file_close(pFormatCtx_Record);
    #if 0
                           // 20130607 Test
                           dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
                           {
                               ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
                               NSString *filePathString = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.mp4"];
                               NSURL *filePathURL = [NSURL fileURLWithPath:filePathString isDirectory:NO];
                               if(1)// ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:filePathURL])
                               {
                                   [library writeVideoAtPathToSavedPhotosAlbum:filePathURL completionBlock:^(NSURL *assetURL, NSError *error){
                                       if (error) {
                                           // TODO: error handling
                                           NSLog(@"writeVideoAtPathToSavedPhotosAlbum error");
                                       } else {
                                           // TODO: success handling
                                           NSLog(@"writeVideoAtPathToSavedPhotosAlbum success");
                                       }
                                   }];
                               }
                               [library release];
                           });
    #endif
                           vPTS = 0;
                           vDTS = 0;
                           vAudioPTS = 0;
                           vAudioDTS = 0;
                           pFormatCtx_Record = NULL;
                           NSLog(@"h264_file_close() is finished");
                       }
                       else
                       {
                           NSLog(@"fc no exist");
                       }
                       bFirstIFrame = false;
                       veVideoRecordState = eH264RecIdle;

                   }
                   break;

                   default:
                       if ( pFormatCtx_Record )
                       {
                           h264_file_close(pFormatCtx_Record);
                           pFormatCtx_Record = NULL;
                       }
                       NSLog(@"[ERROR] unexpected veVideoRecordState!!");
                       veVideoRecordState = eH264RecIdle;
                       break;
               }
           }

           // Decode video frame
           avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);
       }
       else if(packet.stream_index==audioStream)
       {
           // 20131024 albert.liao modfied start
           static int vPktCount=0;
           BOOL bIsAACADTS = FALSE;
           int ret = 0;

           if(aPlayer.vAACType == eAAC_UNDEFINED)
           {
               tAACADTSHeaderInfo vxAACADTSHeaderInfo = {0};
               bIsAACADTS = [AudioUtilities parseAACADTSHeader:(uint8_t *)packet.data ToHeader:&amp;vxAACADTSHeaderInfo];
           }

           @synchronized(aPlayer)
           {
               if(aPlayer==nil)
               {
                   aPlayer = [[AudioPlayer alloc]initAudio:nil withCodecCtx:(AVCodecContext *) pAudioCodecCtx];
                   NSLog(@"aPlayer initAudio");

                   if(bIsAACADTS)
                   {
                       aPlayer.vAACType = eAAC_ADTS;
                       //NSLog(@"is ADTS AAC");
                   }
               }
               else
               {
                   if(vPktCount&lt;5) // The voice is listened once image is rendered
                   {
                       vPktCount++;
                   }
                   else
                   {
                       if([aPlayer getStatus]!=eAudioRunning)
                       {
                           dispatch_async(dispatch_get_main_queue(), ^(void) {
                               @synchronized(aPlayer)
                               {
                                   NSLog(@"aPlayer start play");
                                   [aPlayer Play];
                               }

                           });
                       }
                   }
               }
           };

           @synchronized(aPlayer)
           {
               int ret = 0;

               ret = [aPlayer putAVPacket:&amp;packet];
               if(ret &lt;= 0)
                   NSLog(@"Put Audio Packet Error!!");

           }

           // 20131024 albert.liao modfied end

           if(bFirstIFrame==true)
           {
               switch(veVideoRecordState)
               {
                   case eH264RecActive:
                   {
                       if ( pFormatCtx_Record )
                       {
                           h264_file_write_audio_frame(pFormatCtx_Record, pAudioCodecCtx, packet.stream_index, packet.data, packet.size, packet.dts, packet.pts);

                       }
                       else
                       {
                           NSLog(@"pFormatCtx_Record no exist");
                       }
                   }
               }
           }
       }
       else
       {
           //fprintf(stderr, "packet len=%d, Byte=%02X%02X%02X%02X%02X\n",\
                   packet.size, packet.data[0],packet.data[1],packet.data[2],packet.data[3], packet.data[4]);
       }
       // 20130525 albert.liao modified end
    }
    return frameFinished!=0;
    }

    avformat_write_header :

    int h264_file_create(const char *pFilePath, AVFormatContext *fc, AVCodecContext *pCodecCtx,AVCodecContext *pAudioCodecCtx, double fps, void *p, int len )
    {
    int vRet=0;
    AVOutputFormat *of=NULL;
    AVStream *pst=NULL;
    AVCodecContext *pcc=NULL, *pAudioOutputCodecContext=NULL;

    avcodec_register_all();
    av_register_all();
    av_log_set_level(AV_LOG_VERBOSE);

    if(!pFilePath)
    {
       fprintf(stderr, "FilePath no exist");
       return -1;
    }

    if(!fc)
    {
       fprintf(stderr, "AVFormatContext no exist");
       return -1;
    }
    fprintf(stderr, "file=%s\n",pFilePath);

    // Create container
    of = av_guess_format( 0, pFilePath, 0 );
    fc->oformat = of;
    strcpy( fc->filename, pFilePath );

    // Add video stream
    pst = avformat_new_stream( fc, 0 );
    vVideoStreamIdx = pst->index;
    fprintf(stderr,"Video Stream:%d",vVideoStreamIdx);

    pcc = pst->codec;
    avcodec_get_context_defaults3( pcc, AVMEDIA_TYPE_VIDEO );

    // Save the stream as origin setting without convert
    pcc->codec_type = pCodecCtx->codec_type;
    pcc->codec_id = pCodecCtx->codec_id;
    pcc->bit_rate = pCodecCtx->bit_rate;
    pcc->width = pCodecCtx->width;
    pcc->height = pCodecCtx->height;

    if(fps==0)
    {
       double fps=0.0;
       AVRational pTimeBase;
       pTimeBase.num = pCodecCtx->time_base.num;
       pTimeBase.den = pCodecCtx->time_base.den;
       fps = 1.0/ av_q2d(pCodecCtx->time_base)/ FFMAX(pCodecCtx->ticks_per_frame, 1);
       fprintf(stderr,"fps_method(tbc): 1/av_q2d()=%g",fps);
       pcc->time_base.num = 1;
       pcc->time_base.den = fps;
    }
    else
    {
       pcc->time_base.num = 1;
       pcc->time_base.den = fps;
    }
    // reference ffmpeg\libavformat\utils.c

    // For SPS and PPS in avcC container
    pcc->extradata = malloc(sizeof(uint8_t)*pCodecCtx->extradata_size);
    memcpy(pcc->extradata, pCodecCtx->extradata, pCodecCtx->extradata_size);
    pcc->extradata_size = pCodecCtx->extradata_size;

    // For Audio stream
    if(pAudioCodecCtx)
    {
       AVCodec *pAudioCodec=NULL;
       AVStream *pst2=NULL;
       pAudioCodec = avcodec_find_encoder(AV_CODEC_ID_AAC);

       // Add audio stream
       pst2 = avformat_new_stream( fc, pAudioCodec );
       vAudioStreamIdx = pst2->index;
       pAudioOutputCodecContext = pst2->codec;
       avcodec_get_context_defaults3( pAudioOutputCodecContext, pAudioCodec );
       fprintf(stderr,"Audio Stream:%d",vAudioStreamIdx);
       fprintf(stderr,"pAudioCodecCtx->bits_per_coded_sample=%d",pAudioCodecCtx->bits_per_coded_sample);

       pAudioOutputCodecContext->codec_type = AVMEDIA_TYPE_AUDIO;
       pAudioOutputCodecContext->codec_id = AV_CODEC_ID_AAC;

       // Copy the codec attributes
       pAudioOutputCodecContext->channels = pAudioCodecCtx->channels;
       pAudioOutputCodecContext->channel_layout = pAudioCodecCtx->channel_layout;
       pAudioOutputCodecContext->sample_rate = pAudioCodecCtx->sample_rate;
       pAudioOutputCodecContext->bit_rate = 12000;//pAudioCodecCtx->sample_rate * pAudioCodecCtx->bits_per_coded_sample;
       pAudioOutputCodecContext->bits_per_coded_sample = pAudioCodecCtx->bits_per_coded_sample;
       pAudioOutputCodecContext->profile = pAudioCodecCtx->profile;
       //FF_PROFILE_AAC_LOW;
       // pAudioCodecCtx->bit_rate;

       // AV_SAMPLE_FMT_U8P, AV_SAMPLE_FMT_S16P
       //pAudioOutputCodecContext->sample_fmt = AV_SAMPLE_FMT_FLTP;//pAudioCodecCtx->sample_fmt;
       pAudioOutputCodecContext->sample_fmt = pAudioCodecCtx->sample_fmt;
       //pAudioOutputCodecContext->sample_fmt = AV_SAMPLE_FMT_U8;

       pAudioOutputCodecContext->sample_aspect_ratio = pAudioCodecCtx->sample_aspect_ratio;

       pAudioOutputCodecContext->time_base.num = pAudioCodecCtx->time_base.num;
       pAudioOutputCodecContext->time_base.den = pAudioCodecCtx->time_base.den;
       pAudioOutputCodecContext->ticks_per_frame = pAudioCodecCtx->ticks_per_frame;
       pAudioOutputCodecContext->frame_size = 1024;

       fprintf(stderr,"profile:%d, sample_rate:%d, channles:%d", pAudioOutputCodecContext->profile, pAudioOutputCodecContext->sample_rate, pAudioOutputCodecContext->channels);
       AVDictionary *opts = NULL;
       av_dict_set(&amp;opts, "strict", "experimental", 0);

       if (avcodec_open2(pAudioOutputCodecContext, pAudioCodec, &amp;opts) &lt; 0) {
           fprintf(stderr, "\ncould not open codec\n");
       }

       av_dict_free(&amp;opts);

    #if 0
       // For Audio, this part is no need
       if(pAudioCodecCtx->extradata_size!=0)
       {
           NSLog(@"extradata_size !=0");
           pAudioOutputCodecContext->extradata = malloc(sizeof(uint8_t)*pAudioCodecCtx->extradata_size);
           memcpy(pAudioOutputCodecContext->extradata, pAudioCodecCtx->extradata, pAudioCodecCtx->extradata_size);
           pAudioOutputCodecContext->extradata_size = pAudioCodecCtx->extradata_size;
       }
       else
       {
           // For WMA test only
           pAudioOutputCodecContext->extradata_size = 0;
           NSLog(@"extradata_size ==0");
       }
    #endif
    }

    if(fc->oformat->flags &amp; AVFMT_GLOBALHEADER)
    {
       pcc->flags |= CODEC_FLAG_GLOBAL_HEADER;
       pAudioOutputCodecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;
    }

    if ( !( fc->oformat->flags &amp; AVFMT_NOFILE ) )
    {
       vRet = avio_open( &amp;fc->pb, fc->filename, AVIO_FLAG_WRITE );
       if(vRet!=0)
       {
           fprintf(stderr,"avio_open(%s) error", fc->filename);
       }
    }

    // dump format in console
    av_dump_format(fc, 0, pFilePath, 1);

    vRet = avformat_write_header( fc, NULL );
    if(vRet==0)
       return 1;
    else
       return 0;
    }

    av_interleaved_write_frame :

    void h264_file_write_frame(AVFormatContext *fc, int vStreamIdx, const void* p, int len, int64_t dts, int64_t pts )
    {
       AVStream *pst = NULL;
       AVPacket pkt;

    if ( 0 > vVideoStreamIdx )
       return;

    // may be audio or video
    pst = fc->streams[ vStreamIdx ];

    // Init packet
    av_init_packet( &amp;pkt );

    if(vStreamIdx ==vVideoStreamIdx)
    {
       pkt.flags |= ( 0 >= getVopType( p, len ) ) ? AV_PKT_FLAG_KEY : 0;
       //pkt.flags |= AV_PKT_FLAG_KEY;
       pkt.stream_index = pst->index;
       pkt.data = (uint8_t*)p;
       pkt.size = len;


       pkt.dts = AV_NOPTS_VALUE;
       pkt.pts = AV_NOPTS_VALUE;

       // TODO: mark or unmark the log
       //fprintf(stderr, "dts=%lld, pts=%lld\n",dts,pts);
       // av_write_frame( fc, &amp;pkt );
    }
    av_interleaved_write_frame( fc, &amp;pkt );
    }

    av_write_trailer :

    void h264_file_close(AVFormatContext *fc)
    {
    if ( !fc )
       return;

    av_write_trailer( fc );


    if ( fc->oformat &amp;&amp; !( fc->oformat->flags &amp; AVFMT_NOFILE ) &amp;&amp; fc->pb )
       avio_close( fc->pb );

    av_free( fc );
    }

    Thanks.