Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Why does ffmpeg command work in terminal but not subprocess.call
4 août, par BrianI reviewed the "similar questions", but those seem to refer to using the full path for ffmpeg to ensure using the same version, which I am already doing so posting my question.
I am using a Mac runnning Sequoia 15.5, python 3, and ffmpeg 4.2.1.
I'm trying to write a script that can convert flac to mp3 320k.
If I use the following command in terminal everything works as intended:
/usr/local/bin/ffmpeg -i "/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.flac" -b:a 320k -map_metadata 0 -id3v2_version 3 "/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.mp3"
But when trying to do the same thing with subprocess.call with the following:
command = ['/usr/local/bin/ffmpeg', '-i', '/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.flac', '-b:a 320k', '-map_metadata 0', '-id3v2_version 3', '/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.mp3'] p = subprocess.call(command)
I get this as a result:
Unrecognized option 'id3v2_version 3'. Error splitting the argument list: Option not found
If I remove the '-id3v2_version 3', then the subprocess.call results in the following error:
[mp3 @ 0x7fae2c008200] Invalid stream specifier: a 320k.
Why does Terminal understand but subprocess.call doesn't when I've verified I'm using the same version of ffmpeg?
-
How to stop ffmpeg remotely ?
4 août, par AdamI'm running ffmpeg on another machine for screen capture. I'd like to be able to stop it recording remotely. FFMPEG requires that q is pressed to stop encoding as it has to do some finalization to finish the file cleanly. I know I could kill it with kill/killall however this can lead to corrupt videos.
Press [q] to stop encoding
I can't find anything on google specifically for this, but some there is suggestion that echoing into /proc//fd/0 will work.
I've tried this but it does not stop ffmpeg. The q is however shown in the terminal in which ffmpeg is running.
echo -n q > /proc/16837/fd/0
So how can I send a character to another existing process in such a way it is as if it were typed locally? Or is there another way of remotely stopping ffmpeg cleanly.
-
Shaka Packager not adding #EXT-X-ENDLIST to HLS playlist after stream ends [closed]
4 août, par ArjitI am using Shaka Packager for live streaming with HLS & DASH output. My setup is like this:
- RTMP stream is published to
NGINX-RTMP
. - On
exec
, I start a transcoder (FFmpeg) and packager (Shaka Packager). - On
exec_publish_done
, I stop both processes.
Here’s the command I use to start Shaka Packager:
"$SHAKA_PACKAGER_BIN" \ "in=${VIDEO_720P_FIFO},stream=video,format=mp4,init_segment=${STREAM_OUTPUT_DIR}/720p_init.mp4,segment_template=${STREAM_OUTPUT_DIR}/720p_\$Number\$.m4s,bandwidth=3000000,hls_name=720p" \ "in=${VIDEO_480P_FIFO},stream=video,format=mp4,init_segment=${STREAM_OUTPUT_DIR}/480p_init.mp4,segment_template=${STREAM_OUTPUT_DIR}/480p_\$Number\$.m4s,bandwidth=1500000,hls_name=480p" \ "in=${AUDIO_FIFO},stream=audio,format=mp4,init_segment=${STREAM_OUTPUT_DIR}/audio_init.mp4,segment_template=${STREAM_OUTPUT_DIR}/audio_\$Number\$.m4s,bandwidth=128000,hls_name=audio" \ --hls_master_playlist_output "${STREAM_OUTPUT_DIR}/master.m3u8" \ --hls_playlist_type LIVE \ --mpd_output "${STREAM_OUTPUT_DIR}/manifest.mpd" \ --segment_duration 2 \ --low_latency_dash_mode=true \ --availability_time_offset 3 \ > "$SHAKA_PKG_LOG" 2>&1 &
And FFmpeg:
ffmpeg -y -re -i "rtmp://localhost:1935/live/${STREAM_KEY}" \ -filter_complex \ "[0:v]split=2[v720][v480]; \ [v720]scale=w=1280:h=720,setsar=1[v720out]; \ [v480]scale=w=854:h=480,setsar=1[v480out]; \ [0:a]aresample=44100[aout]" \ -map "[v720out]" -c:v libx264 -b:v 3000k -f mp4 ${VIDEO_720P_FIFO} \ -map "[v480out]" -c:v libx264 -b:v 1500k -f mp4 ${VIDEO_480P_FIFO} \ -map "[aout]" -c:a aac -b:a 128k -f mp4 ${AUDIO_FIFO} \ > "$FFMPEG_LOG" 2>&1 &
My NGINX RTMP config triggers these scripts:
application live { live on; record off; exec /start_transcoder_and_packager.sh $name; exec_publish_done /stop_transcoder_and_packager.sh $name; }
Problem:
When stream ends, I stop FFmpeg and Shaka Packager like this in
stop_transcoder_and_packager.sh
:kill -s TERM $FFMPEG_PID kill -s TERM $SHAKA_PID
FFmpeg stops fine. But Shaka Packager doesn't finalize the HLS playlist properly — it doesn't write
#EXT-X-ENDLIST
in variant playlists. The.m3u8
files are left open-ended.If I manually append
#EXT-X-ENDLIST
to.m3u8
files after stopping the packager:for playlist in "$HLS_PLAYLISTS_DIR"/*.m3u8; do if [[ "$(basename "$playlist")" != "master.m3u8" ]]; then echo "#EXT-X-ENDLIST" >> "$playlist" fi done
The player either stops abruptly or keeps buffering.
What I want:
- The player should be able to play all segments until the end and then stop, like a VOD.
Tried Solutions:
- Sending
TERM
to Shaka Packager — doesn't finalize playlist. - Manually adding
#EXT-X-ENDLIST
— not working because segments are incomplete. - Tried lowering segment duration and buffer depths — no effect on finalize.
- RTMP stream is published to
-
VFR input + h264_nvenc - output bitrate is based on initial frame rate when I want it to be time based [closed]
4 août, par hedgehog90I have an HLS stream produced from a live VFR source in ffmpeg. The source consists of blocks of varying frame rate. The first 30 minutes might be 24fps, the next 30 minutes @ 60fps. Although it is not standard for HLS to be VFR, it appears to playback perfectly well on various platforms I've tested.
When I use the libx264 encoder with -crf + -maxrate parameters, I can get my desired bitrate per stream despite potentially wild frame rate fluctuations.
But when I use the h264_nvenc encoder with -cq + -maxrate parameters (and practically every configuration I could think of), the bitrate is all dependant on the initial frame rate of the input stream. For example, segment duration is set to 5 seconds... the first 5 seconds of the input are 30fps, and the next 5 seconds are 60fps, the resulting output will produce 1 segment at the desired bitrate, the next at double the desired bitrate.
I have tried every configuration to try and trick the encoder into working differently, but it appears this might be a built-in limitation.
I've searched for answers, I've asked the chatbots, I can't find a definitive solution, besides converting the input stream to a constant frame rate (which is not an option).
-
How do I deploy Whisper.cpp stream.wasm on an EC2 instance ? [closed]
3 août, par tosUserHow do I deploy the whisper.cpp stream.wasm demo on a EC2 instance?
The demo is available from the following git: https://github.com/ggml-org/whisper.cpp/tree/master/examples/stream.wasm
I am fairly far along, but the program hangs on Preparing ... I do not know what is causing the issue.
Here are the steps I have taken. (I am trying to make it brief, and provide more detail as necessary.) I cloned the repository and built it locally. It runs properly.
I created an EC2 instance running Amazon Linux 2023, and uploaded the Whisper.cpp files to it. I ssh into the server and installed nginx, it displays the default page to the server's public ip address. I then configured nginx as a reverse proxy server:
server { listen 80; server_name redactedPublicIpAddress; location / { proxy_pass http://127.0.0.1:8000; } }
I enabled and restarted nginx.
I then try to run whisper.cpp stream.wasm by running
python3 examples/server.py
It indicates that it is serving home/ec2-user/whisper.cpp/build-em/bin to localhost:8000 This is analogous to the message when it is served locally. Stream.wasm has a 301 response. Helpers.js and coi-serviceworker.js have 200 responses.The index file displays normally at the public ip address/stream.wasm/
However, all is not well. The js seems to hang on Preparing... Other js functions on the page still function, I can download a model and the page indicates it was downloaded, etc. However, I cannot start recording. The start button is not active. It never properly initializes.
This type of behavior is identical to trying to open the index file on my local computer without it being served.
I think I am missing something simple, but do not know what it is.
Here are some steps that I took afterwards that did not fix the issue: I installed nodejs and npm so that I could install ffmpeg.wasm:
npm install @ffmpeg/ffmpeg @ffmpeg/util
The github page indicates that I need to put the files in the html path. So in trying to troubleshoot I put them in /user/shared/nginx/html which is where the nginx default index file is placed.
I think it may be related to serving the python. The server.py file is not in a state to deploy it with uvicorn.
Maybe there is some sort of cors issue.
I simply do not know.