FFMPEG streaming raw H264 - tcp

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

Related

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?

watermark on transcoding rtmp video nginx

Hello i am transcoding video with rtmp and i want to put some text...i put Arial.ttf in my home directory of the server but doesnt work.. this is my command..
-map 0:0 -map 0:1 -strict -2 -crf 26 -vcodec libx264 -preset superfast
-acodec aac -b:a 128k -vf scale=-1:720 -aspect 16:9 -g 50 -r 30 -ar 48000
-ac 2 -vf drawtext="fontfile=/home/Arial.ttf: text='TEXT': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=10:y=10"
-f flv
can someone help me please?
thanks
Make sure you include absolute path to font and file is there:
drawtext="fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf:
text='Test Text': x=100: y=50: fontsize=24: fontcolor=yellow#0.2:
box=1: boxcolor=red#0.2"
Redirect output to a log file and see if command outputs any errors.
You can also include a watermark image instead:
-i /path/to/watermark.png -filter_complex "overlay=main_w-overlay_w-4:4"

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

Video timecode using RTMP / AVCONV (ffmpeg) / 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.

Stream from file .avi - Nginx + Rtmp

I want stream to rtmp server. I try:
ffmpeg.exe -f dshow -i "myvideo.avi" -s 480x288 -r 10 -vcodec libx264 -b:v 30k -pix_fmt yuv420p -acodec libvo_aacenc -ac 1 -b:a 4k -f flv rtmp://ip/live/test
And did not work... Error:
http://i.stack.imgur.com/06Rcf.png
how to do? Thx

Resources