[FFmpeg-devel] avformat/avienc: add check bitstream method

Submitted by Steven Liu on Jan. 5, 2018, 8:13 a.m.

Details

Message ID 20180105081349.619-1-lq@chinaffmpeg.org
State New
Headers show

Commit Message

Steven Liu Jan. 5, 2018, 8:13 a.m.
rename mpegts_check_bitstream to ff_check_bitstream
fix problem: remux from mp4(AVC Codec) to avi(AVC Codec)
error message:
[avi @ 0x7fac97003c00] H.264 bitstream malformed, no startcode found,
use the video bitstream filter 'h264_mp4toannexb' to fix
it ('-bsf:v h264_mp4toannexb' option with ffmpeg)

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/avienc.c    | 1 +
 libavformat/mpegts.h    | 5 +++++
 libavformat/mpegtsenc.c | 4 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

Comments

Hendrik Leppkes Jan. 5, 2018, 9 a.m.
On Fri, Jan 5, 2018 at 9:13 AM, Steven Liu <lq@chinaffmpeg.org> wrote:
> rename mpegts_check_bitstream to ff_check_bitstream
> fix problem: remux from mp4(AVC Codec) to avi(AVC Codec)
> error message:
> [avi @ 0x7fac97003c00] H.264 bitstream malformed, no startcode found,
> use the video bitstream filter 'h264_mp4toannexb' to fix
> it ('-bsf:v h264_mp4toannexb' option with ffmpeg)
>

There are several issues with this patch -

The function naming and description is way too generic, it doesn't
indicate at all what it does - but lets skip that for now, since I
believe there are much bigger issues.
Secondly, avi and mpegts are very different formats, and probably
should not share such a function.

mpegts always needs AnnexB format, avi can actually "support" (and I
use that word losely, H264 in AVI is always a hack) both MP4-style and
AnnexB, which means AVI doesn't really need the BSF at all.
In AVI, you need to properly write a matching codec_tag however, H264
for AnnexB, and AVC1 for MP4-style  - if that is not being done, then
this should be fixed, and not a BSF being forced.

- Hendrik

Patch hide | download patch | download mbox

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index ac0f04c354..a8782ef292 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -1002,6 +1002,7 @@  AVOutputFormat ff_avi_muxer = {
     .write_header   = avi_write_header,
     .write_packet   = avi_write_packet,
     .write_trailer  = avi_write_trailer,
+    .check_bitstream = ff_check_bitstream,
     .codec_tag      = (const AVCodecTag * const []) {
         ff_codec_bmp_tags, ff_codec_wav_tags, 0
     },
diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 272e2be4f7..96610ee0a6 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -114,4 +114,9 @@  int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
  */
 int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt);
 
+/**
+ * Check bitstream of stream
+ * @return <0 to stop processing
+ */
+int ff_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt);
 #endif /* AVFORMAT_MPEGTS_H */
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index fdfa544ee2..866615f620 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1846,7 +1846,7 @@  static void mpegts_deinit(AVFormatContext *s)
     av_freep(&ts->services);
 }
 
-static int mpegts_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
+int ff_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
 {
     int ret = 1;
     AVStream *st = s->streams[pkt->stream_index];
@@ -1982,7 +1982,7 @@  AVOutputFormat ff_mpegts_muxer = {
     .write_packet   = mpegts_write_packet,
     .write_trailer  = mpegts_write_end,
     .deinit         = mpegts_deinit,
-    .check_bitstream = mpegts_check_bitstream,
+    .check_bitstream = ff_check_bitstream,
     .flags          = AVFMT_ALLOW_FLUSH | AVFMT_VARIABLE_FPS,
     .priv_class     = &mpegts_muxer_class,
 };