VLC流脚本链失败求助:无法保存H264流至MP4
Fixing Your VLC TCP Stream Recording Script
Let's work through the issues in your script one by one to get your stream recording working properly:
1. Variable & Filename Problems
- Initial variable mix-up: You originally used
$fileinstead of$_filein the VLC command, which caused the empty.mp4filename. You fixed this, but two more filename issues remain:- Duplicate .mp4 extension: Your
$_filevariable already ends with.mp4, but you added another.mp4in thefile{dst=$_file.mp4,...}part. This creates messy filenames likevidlecture_11:30:58_09_03_2020.mp4.mp4. - Colons in filenames: The
%Tdate format includes colons (HH:MM:SS), which can cause parsing issues with VLC or file system quirks. Replace it with%H_%M_%Sto use underscores instead.
- Duplicate .mp4 extension: Your
2. Critical VLC Stream Output Syntax Error
The no sout stream modules matched for 'sout-keep' error happens because sout-keep is a global VLC parameter, not part of the --sout chain. You incorrectly included it inside the #transcode:... string. Move it outside as a separate argument to fix this.
Corrected Full Script
#!/bin/bash # Use underscores for time to avoid problematic colons in filenames _now=$(date +"%H_%M_%S_%d_%m_%Y") # Define filename with single .mp4 extension _file="vidlecture_$_now.mp4" # Run VLC with fixed parameters: split long command for readability vlc -vvv tcp://1.1.1.1:3000 \ --sout="#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=file{dst=$_file,no-overwrite},dst=display}" \ no-sout-all \ sout-keep
Key Fix Breakdown
- Filename cleanup:
%H_%M_%Sreplaces%Tto remove colons, and we only add.mp4once in the$_filevariable. - Sout parameter correction:
sout-keepandno-sout-allare now standalone arguments, not part of the stream chain string. This eliminates the "stream module not found" error. - Readability: Added line breaks (
\) to split the long VLC command into multiple lines, making it easier to debug later.
Expected Results
When you run the corrected script:
- It will generate a clean filename like
vidlecture_11_30_58_09_03_2020.mp4 - The stream will both display and save without the "stream chain failed" error
内容的提问来源于stack exchange,提问作者Michael de Borst
相关产品推荐
相关产品推荐

