Parsix Posted June 25 Posted June 25 how to view video stream from "Tee pseudo-muxer" in ffmpeg inside gui form? capture from camera Quote ffmpeg -f dshow -i video="WebCamera":audio="Microphone (WebCamera)" -vcodec libx264 -framerate 30 -s 1280x720 -b:a 320k -ar 48000 -ac 2 -t 10 "E:\0-Dev-Projects\0-TestArea\Camera\ffmpeg\output.mkv" I want to have a live view while recording from the camera. I used WebcamDS (DirectShow webcam) but it doesn't support x265 with synchronized audio in mp4 output format
KaFu Posted June 26 Posted June 26 Google AI give me this: ffmpeg -f dshow -framerate 30 -video_size 1280x720 -i video="WebCamera":audio="Microphone (WebCamera)" -filter_complex "[0:v]split=2[v1][v2]" -map "[v1]" -map 0:a -vcodec libx264 -b:a 320k -ar 48000 -ac 2 -t 10 "E:\0-Dev-Projects\0-TestArea\Camera\ffmpeg\output.mkv" -map "[v2]" -f matroska - | ffplay -i - Parsix 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Parsix Posted June 26 Author Posted June 26 (edited) The problem is the display in the autoit form. this worked Quote ffmpeg -f dshow -i video="WebCamera":audio="Microphone (WebCamera)" -vcodec libx264 -framerate 30 -s 1280x720 -b:a 320k -ar 48000 -ac 2 -y "E:\0-Dev-Projects\0-TestArea\Camera\ffmpeg\TEST-1.mkv" -f matroska -c copy - | ffplay -f matroska -x 760 -y 360 - Edited June 26 by Parsix KaFu 1
Solution UEZ Posted June 26 Solution Posted June 26 (edited) Try this: expandcollapse popup;Code by UEZ build 2026-06-27 #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIError.au3> Global $iW = 1280, $iH = 720 Global $sFFMPEG = '"...\FFMPEG\bin\ffmpeg.exe"' Global $sMPV = '"...\MPV\mpv.exe"' Global $sOutFile = "C:\Temp\WebCamRec.mkv" Global $aVid, $aAud _GetDShowDevices($sFFMPEG, $aVid, $aAud) If $aVid[0] = 0 Then Exit MsgBox(16, "Error", "No video capture device found") Global $sVideo = $aVid[1] ; first WebCam Global $sAudio = ($aAud[0] > 0) ? $aAud[1] : "" ; first micro, if available Global $bHasAudio = ($sAudio <> "") ; Input-Optionen MUESSEN vor dem -i stehen (gelten fuer den folgenden Input) Global $sInput = '-f dshow -rtbufsize 256M -video_size 1280x720 -framerate 30 -pixel_format nv12 ' & _ '-use_wallclock_as_timestamps 1 -i video="' & $sVideo & '"' If $bHasAudio Then $sInput &= ' -f dshow -use_wallclock_as_timestamps 1 -i audio="' & $sAudio & '"' Global $sAudioMap = $bHasAudio ? '-map 1:a -c:a aac -ar 48000 -ac 2 ' : '' Global $hGUI = GUICreate("WebCam + Live Preview + Record", $iW, $iH + 40, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN)) Global $idStop = GUICtrlCreateButton("Stop", 10, $iH + 6, 80, 26) Global $hChild = GUICreate("", $iW, $iH, 0, 0, $WS_CHILD, -1, $hGUI) GUISetState(@SW_SHOW, $hChild) GUISwitch($hGUI) GUISetState(@SW_SHOW, $hGUI) Global $wid = Number($hChild) If FileExists($sOutFile) Then FileDelete($sOutFile) Global $sUDP = "udp://127.0.0.1:1234?pkt_size=1316" Global $sCmd = $sFFMPEG & ' ' & $sInput & ' ' & _ '-filter_complex "[0:v]split[rec][tmp];[tmp]fps=30[prev]" ' & _ '-map "[rec]" -c:v libx264 -pix_fmt yuv420p ' & $sAudioMap & '"' & $sOutFile & '" ' & _ '-map "[prev]" -c:v libx264 -preset ultrafast -tune zerolatency -g 10 -an ' & _ '-fflags +nobuffer -flags +low_delay -muxdelay 0 -muxpreload 0 -flush_packets 1 ' & _ '-f mpegts ' & $sUDP Global $iPID = Run($sCmd, "", @SW_HIDE, $STDIN_CHILD) Global $sMpvPipe = "\\.\pipe\mpv_preview" Global $sMpvCmd = $sMPV & ' --wid=' & $wid & ' --no-audio --no-osc --force-window=yes ' & _ '--profile=low-latency --untimed --no-cache --demuxer-readahead-secs=0 ' & _ '--vd-queue-enable=no --demuxer-lavf-o=fflags=+nobuffer ' & _ '--demuxer-lavf-format=mpegts --input-ipc-server=' & $sMpvPipe & ' "' & $sUDP & '"' Global $iPIDmpv = Run($sMpvCmd, "") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idStop _StopAll($iPID, $iPIDmpv) ExitLoop EndSwitch WEnd GUIDelete($hGUI) Func _GetDShowDevices($sFFMPEG, ByRef $aVideo, ByRef $aAudio) Local $sExe = StringReplace($sFFMPEG, '"', '') Local $iPID = Run('"' & $sExe & '" -hide_banner -list_devices true -f dshow -i dummy', "", @SW_HIDE, $STDERR_CHILD) Local $sOut = "" While 1 $sOut &= StderrRead($iPID) If @error Then ExitLoop WEnd Local $aV[1] = [0], $aA[1] = [0], $sType = "" Local $aLines = StringSplit(StringStripCR($sOut), @LF), $sLine, $aM For $i = 1 To $aLines[0] $sLine = $aLines[$i] If StringInStr($sLine, "(video)") Then $sType = "v" If StringInStr($sLine, "(audio)") Then $sType = "a" If StringInStr($sLine, "Alternative name") Then ContinueLoop $aM = StringRegExp($sLine, '"([^"]+)"', 1) If @error Then ContinueLoop If $sType = "v" Then _ArrayAdd_($aV, $aM[0]) ElseIf $sType = "a" Then _ArrayAdd_($aA, $aM[0]) EndIf Next $aVideo = $aV $aAudio = $aA EndFunc Func _ArrayAdd_(ByRef $a, $v) ReDim $a[$a[0] + 2] $a[0] += 1 $a[$a[0]] = $v EndFunc Func _StopAll($iPID, $iPIDmpv) If ProcessExists($iPID) Then StdinWrite($iPID, "q") StdinWrite($iPID) ProcessWaitClose($iPID, 10) If ProcessExists($iPID) Then ProcessClose($iPID) EndIf Local $h = FileOpen($sMpvPipe, 2) If $h <> -1 Then FileWrite($h, '{"command":["quit"]}' & @LF) FileClose($h) EndIf ProcessWaitClose($iPIDmpv, 2) If ProcessExists($iPIDmpv) Then ProcessClose($iPIDmpv) EndFunc mpv can be found here: https://sourceforge.net/projects/mpv-player-windows/files/ Adjust the pathes to ffmpeg and mpv! Edited June 27 by UEZ Code update Parsix and Xandy 2 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Parsix Posted June 26 Author Posted June 26 Invalid input file index: 1. Failed to set value '1:a' for option 'map': Invalid argument Error parsing options for output file C:\temp\WebCamRec.mkv. Error opening o
UEZ Posted June 26 Posted June 26 39 minutes ago, Parsix said: Invalid input file index: 1. Failed to set value '1:a' for option 'map': Invalid argument Error parsing options for output file C:\temp\WebCamRec.mkv. Error opening o Made some updates - please try again. Parsix 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Parsix Posted June 26 Author Posted June 26 this error : [in#0 @ 000001ff3283f740] Could not set video options [in#0 @ 000001ff32845780] Error opening input: I/O error Error opening input file video=WebCamera. Error opening input files: I/O error i modify to this and not have error (ffmpeg) Global $sAudioMap = ($sAudio <> "") ? '-map 0:a -c:a aac -ar 48000 -ac 2 ' : '' $sInput = '-f dshow -i video="Camera":audio="Microphone (Camera)" -rtbufsize 256M -video_size 1280x720 -framerate 30 -pixel_format nv12 -use_wallclock_as_timestamps 1' Global $sCmd = $sFFMPEG & ' ' & $sInput & ' ' & _ '-filter_complex "[0:v]split[rec][tmp];[tmp]fps=30[prev]" ' & _ '-map "[rec]" -c:v libx264 -pix_fmt yuv420p ' & $sAudioMap & '"' & $sOutFile & '" ' & _ '-map "[prev]" -c:v mpeg2video -q:v 5 -an -f mpegts ' & $sUDP but mpv.exe not work
Parsix Posted June 26 Author Posted June 26 (edited) Sorry, access was blocked by the firewall. The playback was successful, but the playback speed is very slow and there is a lot of delay. Thank you Dear UEZ, all the best to you always. Edited June 26 by Parsix
UEZ Posted June 27 Posted June 27 I updated the code above - the latency should be better now. Parsix 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Parsix Posted June 27 Author Posted June 27 (edited) The delay is still noticeable. It doesn't record the last few seconds before pressing the stop button. Edited June 27 by Parsix
UEZ Posted June 27 Posted June 27 6 hours ago, Parsix said: The delay is still noticeable. It doesn't record the last few seconds before pressing the stop button. Last try - see above. Personally, I don't like this approach of using ffmpeg and mpv to display and record the webcam. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Parsix Posted June 28 Author Posted June 28 19 hours ago, UEZ said: Last try - see above. Personally, I don't like this approach of using ffmpeg and mpv to display and record the webcam. What do you recommend ? I was simultaneously working on the WebcamDS project, but I ran into problems due to a problem with the output image codec. ffmpeg appeals to me because of its simultaneous streaming over the network.
UEZ Posted June 28 Posted June 28 What are you trying to do? Record from the webcam? Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Parsix Posted June 28 Author Posted June 28 5 hours ago, UEZ said: What are you trying to do? Record from the webcam? record from webcam need to preview, stream to network and recive to another system
UEZ Posted June 28 Posted June 28 55 minutes ago, Parsix said: record from webcam need to preview, stream to network and recive to another system Try: Global $sRemote = "192.168.1.50:9000" ; IP of the receiver Global $sCmd = $sFFMPEG & ' ' & $sInput & ' ' & _ '-filter_complex "[0:v]split[rec][tmp];[tmp]fps=30[net]" ' & _ '-map "[rec]" -c:v libx264 -pix_fmt yuv420p ' & $sAudioMap & '"' & $sOutFile & '" ' & _ '-map "[net]" -c:v libx264 -preset ultrafast -tune zerolatency -g 10 -an ' & _ '-fflags +nobuffer -flags +low_delay -muxdelay 0 -muxpreload 0 -flush_packets 1 ' & _ '-f tee "[f=mpegts]' & $sUDP & '|[f=mpegts]srt://' & $sRemote & '?mode=caller"' Parsix 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now