diff --git a/modules/access_output/Modules.am b/modules/access_output/Modules.am
index de6c5b5..6b12fd4 100644
--- a/modules/access_output/Modules.am
+++ b/modules/access_output/Modules.am
@@ -1,4 +1,5 @@
 SOURCES_access_output_dummy = dummy.c
+SOURCES_access_output_livehttp = livehttp.c
 SOURCES_access_output_file = file.c
 SOURCES_access_output_udp = udp.c
 SOURCES_access_output_http = http.c bonjour.c bonjour.h
@@ -15,6 +16,7 @@ libaccess_output_rtmp_plugin_la_DEPENDENCIES =
 
 libvlc_LTLIBRARIES += \
 	libaccess_output_dummy_plugin.la \
+	libaccess_output_livehttp_plugin.la \
 	libaccess_output_file_plugin.la \
 	libaccess_output_udp_plugin.la \
 	libaccess_output_http_plugin.la \
diff --git a/modules/access_output/livehttp.c b/modules/access_output/livehttp.c
new file mode 100644
index 0000000..02c1745
--- /dev/null
+++ b/modules/access_output/livehttp.c
@@ -0,0 +1,581 @@
+/*****************************************************************************
+ * file.c
+ *****************************************************************************
+ * Copyright (C) 2001, 2002 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Laurent Aimar <fenrir@via.ecp.fr>
+ *          Eric Petit <titer@videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <time.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_sout.h>
+#include <vlc_block.h>
+#include <vlc_fs.h>
+#include <vlc_strings.h>
+#include <vlc_charset.h>
+#if defined( WIN32 ) && !defined( UNDER_CE )
+#   include <io.h>
+#   define lseek _lseeki64
+#else
+#   include <unistd.h>
+#endif
+
+#ifndef O_LARGEFILE
+#   define O_LARGEFILE 0
+#endif
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int  Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
+#define TMP_IDX_SUFFIX ".tmp"
+#define STR_ENDLIST "#EXT-X-ENDLIST\n"
+
+#define SOUT_CFG_PREFIX "sout-livehttp-"
+#define SEGLEN_TEXT N_("Segment length")
+#define SEGLEN_LONGTEXT N_( "Length of ts stream segments") 
+
+#define SPLITANYWHERE_TEXT N_("Split segments anywhere")
+#define SPLITANYWHERE_LONGTEXT N_( "Don't require a keyframe before splitting "\
+                                "a segment. Neede for audio only.") 
+
+#define NUMSEGS_TEXT N_("Number of segments")
+#define NUMSEGS_LONGTEXT N_( "Number of segments to include in index") 
+
+#define INDEX_TEXT N_("Index file")
+#define INDEX_LONGTEXT N_( "Path to the index file to create") 
+
+#define INDEXURL_TEXT N_("Full url to put in index file")
+#define INDEXURL_LONGTEXT N_( "Full url to put in index file. "\
+                          "Use #'s to represent segment number")
+
+#define DELSEGS_TEXT N_("Delete segments")
+#define DELSEGS_LONGTEXT N_( "Delete segments when they are no longer ") 
+
+#define RATECONTROL_TEXT N_("Use muxers rate control mechanism")
+#define RATECONTROL_LONGTEXT N_( "Use muxers rate control mechanism") 
+
+
+
+vlc_module_begin ()
+    set_description( N_("File stream output") )
+    set_shortname( N_("LiveHTTP" ))
+    add_shortcut( "livehttp" )
+    set_capability( "sout access", 50 )
+    set_category( CAT_SOUT )
+    set_subcategory( SUBCAT_SOUT_ACO )
+    add_integer( SOUT_CFG_PREFIX "seglen", 10, NULL, SEGLEN_TEXT, SEGLEN_LONGTEXT, true )
+
+    add_integer( SOUT_CFG_PREFIX "numsegs", 0, NULL, NUMSEGS_TEXT, NUMSEGS_LONGTEXT, true )
+    add_bool( SOUT_CFG_PREFIX "splitanywhere", false, NULL,
+              SPLITANYWHERE_TEXT, SPLITANYWHERE_LONGTEXT, true)
+    add_bool( SOUT_CFG_PREFIX "delsegs", true, NULL,
+              DELSEGS_TEXT, DELSEGS_LONGTEXT, true)
+    add_bool( SOUT_CFG_PREFIX "ratecontrol", false, NULL,
+              RATECONTROL_TEXT, RATECONTROL_LONGTEXT, true)
+
+    add_string( SOUT_CFG_PREFIX "index", NULL, NULL,
+                INDEX_TEXT, INDEX_LONGTEXT, true )
+    add_string( SOUT_CFG_PREFIX "index-url", NULL, NULL,
+                INDEXURL_TEXT, INDEXURL_LONGTEXT, true )
+
+    set_callbacks( Open, Close )
+vlc_module_end ()
+
+
+/*****************************************************************************
+ * Exported prototypes
+ *****************************************************************************/
+static const char *const ppsz_sout_options[] = {
+    "seglen",
+    "splitanywhere",
+    "numsegs",
+    "delsegs",
+    "index",
+    "index-url",
+    "ratecontrol",
+    NULL
+};
+
+static ssize_t Write( sout_access_out_t *, block_t * );
+static int Seek ( sout_access_out_t *, off_t  );
+static ssize_t Read ( sout_access_out_t *, block_t * );
+static int Control( sout_access_out_t *, int, va_list );
+
+struct sout_access_out_sys_t
+{
+    int i_handle;
+    bool b_splitanywhere;
+    int i_segment;
+    mtime_t i_opendts;
+    int  i_seglen;
+    mtime_t  i_seglenm;
+    char *psz_cursegPath;
+    char *psz_indexPath;
+    char *psz_indexUrl;
+    int  i_numsegs;
+    bool b_delsegs;
+    bool b_ratecontrol;
+};
+
+/*****************************************************************************
+ * Open: open the file
+ *****************************************************************************/
+static int Open( vlc_object_t *p_this )
+{
+    sout_access_out_t   *p_access = (sout_access_out_t*)p_this;
+    sout_access_out_sys_t *p_sys;    
+    char *psz_idx;
+
+    config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
+
+    if( !p_access->psz_path )
+    {
+        msg_Err( p_access, "no file name specified" );
+        return VLC_EGENERIC;
+    }
+
+    p_access->pf_write = Write;
+    p_access->pf_read  = Read;
+    p_access->pf_seek  = Seek;
+    p_access->pf_control = Control;
+    if( !( p_sys = malloc ( sizeof( *p_sys ) ) ) )
+        return VLC_ENOMEM;
+
+    p_sys->i_seglen = var_GetInteger( p_access, SOUT_CFG_PREFIX "seglen");
+    p_sys->i_seglenm = UINT64_C(1000000) * p_sys->i_seglen;
+
+    p_sys->i_numsegs = var_GetInteger( p_access, SOUT_CFG_PREFIX "numsegs");
+    p_sys->b_splitanywhere = var_GetBool( p_access, SOUT_CFG_PREFIX "splitanywhere");
+    p_sys->b_delsegs = var_GetBool( p_access, SOUT_CFG_PREFIX "delsegs");
+    p_sys->b_ratecontrol = var_GetBool( p_access, SOUT_CFG_PREFIX "ratecontrol");
+
+    p_sys->psz_indexPath = 0;
+    p_sys->psz_indexUrl = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX"index-url" );
+ 
+    psz_idx = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX"index" );
+    if ( psz_idx )
+    {
+        char *psz_tmp = str_format( p_access, psz_idx );
+        path_sanitize( psz_tmp );
+        p_sys->psz_indexPath = psz_tmp;
+        vlc_unlink(p_sys->psz_indexPath);
+    }
+
+    p_access->p_sys = p_sys;
+    p_sys->i_handle = -1;
+    p_sys->i_segment = 0;
+    p_sys->psz_cursegPath = 0;
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * formatSegmentPath: create segment path name based on seg # 
+ *****************************************************************************/
+static char *formatSegmentPath(sout_access_out_t *p_access, char *psz_path, int i_seg, bool b_sanitize)
+{
+    char *psz_tmp = str_format( p_access, psz_path );
+    char *p1, *p2;
+    p1 = psz_tmp;
+    while(*p1 && *p1 != '#')
+        p1++;
+    if (*p1) {
+        p2 = p1+1;
+        while(*p2 && *p2 == '#')
+            p2++;
+        int numcnt = p2 - p1;
+        char *segstr;
+        if (asprintf(&segstr, "%0*d", numcnt, i_seg) < 0)
+        {
+            free(psz_tmp);
+            return NULL;
+        }
+        char *psz_tmp2;
+        *p1 = '\0';
+        int ret = asprintf(&psz_tmp2, "%s%s%s", psz_tmp, segstr, p2);
+        free(psz_tmp);
+        if (ret < 0) 
+            return NULL;
+        psz_tmp =psz_tmp2;            
+    }
+        
+    if (b_sanitize)
+        path_sanitize( psz_tmp);    
+
+    return psz_tmp;
+}
+
+#ifdef WIN32
+static int convert_path (const char *restrict path, wchar_t *restrict wpath)
+{
+    if (!MultiByteToWideChar (CP_UTF8, 0, path, -1, wpath, MAX_PATH))
+    {
+        errno = ENOENT;
+        return -1;
+    }
+    wpath[MAX_PATH] = L'\0';
+    return 0;
+}
+# define CONVERT_PATH(path, wpath, err) \
+  wchar_t wpath[MAX_PATH+1]; \
+  if (convert_path (path, wpath)) \
+      return (err)
+#endif
+
+/**
+ * Moves a file atomically. This only works within a single file system.
+ *
+ * @param oldpath path to the file before the move
+ * @param newpath intended path to the file after the move
+ * @return A 0 return value indicates success. A -1 return value indicates an
+ *        error, and an error code is stored in errno
+ */
+static int prv_vlc_rename (const char *oldpath, const char *newpath)
+{
+#if defined (WIN32)
+    CONVERT_PATH (oldpath, wold, -1);
+    CONVERT_PATH (newpath, wnew, -1);
+# ifdef UNDER_CE
+    /* FIXME: errno support */
+    if (MoveFileW (wold, wnew))
+        return 0;
+    else
+        return -1;
+#else
+    /*  _wrename does not seem to be returning an error even when it fails
+        because the file already exists, so we can't try it first as we
+        would like to do.  (so it set's errno correctly...)
+   
+    if (!_wrename (wold, wnew))
+        return 0;
+    if (errno != EEXIST)
+        return -1;
+    */
+
+    /* Try again if it already existed using native call */
+    if (MoveFileExW(wold, wnew, MOVEFILE_REPLACE_EXISTING))
+    {
+        return 0;
+    }
+    /* There was an error, we should probably set errno more appropriately
+       but this should do for now... */
+    errno = EIO; 
+    return -1;
+#endif
+
+#endif
+    const char *lo = ToLocale (oldpath);
+    if (lo == NULL)
+        goto error;
+
+    const char *ln = ToLocale (newpath);
+    if (ln == NULL)
+    {
+        LocaleFree (lo);
+error:
+        errno = ENOENT;
+        return -1;
+    }
+
+    int ret = rename (lo, ln);
+    LocaleFree (lo);
+    LocaleFree (ln);
+    return ret;
+}
+
+  
+/************************************************************************
+ * updateIndexAndDel: If necessary, update index file & delete old segments
+ ************************************************************************/
+static int updateIndexAndDel( sout_access_out_t *p_access, sout_access_out_sys_t *p_sys, bool b_isend )
+{
+
+    int i_firstseg;
+
+    if (p_sys->i_numsegs == 0)
+        i_firstseg = 1;
+    else
+        i_firstseg = (p_sys->i_segment - p_sys->i_numsegs) + 1;
+    if (i_firstseg < 1)
+        i_firstseg = 1;
+
+    // First update index
+    if (p_sys->psz_indexPath)
+    {
+        int val;
+        char *psz_buf;
+        int fd;
+        char *psz_idxTmp = malloc(strlen(p_sys->psz_indexPath) + strlen(TMP_IDX_SUFFIX) + 1);
+        if (!psz_idxTmp)
+            return -1;
+        strcpy(psz_idxTmp, p_sys->psz_indexPath);
+        strcpy(psz_idxTmp + strlen(psz_idxTmp), TMP_IDX_SUFFIX);
+        vlc_unlink(psz_idxTmp);
+
+        fd = vlc_open(psz_idxTmp, O_RDWR | O_CREAT | O_LARGEFILE |
+                     O_TRUNC, 0666 );
+        if (fd == -1)
+        {
+            msg_Err( p_access, "cannot open index file `%s' (%m)", psz_idxTmp);
+            free( psz_idxTmp );
+            return -1;
+        }
+        if (asprintf(&psz_buf, "#EXTM3U\n#EXT-X-TARGETDURATION:%d\n#EXT-X-MEDIA-SEQUENCE:%d\n", p_sys->i_seglen, i_firstseg) < 0)
+        {
+            free( psz_idxTmp );
+            close( fd );
+            return -1;
+        }
+       
+        val = write (fd, psz_buf, strlen(psz_buf));
+        free(psz_buf);
+        if (val < 0)
+        {
+            free( psz_idxTmp );
+            close( fd ) ;
+            return -1;
+        }
+        char *psz_idxFormat = p_sys->psz_indexUrl ? p_sys->psz_indexUrl : p_access->psz_path;
+        
+        for (int i=i_firstseg;i<=p_sys->i_segment;i++)
+        {
+            char *psz_name = formatSegmentPath(p_access, psz_idxFormat, i, false);
+            if (psz_name == NULL || asprintf(&psz_buf, "#EXTINF:%d\n%s", p_sys->i_seglen, psz_name) < 0)
+            {
+                free( psz_idxTmp );
+                close( fd );
+                return -1;
+            }
+            val = write(fd, psz_buf, strlen(psz_buf));
+            if (val >= 0)
+                write(fd, "\n", strlen("\n"));
+            free(psz_buf);
+            free(psz_name);
+            if (val < 0)
+            {
+                free( psz_idxTmp );
+                close( fd ) ;
+                return -1;
+            }
+        }
+
+        if (b_isend)
+        {
+            val = write(fd,  STR_ENDLIST,  strlen(STR_ENDLIST));
+            if (val < 0)
+            {
+                free( psz_idxTmp );
+                close( fd ) ;
+                return -1;
+            }
+ 
+        }
+        close(fd);
+        val = -1;
+        for (int i=0;i<10 && val < 0;i++) 
+        {
+            val = prv_vlc_rename(psz_idxTmp, p_sys->psz_indexPath);
+            if (val < 0)
+                msleep(1000*100);
+        }
+        if (val < 0)
+            msg_Err(p_access, "Error moving LiveHttp index file");
+        free(psz_idxTmp);
+    }
+ 
+    // Then take care of deletion
+    if (p_sys->b_delsegs && i_firstseg > 1)
+    {
+        char *psz_name = formatSegmentPath(p_access, p_access->psz_path, i_firstseg-1, true);
+         if ( psz_name )
+         {
+             vlc_unlink(psz_name);
+             free( psz_name );
+         }
+    }
+    return 0;
+}
+/*****************************************************************************
+ * closeCurrentSegment: Open the segment file
+ *****************************************************************************/
+static void closeCurrentSegment( sout_access_out_t *p_access, sout_access_out_sys_t *p_sys, bool b_isend )
+{
+    if (p_sys->i_handle >= 0) {
+        close(p_sys->i_handle);
+        p_sys->i_handle = -1;
+        if (p_sys->psz_cursegPath) 
+        {        
+            msg_Info( p_access, "LiveHttpSegmentComplete: %s (%d)" , p_sys->psz_cursegPath, p_sys->i_segment); 
+            free(p_sys->psz_cursegPath);
+            p_sys->psz_cursegPath = 0;
+            updateIndexAndDel( p_access, p_sys, b_isend );
+        }
+    }
+}
+
+/*****************************************************************************
+ * Close: close the target
+ *****************************************************************************/
+static void Close( vlc_object_t * p_this )
+{
+    sout_access_out_t *p_access = (sout_access_out_t*)p_this;
+    sout_access_out_sys_t *p_sys = p_access->p_sys;
+
+
+    closeCurrentSegment( p_access, p_sys, true );
+    if (p_sys->psz_indexPath)
+        free( p_sys->psz_indexPath);
+    free(p_sys);
+
+    msg_Dbg( p_access, "file access output closed" );
+}
+
+static int Control( sout_access_out_t *p_access, int i_query, va_list args )
+{
+    sout_access_out_sys_t *p_sys = p_access->p_sys;
+    
+    switch( i_query )
+    {
+        case ACCESS_OUT_CONTROLS_PACE:
+        {
+            bool *pb = va_arg( args, bool * );
+            *pb = !p_sys->b_ratecontrol;
+            //*pb = true;
+            break;
+        }
+
+        default:
+            return VLC_EGENERIC;
+    }
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Read: standard read on a file descriptor.
+ *****************************************************************************/
+static ssize_t Read( sout_access_out_t *p_access, block_t *p_buffer )
+{
+    (void) p_buffer;
+    (void)p_access;
+    msg_Err( p_access, "livehttp sout access cannot read" );
+    return -1;
+}
+
+/*****************************************************************************
+ * openNextFile: Open the segment file
+ *****************************************************************************/
+static ssize_t openNextFile( sout_access_out_t *p_access, sout_access_out_sys_t *p_sys )
+{
+    int fd;
+   
+    int i_newseg = p_sys->i_segment + 1; 
+
+    char *psz_seg = formatSegmentPath(p_access, p_access->psz_path, i_newseg, true);
+    if ( !psz_seg )
+        return -1;
+
+    fd = vlc_open( psz_seg, O_RDWR | O_CREAT | O_LARGEFILE |
+                     O_TRUNC, 0666 );
+    if (fd == -1)
+    {
+        msg_Err( p_access, "cannot open `%s' (%m)", psz_seg);
+        free( psz_seg );
+        return -1;
+    }
+    
+    msg_Dbg( p_access, "Successfully opened livehttp file: %s (%d)" , psz_seg, i_newseg);
+
+    //free( psz_seg );
+    p_sys->psz_cursegPath = psz_seg;
+    p_sys->i_handle = fd;
+    p_sys->i_segment = i_newseg;
+    return fd;
+}
+/*****************************************************************************
+ * Write: standard write on a file descriptor.
+ *****************************************************************************/
+static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
+{
+    size_t i_write = 0;
+    sout_access_out_sys_t *p_sys = p_access->p_sys;    
+
+    while( p_buffer )
+    {
+        //msg_Dbg(p_access, "Flags: %d, Dts: %"PRId64"", p_buffer->i_flags, p_buffer->i_dts);
+        if (p_sys->i_handle >= 0 && (p_sys->b_splitanywhere || (p_buffer->i_flags & BLOCK_FLAG_TYPE_I)) && (p_buffer->i_dts-p_sys->i_opendts) > p_sys->i_seglenm)
+        {
+            closeCurrentSegment( p_access, p_sys, false );
+        }
+        if (p_buffer->i_buffer > 0 && p_sys->i_handle < 0) 
+        {
+            p_sys->i_opendts = p_buffer->i_dts;            
+            if (openNextFile(p_access, p_sys) < 0)
+                return -1;            
+        }
+        ssize_t val = write (p_sys->i_handle,
+                             p_buffer->p_buffer, p_buffer->i_buffer);
+        if (val == -1)
+        {
+            if (errno == EINTR)
+                continue;
+            block_ChainRelease (p_buffer);
+            return -1;
+        }
+
+        if ((size_t)val >= p_buffer->i_buffer)
+        {
+            block_t *p_next = p_buffer->p_next;
+            block_Release (p_buffer);
+            p_buffer = p_next;
+        }
+        else
+        {
+            p_buffer->p_buffer += val;
+            p_buffer->i_buffer -= val;
+        }
+        i_write += val;
+    }
+    return i_write;
+}
+
+/*****************************************************************************
+ * Seek: seek to a specific location in a file
+ *****************************************************************************/
+static int Seek( sout_access_out_t *p_access, off_t i_pos )
+{
+    (void) i_pos;
+    msg_Err( p_access, "livehttp sout access cannot seek" );
+    return -1;
+}
diff --git a/modules/mux/mpeg/ts.c b/modules/mux/mpeg/ts.c
index 34e4e3e..893140e 100644
--- a/modules/mux/mpeg/ts.c
+++ b/modules/mux/mpeg/ts.c
@@ -2019,6 +2019,12 @@ static block_t *TSNew( sout_mux_t *p_mux, ts_stream_t *p_stream,
     }
 
     p_ts = block_New( p_mux, 188 );
+
+    if (b_new_pes && !(p_pes->i_flags & BLOCK_FLAG_NO_KEYFRAME) && p_pes->i_flags & BLOCK_FLAG_TYPE_I)
+    {
+        p_ts->i_flags |= BLOCK_FLAG_TYPE_I;
+    }
+
     p_ts->i_dts = p_pes->i_dts;
 
     p_ts->p_buffer[0] = 0x47;

