<p>Is there a way one can compress captured video input before saving to file? I have raspberry pi that I am using to record youtube videos. 1-2 min video takes over a Gb of space. I cant compress the recorded file because the pi does not have enough space to record the initial video. Is there a way using ffmpeg I can compress my webcam video directly after its captured before saving the file versus waiting until I am done recording then compressing the saved file?</p>

<p>I'm using </p>

<p><code>ffmpeg \ -f v4l2 \ -thread_queue_size 5000 -framerate 25 -video_size 640x480 -i /dev/video0 -y -c:v libx264 ~/Desktop/ffmpegTesting/money.mp4 \ -thread_queue_size 5000 -f alsa -ac 1 -ar 44100 -i hw:1,0 -t 30 -c:v copy -c:a ~/Desktop/ffmpegTesting/money.mp4 \</code></p>

CC BY-SA 4.0
2019-02-09T20:37:07.473Z
Ive managed to compress before saving but the audio is disapearring now :(
sirshakir
CC BY-SA 4.0
2019-02-09T20:38:05.667Z
to be more exact. The audio disappears around the 10-11 second mark in the video
sirshakir
CC BY-SA 4.0
2019-02-09T20:53:40.327Z
Syntax is malformed, it should be: `ffmpeg -f v4l2 -thread_queue_size 5000 -framerate 25 -video_size 640x480 -i /dev/video0 -thread_queue_size 5000 -f alsa -i hw:1,0 -c:v libx264 -ac 1 -ar 44100 -c:a aac -y ~/Desktop/ffmpegTesting/money.mp4`
Gyan
CC BY-SA 4.0
2019-02-09T20:59:18.197Z
The error I am getting now is :  cannot set channel count to 2 (Invalid argument)
hw:1,0: Input/output error
sirshakir
CC BY-SA 4.0
2019-02-09T21:23:35.520Z
Ok i fixed problem by setting hw:1,0 to plughw:1,0
sirshakir
CC BY-SA 4.0
2019-02-09T21:23:42.953Z
ffmpeg -f v4l2 -thread_queue_size 5000 -framerate 25 -video_size 640x480 -i /dev/video0 -thread_queue_size 5000 -f alsa -i plughw:1,0 -c:v libx264 -ac 2 -ar 44100 -c:a aac -y ~/Desktop/ffmpegTesting/money.mp4
sirshakir
CC BY-SA 4.0
2019-02-09T21:24:03.967Z
The audio still times out before the video ends
sirshakir
CC BY-SA 4.0
2019-02-09T21:28:37.017Z
After further testing it appears the audio always times out a 4 - 5 seconds before the video ends no matter the length of video. Im starting to belive it has somehting to do when I stop the process. Maybe there is a lag between the video being compressed and adding the audio to it.
sirshakir
CC BY-SA 4.0
2019-02-10T04:49:31.770Z
How are you ending the process?
Gyan
CC BY-SA 4.0
2019-02-11T19:51:44.097Z
Either by pressing Q or Ctrl C
sirshakir
<ffmpeg><compression>
ffmpeg video compression : Compress captured video being before saving to file
sirshakir
# ffmpeg video compression : Compress captured video being before saving to file

(Asked by: username_0 on 2019-02-09)

Is there a way one can compress captured video input before saving to file? I have raspberry pi that I am using to record youtube videos. 1-2 min video takes over a Gb of space. I cant compress the recorded file because the pi does not have enough space to record the initial video. Is there a way using ffmpeg I can compress my webcam video directly after its captured before saving the file versus waiting until I am done recording then compressing the saved file?

I'm using

`ffmpeg \ -f v4l2 \ -thread_queue_size 5000 -framerate 25 -video_size 640x480 -i /dev/video0 -y -c:v libx264 ~/Desktop/ffmpegTesting/money.mp4 \ -thread_queue_size 5000 -f alsa -ac 1 -ar 44100 -i hw:1,0 -t 30 -c:v copy -c:a ~/Desktop/ffmpegTesting/money.mp4 \`

**Tags:** ffmpeg, compression

> **Comments:**
> **username_0**: Ive managed to compress before saving but the audio is disapearring now :(  
> **username_0**: to be more exact. The audio disappears around the 10-11 second mark in the video  
> **username_1**: Syntax is malformed, it should be: `ffmpeg -f v4l2 -thread_queue_size 5000 -framerate 25 -video_size 640x480 -i /dev/video0 -thread_queue_size 5000 -f alsa -i hw:1,0 -c:v libx264 -ac 1 -ar 44100 -c:a aac -y ~/Desktop/ffmpegTesting/money.mp4`  
> **username_0**: The error I am getting now is :  cannot set channel count to 2 (Invalid argument) hw:1,0: Input/output error  
> **username_0**: Ok i fixed problem by setting hw:1,0 to plughw:1,0  
> **username_0**: ffmpeg -f v4l2 -thread_queue_size 5000 -framerate 25 -video_size 640x480 -i /dev/video0 -thread_queue_size 5000 -f alsa -i plughw:1,0 -c:v libx264 -ac 2 -ar 44100 -c:a aac -y ~/Desktop/ffmpegTesting/money.mp4  
> **username_0**: The audio still times out before the video ends  
> **username_0**: After further testing it appears the audio always times out a 4 - 5 seconds before the video ends no matter the length of video. Im starting to belive it has somehting to do when I stop the process. Maybe there is a lag between the video being compressed and adding the audio to it.  
> **username_1**: How are you ending the process?  
> **username_0**: Either by pressing Q or Ctrl C  

---

## 0 answers

