before patched: [root@localhost ffmpeg]# ./ffmpeg_g -re -i /root/facebook.mp4 -c copy -f hls -v verbose -y aaaa.m3u8 ffmpeg version N-80779-gb18d6c5 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17) configuration: --prefix=/usr/ --libdir=/usr/lib64 --enable-libx264 --enable-libfaac --enable-gpl --enable-nonfree libavutil 55. 27.100 / 55. 27.100 libavcodec 57. 48.101 / 57. 48.101 libavformat 57. 40.101 / 57. 40.101 libavdevice 57. 0.102 / 57. 0.102 libavfilter 6. 46.102 / 6. 46.102 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 1.100 / 2. 1.100 libpostproc 54. 0.100 / 54. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/root/facebook.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.34.103 Duration: 00:45:45.64, start: 0.000000, bitrate: 1530 kb/s Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p, 720x528 [SAR 1:1 DAR 15:11], 1141 kb/s, 25 fps, 25 tbr, 16k tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s (default) Metadata: handler_name : SoundHandler Side data: audio service type: main [hls @ 0x2e49540] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. Last message repeated 1 times [mpegts @ 0x2e457a0] muxrate VBR, pcr every 5 pkts, sdt every 2147483647, pat/pmt every 2147483647 pkts Output #0, hls, to 'aaaa.m3u8': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.40.101 Stream #0:0(und): Video: h264, 1 reference frame (avc1 / 0x31637661), yuv420p, 720x528 (0x0) [SAR 1:1 DAR 15:11], q=2-31, 1141 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), 384 kb/s (default) Metadata: handler_name : SoundHandler Side data: audio service type: main Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help [mpegts @ 0x2e457a0] H.264 bitstream malformed, no startcode found, use the video bitstream filter 'h264_mp4toannexb' to fix it ('-bsf:v h264_mp4toannexb' option with ffmpeg) av_interleaved_write_frame(): Invalid data found when processing input No more output streams to write to, finishing. [mpegts @ 0x2e457a0] H.264 bitstream malformed, no startcode found, use the video bitstream filter 'h264_mp4toannexb' to fix it ('-bsf:v h264_mp4toannexb' option with ffmpeg) [hls @ 0x2e49540] EXT-X-MEDIA-SEQUENCE:0 Error writing trailer of aaaa.m3u8: Invalid data found when processing inputframe= 3 fps=0.0 q=-1.0 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=1.42x video:18kB audio:2kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown Input file #0 (/root/facebook.mp4): Input stream #0:0 (video): 3 packets read (18793 bytes); Input stream #0:1 (audio): 1 packets read (1536 bytes); Total: 4 packets (20329 bytes) demuxed Output file #0 (aaaa.m3u8): Output stream #0:0 (video): 3 packets muxed (18793 bytes); Output stream #0:1 (audio): 1 packets muxed (1536 bytes); Total: 4 packets (20329 bytes) muxed Conversion failed!
after patched: [root@localhost ffmpeg]# ./ffmpeg_g -re -i /root/facebook.mp4 -c copy -f hls -v verbose -y aaaa.m3u8 ffmpeg version N-80779-gb18d6c5 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17) configuration: --prefix=/usr/ --libdir=/usr/lib64 --enable-libx264 --enable-libfaac --enable-gpl --enable-nonfree libavutil 55. 27.100 / 55. 27.100 libavcodec 57. 48.101 / 57. 48.101 libavformat 57. 40.101 / 57. 40.101 libavdevice 57. 0.102 / 57. 0.102 libavfilter 6. 46.102 / 6. 46.102 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 1.100 / 2. 1.100 libpostproc 54. 0.100 / 54. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/root/facebook.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.34.103 Duration: 00:45:45.64, start: 0.000000, bitrate: 1530 kb/s Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p, 720x528 [SAR 1:1 DAR 15:11], 1141 kb/s, 25 fps, 25 tbr, 16k tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s (default) Metadata: handler_name : SoundHandler Side data: audio service type: main [hls @ 0x3dfa540] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. Last message repeated 1 times [mpegts @ 0x3df67a0] muxrate VBR, pcr every 5 pkts, sdt every 2147483647, pat/pmt every 2147483647 pkts Output #0, hls, to 'aaaa.m3u8': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.40.101 Stream #0:0(und): Video: h264, 1 reference frame (avc1 / 0x31637661), yuv420p, 720x528 (0x0) [SAR 1:1 DAR 15:11], q=2-31, 1141 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), 384 kb/s (default) Metadata: handler_name : SoundHandler Side data: audio service type: main Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help Automatically inserted bitstream filter 'h264_mp4toannexb'; args='' [hls @ 0x3dfa540] EXT-X-MEDIA-SEQUENCE:0=00:00:01.56 bitrate=N/A speed=1.03x frame= 46 fps= 27 q=-1.0 Lsize=N/A time=00:00:01.76 bitrate=N/A speed=1.02x video:175kB audio:82kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown Input file #0 (/root/facebook.mp4): Input stream #0:0 (video): 46 packets read (179629 bytes); Input stream #0:1 (audio): 55 packets read (84480 bytes); Total: 101 packets (264109 bytes) demuxed Output file #0 (aaaa.m3u8): Output stream #0:0 (video): 46 packets muxed (179629 bytes); Output stream #0:1 (audio): 55 packets muxed (84480 bytes); Total: 101 packets (264109 bytes) muxed Signed-off-by: LiuQi <li...@gosun.com> --- libavformat/hlsenc.c | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index a9fa5d8..dcf2002 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -267,7 +267,7 @@ static int hls_encryption_start(AVFormatContext *s) static int hls_mux_init(AVFormatContext *s) { HLSContext *hls = s->priv_data; - AVFormatContext *oc; + AVFormatContext *oc = hls->avf; AVFormatContext *vtt_oc = NULL; int i, ret; @@ -633,7 +633,7 @@ fail: return err; } -static int hls_write_header(AVFormatContext *s) +static int hls_init(AVFormatContext *s) { HLSContext *hls = s->priv_data; int ret, i; @@ -903,6 +903,26 @@ static int hls_write_trailer(struct AVFormatContext *s) return 0; } +static int hls_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) +{ + HLSContext *hls = s->priv_data; + AVFormatContext *oc = hls->avf; + if (oc->oformat->check_bitstream) { + int ret = oc->oformat->check_bitstream(oc, pkt); + if (ret == 1) { + AVStream *st = s->streams[pkt->stream_index]; + AVStream *ost = oc->streams[pkt->stream_index]; + st->internal->bsfcs = ost->internal->bsfcs; + st->internal->nb_bsfcs = ost->internal->nb_bsfcs; + ost->internal->bsfcs = NULL; + ost->internal->nb_bsfcs = 0; + } + return ret; + } + return 1; +} + + #define OFFSET(x) offsetof(HLSContext, x) #define E AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@ -950,8 +970,9 @@ AVOutputFormat ff_hls_muxer = { .video_codec = AV_CODEC_ID_H264, .subtitle_codec = AV_CODEC_ID_WEBVTT, .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH, - .write_header = hls_write_header, + .init = hls_init, .write_packet = hls_write_packet, .write_trailer = hls_write_trailer, + .check_bitstream = hls_check_bitstream, .priv_class = &hls_class, }; -- 1.7.1
0001-Automatically-inserted-bitstream-filter-h264_mp4toan.patch
Description: Binary data
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel