Can stream to Facebook using ffmpeg but not when using tee - facebook

I'm trying to stream to YouTube and Facebook simultaneously using ffmpeg.
I can do them individually, but I want to use "tee" to send the results of encoding to two places.
If I do:
ffmpeg -re -i pipe:0 -acodec libfdk_aac -bsf:a aac_adtstoasc \
-ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline \
-s 720x480 -bufsize 2048k -vb 1300k -maxrate 4000k -deinterlace \
-vcodec libx264 -g 25 -r 25 \
-f flv "rtmp://rtmp-api.facebook.com:80/rtmp/key"
It works just fine.
But if I do:
ffmpeg -re -i pipe:0 -acodec libfdk_aac -bsf:a aac_adtstoasc \
-ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline \
-s 720x480 -bufsize 2048k -vb 1300k -maxrate 4000k -deinterlace \
-vcodec libx264 -g 25 -r 25 \
-f tee -map 0:v -map 0:a \
"[f=flv]rtmp://rtmp-api.facebook.com:80/rtmp/key"
Then I get a rtmp 104 error.
If that would work then I could just do:
"[f=flv]rtmp://rtmp-api.facebook.com:80/rtmp/key|[f=flv]rtmp://youtube.etc"
And that would stream to both.
I did find out that I needed "-bsf:a aac_adtstoasc" otherwise the encoder broke, complaining about malformed bits.
Any ideas?
The error is only with Facebook. YouTube works fine.
Console output:
Metadata:
encoder : Lavf57.72.101
Stream #0:0: Video: h264 (libx264), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=-1--1, 1300 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc
Metadata:
encoder : Lavc57.95.101 libx264
Side data:
cpb: bitrate max/min/avg: 2000000/0/1300000 buffer size: 2048000 vbv_delay: -1
Stream #0:1: Audio: aac (libfdk_aac), 44100 Hz, stereo, s16, 128 kb/s
Metadata:
encoder : Lavc57.95.101 libfdk_aac
frame= 61 fps= 30 q=25.0 size=N/A time=00:00:01.97 bitrate=N/A speed=0.961x
WriteN, RTMP send error 104 (136 bytes)

The FLV format requires global headers. When ffmpeg outputs to FLV directly -f flv, the encoder is signaled to produce global headers. But when -f tee is the primary/parent muxer, that flag isn't set. So, it has to be manually set via -flags +global_header.

Related

How do i set a strict audio bitrate when encoding?

I'm encoding with ffmpeg and my audio bitrate varies somewhat, even tho I'm using -b:a 224K it differs with +-1 or 2 kb/s in the finished product. Is there a way to set a strict bitrate? My OCD made me write this post.
Here is my encoding parameters:
-c:v libx264 -preset fast -profile:v high -level 4.0 -crf 23 -x264opts cabac=1:ref=4:vbv_maxrate=15000:vbv_bufsize=31250 -coder 1 -pix_fmt yuv420p -r 24000/1001 -use_editlist 0 -movflags +faststart -g 30 -bf 2 -map 0:1 -map 0:2 -map 0:3 -c:a aac -b:a 224K -ar 48K -ac 2 -profile:a aac_low

Encoding 25mp video

I have a 25MP uncompressed video file of 100 frames.
I tried to encode it with ffmpeg and h264 encoder into a .mp4 file, but the encoding got stuck around the 10th frame.
This is the script:
avconv -y -i input.avi -c:v libx264 -preset medium -b:v 5000K -pass 1 -c:a libfdk_aac -b:a 5000K -f mp4 /dev/null && \
avconv -i input.avi -c:v libx264 -preset medium -b:v 5000K -pass 2 -c:a libfdk_aac -b:a 5000K output.mp4
I am running it on a jetson TK1 with nvidia gpu, is there any way to use an accelarating encoding in order to make the encoding possible?
Please, if you can, give me a sampler script of something that might work.
Right now, I dont care how much time the encoding take, as long as it will work.
Thank you in advance! :)

