[FFmpeg-user] help using SIGPIPE in ffmpeg
Hi ffmpeg-users, I was using a behavior in ffmpeg where SIGPIPE would terminate ffmpeg (while permitting it to cleanly end its muxing). This can be demonstrated in ffmpeg 5.1.3 with this command of piping ffmpeg into ffplay. When I close the ffplay window, the ffmpeg receives a SIGPIPE and stop. ffmpeg -f lavfi -i testsrc -f matroska test_ffmpeg5.mov -f nut - | ffplay - ffmpeg version 5.1.3ffplay version 5.1.3 Copyright (c) 2003-2022 the FFmpeg developers Copyright (c) 2000-2022 the FFmpeg developers built with Apple clang version 13.0.0 (clang-1300.0.29.30) built with Apple clang version 13.0.0 (clang-1300.0.29.30) configuration: --prefix='/usr/local/Cellar/ffmpeg@5/5.1.3' --datadir='/usr/local/Cellar/ffmpeg@5/5.1.3/share/ffmpeg' --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox configuration: --prefix='/usr/local/Cellar/ffmpeg@5/5.1.3' --datadir='/usr/local/Cellar/ffmpeg@5/5.1.3/share/ffmpeg' --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox libavutil 57. 28.100 / 57. 28.100 libavutil 57. 28.100 / 57. 28.100 libavcodec 59. 37.100 / 59. 37.100 libavcodec 59. 37.100 / 59. 37.100 libavformat59. 27.100 / 59. 27.100 libavformat59. 27.100 / 59. 27.100 libavdevice59. 7.100 / 59. 7.100 libavdevice59. 7.100 / 59. 7.100 libavfilter 8. 44.100 / 8. 44.100 libavfilter 8. 44.100 / 8. 44.100 libswscale 6. 7.100 / 6. 7.100 libswscale 6. 7.100 / 6. 7.100 libswresample 4. 7.100 / 4. 7.100 libswresample 4. 7.100 / 4. 7.100 libpostproc56. 6.100 / 56. 6.100 libpostproc56. 6.100 / 56. 6.100 Input #0, lavfi, from 'testsrc': Duration: N/A, start: 0.00, bitrate: N/A Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264)) Stream #0:0 -> #1:0 (rawvideo (native) -> mpeg4 (native)) Press [q] to stop, [?] for help [libx264 @ 0x7f9070417300] using SAR=1/1 [libx264 @ 0x7f9070417300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 [libx264 @ 0x7f9070417300] profile High 4:4:4 Predictive, level 1.3, 4:4:4, 8-bit [libx264 @ 0x7f9070417300] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=7 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 Output #0, matroska, to 'test_ffmpeg5.mov': Metadata: encoder : Lavf59.27.100 Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(tv, progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 1k tbn Metadata: encoder : Lavc59.37.100 libx264 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A Output #1, nut, to 'pipe:': Metadata: encoder : Lavf59.27.100 Stream #1:0: Video: mpeg4 (FMP4 / 0x34504D46),
Re: [FFmpeg-user] Extracted Audio not in Sync with Video
Thanks, this is really helpful. I was actually able to correct the audio without distortion by using the atempo filter. Not sure why it worked better than the rubberband filter, but it did for me. Thanks, Josh [1]atempo=.10411607[aud]; with rubberband you stretch the audio track by 0.1 the original speed, leaving the video track unchanged. If audio quality is that crucial to your video, you also can hasten the video by the factor 1/0.1 to make it finish together with your unchanged audio track. This can be achieved with the video filter setpts. PTS means "Presentation Time Slot". The default is 1, presenting the video track as it is. Hastening your video track then means reducing the Presentation Time Slot a bit. In your presented usecase this would mean setpts=0.1 Values in video speed between 0.8 and 1.2 deliver convincing natural results. Below and above it is more likely a video trick. On 02.11.23 18:25, Josh wrote: Sorry for top posting again, forgot about that! So this worked. I added "[1]rubberband=tempo=.1[aud];" to the filters and now the audio and video all sync properly. But this created a new problem. Now the audio has some slight distortion. It almost sounds like an mp3 that doesn't have a high enough bitrate. It's very faint, and most people probably wouldn't notice it, but I can definitely hear it. Are there other ways so change the tempo that won't distort the sound? Josh On Wed, 1 Nov 2023, Torsten Kaiser wrote: (top posted since the whole thing is top posted) That is what I do for adapting audio length to the video track In preparation I calculate the durations in seconds for VIDEO.mp4 and AUDIO.mp3 separately. Must be different files to get the length difference. Korn Script Snippet # ADSS is audio length in seconds (n.nn) # VDSS is video length in seconds (n.nn) typeset -F5 TEMPO=$(( $ADSS / $VDSS )) # calculates the correction factor for audio length, five digits precision #then I apply the rubberband filter to the AUDIO.mp3 ffmpeg -y -i .AUDIO.mp3 -af rubberband=tempo=$TEMPO audio-corrected.mp3 #Merging corrected audio and video ffmpeg -y -i .VIDEO.mp4 -i audio-corrected.mp3 TARGET.mp4 #Note: rubberband has two nice options: tempo and pitch. Tempo makes the marching band play the same tune while running a marathon. #Pitch leaves the speed as it is while the cantor either sings with the whales or attracts all bats in the forest. Default is 1 for same tempo and/or same pitch. On 31.10.23 15:34, Joshua Grauman wrote: I tried this and it doesn't help. The audio and video are still not in sync, even when you don't use the fade-out... Josh On Tue, 31 Oct 2023, 凯迪软件(咨询、售后) via ffmpeg-user wrote: ffmpeg -y -i "v1-ed.mp4" -i "a1-ed.wav" -filter_complex "[1]anull[aud]; [0]fade=t=out:st=6673.87:n=24[out]" -strict experimental -shortest -map 0:v:0 -map 1:a:0 "lecture.mp4" ?? You can try using this command to see if it can solve your problem. The translation in English is: "Try canceling the fade-in and fade-out effect you added." china kaidi --Original-- From: "FFmpeg user questions" https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-user] Decode ac3 from multichannel USB input
Finally, I managed to extract ac3 from the Digiface USB spdif input but not in a way that helped me. It took a while but eventually I learned that the spdif signal is not pure ac3 but ac3 wrapped as SMPTE ST 337. VLC does not recognise this but ffmpeg and MediaInfo do. So if I first capture the first two Digiface channels into a file using: `ffmpeg -f avfoundation -i :2 -filter_complex "[0:a]pan=2C|c0=c0|c1=c1" -y capture.wav` and pipe this file into the VLC audio capture device via Blackhole2ch or any other audio device: `ffmpeg -y -i capture_2c.wav -f spdif -f audiotoolbox -audio_device_index 2 -` it works since ffmpeg will extract the ac3 and if necessary, decode appropriately. However, if I try to use VLC as the capture device directly: `ffmpeg -f avfoundation -i :2 -filter_complex "[0:a]pan=2C|c0=c0|c1=c1" -f spdif -f audiotoolbox -audio_device_index 2 -` ffmpeg does not extract the ac3 but passes on the raw signal as PCM! I tried bypassing the problem by using a pipe, such as: `ffmpeg -f avfoundation -i :2 -filter_complex "[0:a]pan=2C|c0=c0|c1=c1" -f s16le - | ffmpeg -i - -f audiotoolbox -audio_device_index 2 -` Here after the pipe, ffmpeg recognised the format but this only worked for about 15 seconds and then no more data was passed. Nothing I tried solved this problem, so unless I get another bright idea or some help, I guess I am giving up on this for now. On 31/10/2023 17:39, Fred Rotbart wrote: Okay! After many hours I am making some progress (if anyone is interested). This extracts the channels, recognises the ac3 and decodes it but there are errors thrown from time to time and the rate is not constant. ffmpeg -f avfoundation -capture_raw_data true -i :2 -filter_complex "\ [0:a]pan=1C|c0=c0[a0];\ [0:a]pan=1C|c0=c1[a1];\ [a0][a1]amerge=inputs=2[a3]" -map '[a3]' \ -f s16le - \ | ffmpeg -loglevel debug \ -acodec ac3 -i - \ -af 'pan=5.1|c0=FL|c1=FR|c4=FC|c5=LFE|c2=SL|c3=SR' \ -ar 48000 -y output.wav How can I clean this up and make it more stable? Thanks -Fred On 28/10/2023 15:36, Fred Rotbart wrote: Here is one of my many other attempts. It should be clear that I am a beginner with ffmpeg. No matter what I try, ffmpeg seems to merge all the 32 USB channels into 6. For example: ffmpeg -ac 2 -c ac3 -loglevel debug -f avfoundation -i :2 -af 'pan=5.1' output.wav Part of the output: Splitting the commandline. Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '2'. Reading option '-c' ... matched as option 'c' (codec name) with argument 'ac3'. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. Reading option '-f' ... matched as option 'f' (force format) with argument 'avfoundation'. Reading option '-i' ... matched as input url with argument ':2'. Reading option '-af' ... matched as option 'af' (set audio filters) with argument 'pan=5.1'. Reading option 'output.wav' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Applying option loglevel (set logging level) with argument debug. Successfully parsed a group of options. Parsing a group of options: input url :2. Applying option ac (set number of audio channels) with argument 2. Applying option c (codec name) with argument ac3. Applying option f (force format) with argument avfoundation. Successfully parsed a group of options. Opening an input file: :2. [avfoundation @ 0x7f96400041c0] audio device 'Digiface USB (24162724)' opened For transform of length 128, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches: 1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544 2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96 3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976 For transform of length 64, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 3 matches: 1: fft_sr_asm_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480 2: fft_sr_asm_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 448 3: fft_sr_asm_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 416 Transform tree: mdct_inv_float_avx2 - type: mdct_float, len: 128, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only] fft_sr_asm_float_avx2 - type: fft_float, len: 64, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call] For transform of length 256, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches: 1:
Re: [FFmpeg-user] Extracted Audio not in Sync with Video
with rubberband you stretch the audio track by 0.1 the original speed, leaving the video track unchanged. If audio quality is that crucial to your video, you also can hasten the video by the factor 1/0.1 to make it finish together with your unchanged audio track. This can be achieved with the video filter setpts. PTS means "Presentation Time Slot". The default is 1, presenting the video track as it is. Hastening your video track then means reducing the Presentation Time Slot a bit. In your presented usecase this would mean setpts=0.1 Values in video speed between 0.8 and 1.2 deliver convincing natural results. Below and above it is more likely a video trick. On 02.11.23 18:25, Josh wrote: Sorry for top posting again, forgot about that! So this worked. I added "[1]rubberband=tempo=.1[aud];" to the filters and now the audio and video all sync properly. But this created a new problem. Now the audio has some slight distortion. It almost sounds like an mp3 that doesn't have a high enough bitrate. It's very faint, and most people probably wouldn't notice it, but I can definitely hear it. Are there other ways so change the tempo that won't distort the sound? Josh On Wed, 1 Nov 2023, Torsten Kaiser wrote: (top posted since the whole thing is top posted) That is what I do for adapting audio length to the video track In preparation I calculate the durations in seconds for VIDEO.mp4 and AUDIO.mp3 separately. Must be different files to get the length difference. Korn Script Snippet # ADSS is audio length in seconds (n.nn) # VDSS is video length in seconds (n.nn) typeset -F5 TEMPO=$(( $ADSS / $VDSS )) # calculates the correction factor for audio length, five digits precision #then I apply the rubberband filter to the AUDIO.mp3 ffmpeg -y -i .AUDIO.mp3 -af rubberband=tempo=$TEMPO audio-corrected.mp3 #Merging corrected audio and video ffmpeg -y -i .VIDEO.mp4 -i audio-corrected.mp3 TARGET.mp4 #Note: rubberband has two nice options: tempo and pitch. Tempo makes the marching band play the same tune while running a marathon. #Pitch leaves the speed as it is while the cantor either sings with the whales or attracts all bats in the forest. Default is 1 for same tempo and/or same pitch. On 31.10.23 15:34, Joshua Grauman wrote: I tried this and it doesn't help. The audio and video are still not in sync, even when you don't use the fade-out... Josh On Tue, 31 Oct 2023, 凯迪软件(咨询、售后) via ffmpeg-user wrote: ffmpeg -y -i "v1-ed.mp4" -i "a1-ed.wav" -filter_complex "[1]anull[aud]; [0]fade=t=out:st=6673.87:n=24[out]" -strict experimental -shortest -map 0:v:0 -map 1:a:0 "lecture.mp4" ?? You can try using this command to see if it can solve your problem. The translation in English is: "Try canceling the fade-in and fade-out effect you added." china kaidi --Original-- From: "FFmpeg user questions" My use case is that I want to extract audio from a mp4, edit the audio, and then put the audio and the video back together. It works fine, but over the course of the two hour video, the audio gets out of sync with the video and falls behind it (visibly, so you can see the mouth and sound aren't in sync). I extract the audio with a command like this: ffmpeg -y -i "v1-ed.mp4" -vn "a1.wav" I edit a1.wav with audacity to create a1-ed.wav. And then combine audio and video with a command like this: ffmpeg -y -i "v1-ed.mp4" -i "a1-ed.wav" -filter_complex "[1]anull[aud]; [0]fade=t=out:st=6673.87:n=24[out]" -strict experimental -shortest -map [out] -map [aud] "lecture.mp4" Is there any easy way to make sure the audio stays sync'd through this process? Thanks, Josh ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email