How to http stream FFMPEG encoded frames with VLC - encoding

I have a python script that write images (numpy arrays) on the standard output.
I want to keep this frames and encode them h264 with FFMPEG, using GPU, then give it to vlc to expose a stream over http.
Here there's a working example of my apporach, without the part of h264 encoding:
python3 script.py | ffmpeg -r 24 -s 1920x1080 -f rawvideo -i - -vcodec copy -f avi - | cvlc --demux=rawvideo --rawvid-fps=25
--rawvid-width=1920 --rawvid-height=1080 --rawvid-chroma=RV24 - --no-audio --sout '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:standard{access=http{user=pippo,pwd=pluto,mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:10001/}'
Now, I'm having troubles in writing working pipes to do what I need.
Here the pipe I'm actually working on, FFMPEG process is managed by GPU, but VLC cannot correctly manage the flow, I suppose, in fact I can connect to VLC from another VLC instance used as client, but then I got an error in which VLC client cannot open MRL.
Here the pipe:
python3 script.py | ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -f rawvideo -s 1920x1080 -i - -c:a copy -c:v h264_nvenc -f h264 - | cvlc --demux=rawvideo --rawvid-fps=25 --rawvid-width=1920 --rawvid-height=1080 --rawvid-chroma=RV24 - --no-audio --sout '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:standard{access=http{user=pippo,pwd=pluto,mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:10001/}'
I don't understand how to set vlc parameters in order to manage the incoming stream. I also could have made errors in ffmpeg pipe, any suggestion is welcome.

Related

Issue regarding Slides not being shown in converted video to mp4 in BigBlueButton

We are using BigBlueButton 2.4 for webinars. When an webinar video is processed by bigbluebutton, the presentation shows the slides that were uploaded in the webiner, but the converted video that we are downloading, does not have those slides shown (Rest of the video is okay).
Does anyone know how to fix this for this particular version?
The code that we are using is mentioned below, if it helps:
#!/bin/sh
# Convert the deskshare and webcam to a combined video stream including logo
cd /var/bigbluebutton/published/presentation/
meetingId=$1
cd $meetingId
# add webcam sound to deskshare
if [ -e deskshare/deskshare.webm ]
then
ffmpeg -nostdin -threads 4 -i video/webcams.webm -i deskshare/deskshare.webm -af afftdn deskshare_with_sound.mp4
else
ffmpeg -nostdin -threads 4 -i video/webcams.webm -af afftdn deskshare_with_sound.mp4
fi
ffmpeg -nostdin -threads 4 -i video/webcams.webm -vf

ffmpeg monochrome rawvideo

I am trying to generate a raw video stream with luma only (monochrome, YUV400) 8bit pixel data using the following command:
ffmpeg -i input.mp4 -vcodec rawvideo -pix_fmt raw.yuv
After that I want to h.264 encode the raw stream with the profiles that support monochrome pixel data (eg: high)
ffmpeg -f rawvideo -vcodec rawvideo -pix_fmt gray -s 640x512 -r 60 -i raw.yuv -codec:v libx264 -profile:v high -c:a copy out.mp4
However, i always get the following error, which indicates that the raw stream is not in the monochrome format that I expected:
x264 [error]: high profile doesn't support 4:4:4
I am new to ffmpeg and video formats in general. Can somebody please point out what I am missing?
Thank you!
Edit:
I also tried to use the following filter to extract only the luma channel. Unfortunately, the end result was the same.
ffmpeg -i input.mp4 -vcodec rawvideo -pix_fmt gray -filter_complex 'extractplanes=y[y]' -map '[y]' raw.yuv
The ffmpeg version installed was quite old (3.4.7). After installing 4.2.3 everything worked fine.

Text streaming with RTMP?

I'm trying to get the output of a bash file to an RTMP stream.
I've successfully done it with FFMPEG using a filter, but the stream stops at Random intervals.
I assume that it's FFMPEG reading NULL data from the file.
I already write another file "output.txt", delete " input.txt" (which FFMPEG is reading) and rename "output.txt" to "input.txt".
Is there any way to do it more atomic in bash so it will work? Or is there a more elegant way to turn a changing text (max one time per second) to an FFMPEG stream?
Here is my current script:
ffmpeg -s 1920x1080 -f rawvideo -pix_fmt rgb24 -r 10 -i /dev/zero -f lavfi -i anullsrc -vcodec h264 -pix_fmt yuv420p -r 10 -b:v 2500k -qscale:v 3 -b:a 712000 -bufsize 512k -vf "drawtext=fontcolor=0xFFFFFF:fontsize=15:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf:textfile=input.txt:x=0:y=0:reload=1" -f flv "rtmp://example.com/key"

How to extract the bitstream from H.264 video?

I have a H.264 video and I want to extract the bitstream from it. In other words, I need to know the stream after encoding a video via H.264 standard. I am going to use the extracted stream in Matlab. How can I do this (extract the bitstream)? Is it possible to use ffmpeg?if so what is the command.
You can do this using
ffmpeg -i in.mp4 -c copy -f h264 stream.264
Depending on what MATLAB expects, you may need to add a bitstream filter
ffmpeg -i in.mp4 -c copy -f h264 -vbsf h264_mp4toannexb stream.264

Trim mp4 files without encoding it again

I have a .mp4 video file, I need to trim it, however no matter how I do it, trimmed video is being encoded again which results in noisy video.
What I've tried:
Open video with Matlab, read frames and write only the frames that I want to have in trimmed video, I use 'MPEG-4' option.
Trim video using Windows Movie Maker.
Trim video using VirtualDub.
In first 2 scenarios original mp4 movie is encoded again after trimming it. I couldn't get mp4 files open in VirtualDub.
So what would be the easiest way to trim a video without re-encdong it?
You can do the split and re-encode in one command.
Create a text file, list.txt,
like this
file 'in.mp4'
inpoint 48.101
outpoint 67.459
file 'in.mp4'
inpoint 76.178
outpoint 86.399
file 'in.mp4'
inpoint 112.140
outpoint 125.031
then run,
ffmpeg -f concat -i list.txt -an -crf 18 out_merged.mp4
I've solved it with the following commands:
ffmpeg.exe -ss 48.101 -t 19.358 -i in.mp4 -an out_part1.mp4
ffmpeg.exe -ss 76.178 -t 10.221 -i in.mp4 -an out_part2.mp4
ffmpeg.exe -ss 112.140 -t 12.891 -i in.mp4 -an out_part3.mp4
ffmpeg -i out_part1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt1.ts
ffmpeg -i out_part2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt2.ts
ffmpeg -i out_part3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt3.ts
ffmpeg -i "concat:intrmdt1.ts|intrmdt2.ts|intrmdt3.ts" -c copy out_merged.mp4
And some explanation:
Giving -ss (start time) and -t (duration) options before -i (input) option avoids unnecessary decoding.
Not using -c copy provides transcoding hence result more precise cut (got this from here).
I used -an because I didn't need the audio, if you need audio just omit this option.
Before concatenating the resulting trimmed videos I needed to transcode them to mpeg transport streams, to achieve lossless concatenation (for more details you can see this link).