dank074/Discord-video-stream

Hardware Codec questions - trying to use h264_v4l2m2m instad of libx264

Opened this issue · 3 comments

My index.ts file is generating this ffmpeg command:

-i /dev/video0 -f alsa -hwaccel auto -i hw:C4K,0 -an -r 30 -vcodec h264_v4l2m2m -b:v 5000k -filter:v scale=w=1280:h=720 -loglevel info -fflags nobuffer -analyzeduration 0 -f h264 -pix_fmt yuv420p -preset ultrafast -g 30 -bsf:v h264_metadata=aud=insert unix:./1.sock -ac 2 -ar 48000 -vn -f s16le unix:./2.sock

When the program is run with this ffmpeg command: the bot joins, creates the stream, I can hear audio, but video has an infinite load symbol.

if i generate this ffmpeg command:

-i /dev/video0 -f alsa -hwaccel auto -i hw:C4K,0 -an -r 30 -vcodec libx264 -b:v 5000k -filter:v scale=w=1280:h=720 -loglevel info -fflags nobuffer -analyzeduration 0 -f h264 -pix_fmt yuv420p -preset ultrafast -g 30 -bsf:v h264_metadata=aud=insert unix:./1.sock -ac 2 -ar 48000 -vn -f s16le unix:./2.sock

everything works perfectly.

Both console outputs look the same, any ideas on what could be going wrong?

The only change between the 2 is changing -vcodec libx264 to -vcodec h264_v4l2m2m

That's weird.

If you enable logging for the ffmpeg process do you see anything?

Yes, when I had ffmpeg set to info, i had no errors and the ffmpeg output seemed to be encoding like normal. i was also able to modify the commands to output to a video file and it recorded as expected for both codecs

Try adding -bf 0 to the first command. WebRTC doesn't support B frames, and even if the stream works, it'll be very glitchy.

If that doesn't work either, can you provide a video file after running it through the encoder?

Another thing to try would be to record into a file (with -bf 0), then replaying that file through the copy codec path.