[FFmpeg-devel] [PATCH]flvenc Allow ffmpeg -copy on rtmp outputs from udp inputs

Tudor SUCIU tudor.suciu at gmail.com
Mon Jun 9 01:27:28 CEST 2014


you said similar code is in the mp4 muxer and i see similar code in

> matroskadec line 1820
>
> I think the code from matroskadec is not reusable, there are no strings to
parse that I know of (at flvenc level).


> I think factorizing all these instances from libavformat into a
> single case if possible should happen.
> I suggest this also because the code in matroskadec considers
> profile and SBR, which your code ignores
>
> I don't have access immediately to Flash Media Encoder 3, but if I
remember correctly it sends only 2 bytes of extradata for he-aacv2. As fmle
3.0 is the reference software for flv, i'll modify the patch if it sends
more than 2 bytes of extradata.
The problem at flvenc level is that in the case of ffmpeg -copy the audio
profile is "-99" so I couldn't extract it. This is why the code is for the
time being working only with AAC-LC.
I totally agree that this code is present in a little too many places. I'm
not sure that I would be able to make the required changes by myself. With
ffmpeg i'm used to make the smallest changes that allow me to maintain
patches over long periods of time. I would gladly update this patch when
somebody fixes the implementation of one other muxer/decoder and adds the
relevant code in a common place.


> also muxers should not write to the extradata field of AVCodecContext
> a local variable seems more correct
>
There is no problem, i can do that.


> and then please see libavcodec/aac_adtstoasc_bsf.c and check if
> using it would fix the issue you are trying to fixe
>
This filter is required, if i don't specify it i get:
[flv @ 0x2ab0700] Malformed AAC bitstream detected: use audio bitstream
filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)
av_interleaved_write_frame(): Invalid data found when processing input
I remember that a few years ago when i worked on an hds segmenter ffmpeg
didn't complain and the adts headers were being sent into the flv. It did
break part of the players, it's a good thing it's corrected now.
The bug is clearly the fact that the audio bitstream filter is called after
the creation of flv header. I have absolutely no idea how to fix it.


> and please provide a sample and commandline (testcase)
>
I wanted to play with cc608 subtitles, so I got the hls files from
http://www.cpcweb.com/webcasts/webcast_samples.htm.
I concatenated .ts files from the .m3u8, then (any .ts file will do):
./ffmpeg -i ~/Downloads/testhls/test.ts -acodec copy -vcodec copy -bsf:a
aac_adtstoasc -bsf:v remove_extra -f flv test.flv
The video bitstream filter fixes all the visible problems from the rtmp
stream, there are only some AUD h264 nals that remain, it would be nice if
we could delete them too.

to generate the offending he-aacv2 file:
./ffmpeg -i test.ts -vcodec copy -acodec libaacplus -ar 48k -ac 2 -ab 47900
test2.ts

the only way to create a correct mp4 file out of this that i have found:
 MP4Box -add test2.ts test2.mp4

Conclusions:
I was not able to ffmpeg -acodec copy -vcodec copy a file with he-aac2 into
.flv, mp4, mkv, so it's not only my patch, it's all the implementations
that seem to get it wrong.
The bitstream filter adtstoasc correctly sets the extradata, but it's toooo
late.
MP4Box works well (including not inserting AUD nals).
A patched flvenc the generate for example 0x13 0x10 aac extradata works
correctly.

I would suggest to bring flvencoder up to the same level of functionality
as the others and fix the he-aac bugs afther that.
The piece of code that detects the audio rate and audio channels should
also initialize the extradata. This would finally render this patch useless.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flvcopyextradatafix3.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140609/49e82f41/attachment.bin>


More information about the ffmpeg-devel mailing list