Video timecode using RTMP / AVCONV (ffmpeg) / NGINX - nginx

to insert a time code in a video I use
avconv -y -i in.mp4 -vf "drawtext=fontfile=/usr/share/fonts/truetype/DroidSans.ttf: fontsize=22: timecode='00\:00\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=black#0.5" -an -y out.mp4
when reading the video
ffplay out.mp4
everything is ok but when using a pipe to feed the rtmp server and then reading the stream with ffplay the time code won't display. Is it due to the flv conversion ?
for example streaming from a raspberry pi camera
/opt/vc/bin/raspivid -n -hf -vf -fl -mm matrix -w 800 -h 600 -fps 25 -g 80 -t 0 -b 6000000 -o - | avconv -re -i - -nostats -c copy -vf "drawtext= ..... -f flv rtmp://myserver/cam/live
doesn't output the timecode.

Related

End FFMPEG execution when RTMP input is closed

I have an RTMP arut server inside which I call a python script to run an FFMPEG command and create HLS packaging.
Problem is that when I stop the RTMP stream, FFMPEG still run processes in background.
FFMPEG string is like this:
ffmpeg -re -v verbose -i rtmp://localhost:1935/live/testlive -rw_timeout 500 -http_persistent 1 -method PUT -http_user_agent test -f hls -hls_list_size 5 -hls_flags discont_start+delete_segments -vf "scale=426:trunc(ow/a/2)*2" -c:a libfdk_aac -ar 48000 -c:v h264 -profile:v main -crf 24 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type event -preset veryfast -b:v 300k -maxrate 856k -bufsize 1200k -b:a 128k -vcodec libx264 -hls_segment_filename http://mystream/123/v1/testlive/0_%03d.ts http://mystream/123/v1/testlive/index.m3u8
The RTMP server should send an NetStream.Play.Stop event to subscribers (or disconnect them) to signal end of stream. If you are using the nginx rtmp module, look at the play_restart or idle_streams directives.

FFMPEG streaming raw H264

Im currently working on streaming a mp4 file encoded with h264 over TCP and decoding at the mobile side (Android).I successfully manage up connection and streaming h264 raw data but that image quality is too bad (half screen is green or purple and everything is pixelized).I started streaming with:
ffmpeg -re \
-i test.mp4 \
-vcodec libx264 \
-vf scale=1920:1080 \
-vprofile high \
-preset ultrafast \
-b:v 1M -maxrate 2M -bufsize 2M -pass 1 \
-strict experimental \
-pix_fmt yuv420p \
-tune zerolatency \
-movflags use_metadata_flag \
-movflags empty_moov+default_base_moof+faststart \
-f h264 tcp://10.230.253.241:9090
Result:
Image
Am I on right road and its that possible with raw h264? Any advice would welcome! Thanks
rawvideo is the opposite of h264. Its non compressed raw video.
You need to set the format to -f h264

Can't livestream with FFmpeg on Nginx?

I am trying to livestream through RTMP on FFmpeg in Nginx. Doing sudo ffmpeg -re -f video4linux2 -i test.mp4 -vcodec libx264 -vprofile baseline -acodec aac -strict -2 -f flv rtmp://localhost/show/stream gives me ioctl(VIDIOC_QUERYCAP): Inappropriate ioctl for device
test.mp4: Inappropriate ioctl for device
Am I even doing this right?

Use FFMPEG to restream RTMP source to YouTube - no video stream in output

I am attempting to grab the .m3u8 file from an nginx-rtmp server and pass it along to YouTube rtmp. I believe this to be possible (for example here: https://stackoverflow.com/a/11978820/1552594 although this is on the same host). The command I am using is:
ffmpeg -analyzeduration 0 -i \
http://source.rtmp.server/hls/stream.m3u8 -pix_fmt yuv420p \
-f flv rtmp://a.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx
However the output contains only audio and YouTube doesn't like it. The command produces following:
As you can see no Video stream in output metadata, stream mapping shows only audio and the trace shows 0kb of Video for 651kb of Audio
Any help much appreciated
MORE INFO
Improved version of the command lifted from this article:
https://judge2020.com/restreaming-a-m3u8-hls-stream-to-youtube-using-ffmpeg/
"Restreaming a m3u8 HLS stream to Youtube using FFMPEG" AKA exactly what I am trying to do.
The command I am sending is now:
ffmpeg -re -i "http://source.rtmp.server/hls/stream.m3u8" \
-strict -2 -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -flags \
+global_header -bsf:a aac_adtstoasc -bufsize 3000k -f flv \
"rtmp://a.rtmp.youtube.com/live2/xxx-xxxx-xxxx-xxxx"
I got pretty much exactly the same response except with the Audio being read and output using aac codec.
MORE MORE INFO
I have found that adding a mapping can force the video stream into the output:
ffmpeg -re -i "http://source.rtmp.server/hls/stream.m3u8" \
-strict -2 -c:v copy -c:a -map 0:0 -map 0:1 -ar 44100 -ab 128k -ac 2 \
-flags +global_header -bsf:a aac_adtstoasc -bufsize 1000k \
-f flv "rtmp://a.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx"
This throws up the error that has presumably been resulting in the video stream being silently dropped:
Finally worked it out. The last issue above was a red herring and was due to missing a codec argument for the audio -c:a.
The complete working command is as follows:
ffmpeg -probesize 100M -analyzeduration 20M -re \
-i "http://source.rtmp.server/hls/stream.m3u8" -strict -2 -c:v \
libx264 -pix_fmt yuv420p -c:a aac -map 0:0 -map 0:1 -ar 44100 \
-ab 128k -ac 2 -b:v 2567k -flags +global_header -bsf:a aac_adtstoasc \
-bufsize 1000k -f flv "rtmp://a.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx"
The important parts are -probesize and -analyeduration - these need tweaking until they work. The -re flag is important to indicate restreaming. The various video codec declarations are also important - -c:v libx264 -pix_fmt yuv420p or it will throw errors about the output size being 0x0. Finally the map flags ensure that both streams are included in the output: -map 0:0 -map 0:1

MPEG-TS audio synchronization lost on segmentation

I use FFmpeg for encoding my iphone video (on debian) and mediafilesegmenter (on mac OS server). For encoding this is my commande :
ffmpeg -i INPUT -y -acodec libfaac -ar 22000 -ab 40k -vcodec libx264 -b 600k \
-bt 600k -vpre slow -vpre baseline -threads 1 -level 30 -r 10 -s 400x224 \
-map_chapters -1:-1 -f ipod INPUT.mp4
When i read the INPUT.mp4 everything is OK with audio.
But when I use the Apple Segmenter (mediafilesegmenter) i have a descync between audio & video.
Is my command line is wrong ? or it's a Apple segmenter bug. The mediastreamvalidator show me :
WARNING: Media segment contains a video track but does not contain any IDR access unit with a SPS and a PPS
But i don't know if cause the audio desync.
I have the latest mediafilesegmenter download from connect.apple.com.

Resources