FFMPEG Transcode so that I can view from iPhone Safari

I've been searching all day for a way to transcode files that are being uploaded to something that iPhone's can handle (in Safari) without any success. I've read that it's best to use Quicktime for iPhone with the h.264 codec but I am struggling to find either the correct dependencies or the correct syntax for this. I have already managed to convert to mp4 and webm .
Mp4:
'ffmpeg -i '.$input.' -strict experimental -s 1024x760 -ab 128k -vcodec libx264 -mbd 2 -flags +mv4+aic -trellis 2 -cmp 2 -subcmp -2 '.$filepath.'/'.$filename.'.mp4'
Webm
'ffmpeg -i '.$input.' -b 600 -s 1024x760 -ab 128k -vcodec libvpx -ab 128k -acodec libvorbis '.$filepath.'/'.$filenamewithoutext.'.webm'
Anyone know how to get these videos available for Safari (on iPhone/Pad)?
In fact, there are much more options which can be set for the input file as well for the output file.
However, I have found this german site : http://www.quadhead.de/videos-mit-ffmpeg-fur-das-iphone-konvertieren-und-streamen/ with this command :
ffmpeg.exe -i "%~1" -r 29.97 -vcodec libx264 -s 480x320 -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -b 400k -bufsize 4M -bt 256k -refs 1 -coder 0 -me_range 16 -subq 4 -partitions +parti4x4+parti8x8+partp8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec aac -ab 80k -ar 48000 -ac 2 -strict experimental -y "%~1".mp4
Yes, I'm german ;) that's the reason for my bad english. So feel free to correct my posts. But hey... I like ffmpeg too.
Have a nice day ;)
According to the official ffmpeg documentation on http://trac.ffmpeg.org/wiki/x264EncodingGuide, this is my suggestion to encode a video file to at least Apple Quicktime compatibility :
ffmpeg -i INPUT -c:v libx264 -movflags +faststart -profile:v normal -pix_fmt yuv420p -c:a aac -cutoff 15000 -b:a 128k OUTPUT.mp4
Have a nice day ;)

FFMPEG: Videos converted from FLV to MP4 does not play in iPod but works in iPhone

I used below command to convert videos from FLV,M4V to MP4.
ffmpeg -y -i video_1336406262.flv -vcodec libx264 -vpre slow -vpre
ipod640 -b 250k -bt 50k -acodec libfaac -ac 2 -ar 48000 -ab 64k -s
480x320 video_1336406262.mp4
The videos converted from M4V to MP4 are playing very well in both iPhone and iPod but the videos converted from FLV to MP4 does not work in iPod but does in iPhone.
In the video area of HTML5 page iPod even does not show the play symbol.
Could someone help here?
I am using the same command to convert from both FLV and M4V to MP4.
Thanks
I would recommend using HandBrakeCLI in order to convert videos to MP4.
Handbrake has a few built-in presets that allow precise compatibility targetting, see https://trac.handbrake.fr/wiki/BuiltInPresets
The built-in ipod preset has a few differences with the format you require, so your invocation can be translated to a handrake call in the following way:
HandBrakeCLI -i video_1336406262.flv -e x264 -a 1 -E faac -6 dpl2 -R Auto -D 0.0 -f mp4 -I -m -x level=30:bframes=0:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subme=6:8x8dct=0:trellis=0 -b 250 -B 64 -R 48 -X 480 -w 480 -l 320 -2 -o video_1336406262.mp4
I can't certify this is exactly what you need, but that should be close enough.
The conversion m4v -> mp4 makes no sense. m4v is just another extension for mp4.
Mp4 is not a video format but a wrapper for audio/videos/subtitles/metadatas.
In my opinion the problem comes from the profile. Depending on the iPhone generation, not all h264 profiles are supported.
Try adding -coder 0 to your command and it should work.
I think you get your command from here and I noticed there is another command that should do what you want :
iPod-iPhone 640 width, without presset :
ffmpeg -i INPUT -s 640x480 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 coder 0 -bf 0 -refs 1 -flags2 -wpred-dct8x8 -level 30 -maxrate 10M -bufsize 10M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4
According to my experience, if you want a good quality/size ratio, you should prefer 2-pass encoding :
ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 1 -an -title "Title" output.mp4
The encoding process is longer but worth the time!
One last thing, instead of using ffmpeg directly, I prefer to use Mencoder which is a wrapper for ffmpeg (more codecs support). A nice GUI for Mencoder should be MeGUI for windows, it really make the encoding process easier!

MPEG-TS Segments HTTP Live Streaming

I'm trying to interleave MPEG-TS segments but failing. One set of segments was actually captured using the built in camera in the laptop, then encoded using FFMPEG with the following command:
ffmpeg -er 4 -y -f video4linux2 -s 640x480 -r 30 -i %s -isync -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s 640x480 -vcodec libx264 -fflags +genpts -b 386k -coder 0 -me_range 16 -keyint_min 25 -i_qfactor 0.71 -bt 386k -maxrate 386k -bufsize 386k -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -aspect 640:480
And the other one is an avi file that was encoded using the following command:
fmpeg -er 4 -y -f avi -s 640x480 -r 30 -i ./DSCF2021.AVI -vbsf dump_extra -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s 640x480 -vcodec libx264 -fflags +genpts -b 386k -coder 0 -me_range 16 -keyint_min 25 -i_qfactor 0.71 -bt 386k -maxrate 386k -bufsize 386k -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -aspect 640:480
Then the output is segmented into ts segments using an open source segmenter.
If both come from the same source (both from the camera) they work fine. However in this case, the second set of segments freeze. Time passes, but the video does not move..
So i think it's an encoding problem. So my question is, how should i change the ffmpeg command for this to work?
By interleave I mean, having a playlist with the first set of segments, and another playlist with the other set of segments, and having the client call one then the other (HTTP Live Streaming)
The ffprobe output of one of the first set of segments:
Input #0, mpegts, from 'live1.ts':
Duration: 00:00:09.76, start: 1.400000, bitrate: 281 kb/s
Program 1 Service01
Metadata:
name : Service01
provider_name : FFmpeg
Stream #0.0[0x100]: Video: h264, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 29.92 fps, 29.92 tbr, 90k tbn, 59.83 tbc
Stream #0.1[0x101]: Audio: aac, 48000 Hz, stereo, s16, 111 kb/s
The ffprobe output of one of the second set of segments:
Input #0, mpegts, from 'ad1.ts':
Duration: 00:00:09.64, start: 1.400000, bitrate: 578 kb/s
Program 1 Service01
Metadata:
name : Service01
provider_name : FFmpeg
Stream #0.0[0x100]: Video: h264, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0.1[0x101]: Audio: aac, 48000 Hz, stereo, s16, 22 kb/s
Thank you,
I have seen quite a few questions in the subject - See:
HTTP Live Streaming MPEG TS segment and
Update .m3u8 playlist file for HTTP Live streaming?
I am not sure exact problem - but i think most people complain that when you mix content from both sources are different then there is a freezing.
I think this situation may arise if PTS and/or PCR is discontinuous and the player is not recognizing this or flushing it. Probably, you can identify the sequence of Timestamps and see if that being fixed solves the problems.
Also, see 3.3.11. of https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-07 : EXT-X-DISCONTINUITY
The EXT-X-DISCONTINUITY tag indicates an encoding discontinuity
between the media segment that follows it and the one that preceded
it. The set of characteristics that MAY change is:
o file format
o number and type of tracks
o encoding parameters
o encoding sequence
o timestamp sequence
So a discontinuity flag in the playlist file might just help if the problem is any of the above. Please try some of this, and put more details. I guess, this will help lot of other people as well.