stefets2112
Posts: 10
Joined: Sat Oct 18, 2014 3:21 pm

Making videos with sound for Youtube possible ?

Sat Oct 18, 2014 8:10 pm

Hello!

I'm testing the camera board and one of my goal is to make videos for Youtube with the RPI Camera Board.

I have a bug, I can't sync. the video with the audio, let me explain.

I'm a guitar player so I record my guitar track on a PC, output is a wave file.
In the same time, I record a video with the RPI Camera Board.
Finally, I load the video file into Sonar Producer Edition and I can move the wave track to fit with the video track.
I record at 640X480 with 24 fps, 30 fps and so on...
It's impossible to fit the audio with the video, after 30 seconds the video is no more synch with the audio.

My question is : What is the setting for recording at real time ?!?! When I record with my Sony cam I can synch with the audio easly but I can't with the RPI camera ! Do I have to set FPS at a specific value ?

I tried picamera python object model and raspivid but no luck....

Please help !

Stef

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Sun Oct 26, 2014 12:54 pm

Hi,
I have tried something simular as you. I wanted to record Video and Audio (over Usbstick pluged in the pi), so i got 2 files aswell.
If you watch the file lenght of the single files, you will notice, that the Videofile is everytime some sec longer.
I have find out, that the pi cam isnt recording 25 fps, it is recording something like 25,1234 fps.
If you want to record 1000 sec, you´ll get 25123,4 frame instad of 25000. Every Programm now things that the video is something like 1006 sec long (25123,4Frames : 25F/sec).

If you now want to sync this Videofile with the Audio file, witch is realy 1000 sec long, your resaulted video must run out of sync.
You have to strech the audio files for 6 sec to make this work.

Ive created an ffmpeg code to do this automaticly...

Hope you will understand that and forgive me my bad english.

Cheers

stefets2112
Posts: 10
Joined: Sat Oct 18, 2014 3:21 pm

Re: Making videos with sound for Youtube possible ?

Tue Oct 28, 2014 9:12 pm

Hi,

Thanks for your reply, so there's a kind of solution !

You mention that you have created a ffmpeg code to fix that ?

Can you share your script ? And explain me how to use your it?

Thanks !

deivid
Posts: 46
Joined: Thu Oct 23, 2014 7:08 am

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 7:00 am

Testing it I've got an approximation: The camera gives 1.5% more fps than it should. Maybe because I've overclocked to 950MHz? That'd make it almost 10% of the clock difference..
Anyway, if you are using ffmpeg

raspivid [parameters] -r 20 | ffmpeg -r 20.3 -i - [more parameters]

is almost perfect. I'd like to contact <someone who knows about / designed the camera> to see if the clock really makes the frames drift (I'd get inconsistent drift on an ondemand governor)

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 7:57 am

Hi,
my pi isnt overclocked jet and the camera gives me the same % more Fps extra. Seems that it makes a difference if you raise or lower the Resolution.

The first script simple starts the Recording.

ssh [email protected] raspivid -o Tisch2.h264 -awb fluorescent -br 55 -t 0 -w 1280 -h 720 -ex fixedfps -fps 25 -b 6000000 & arecord -f S16_LE -D hw:1,0 Tisch2.wav

the second script kills the recordings, copys the files to my Desktop PC and uses ffmpeg to get the Video.

ssh [email protected] << _EOF_
killall -- raspivid
killall -- arecord
_EOF_
scp [email protected]:/home/pi/Tisch2.h264 /home/kai/Arbeitsfläche/rawfiles/Tisch2-$datum-$$.h264
scp [email protected]:/home/pi/Tisch2.wav /home/kai/Arbeitsfläche/rawfiles/Tisch2-$datum-$$.wav

ffmpeg -i /home/kai/Arbeitsfläche/rawfiles/Tisch2-$datum-$$.h264 -ss 0.4 -i /home/kai/Arbeitsfläche/rawfiles/Tisch2-$datum-$$.wav -vcodec copy -acodec aac -strict experimental -filter:a atempo="1.013,atempo=0.973" /home/pbckarben/Arbeitsfläche/Output/Tisch2-$datum2.mp4

not yet very elegant, but its the first time after 3 Month of research iv got it synced. Even if i record 3 hours...

I set up a new Partition on my SD Card with XFS as filesystem to get no Alsa Buffer Overrun...

If someone could give me a hint how to optimate this, it would be very helpful.

deivid
Posts: 46
Joined: Thu Oct 23, 2014 7:08 am

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 8:17 am

You could do everything at once:

raspivid -awb fluorescent -br 55 -t 0 -w 1280 -h 720 -ex fixedfps -fps 25 -b 6000000 -o - | ffmpeg -r 25.37 -i - -f alsa -ar 48000 -ac 1 -itsoffset 1 -i hw:1,0 -c:v copy -r 25 -vsync 1 -c:a aac -strict experimental output-mp4


I might've mistaken somewhere but this should give you a nice output file with audio and it should be synced.
if it's not synced:
*at the beginning: play with itsoffset
*over time: play with -r 25.37 (actual FPS you get, you can test it or 'eyeball' it)

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 8:44 am

Thx for the post.

Ive tryed this before. the Problem was, that ive to Compile an ffmpeg with alsa support.
I think recording and "encoding with FFmpeg" will totaly overload the Pi.??

Have you tried this yet? have you compiled your ffmpeg or is it possible to install the missing libs or what ever?

deivid
Posts: 46
Joined: Thu Oct 23, 2014 7:08 am

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 4:45 pm

The cpu is at 20% while doing all that. You have to compile it but I can send you my binaries if you want

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 6:16 pm

Yeah that would be great!

Ive compiled it before, but i followed an old tutorial and run in some troubles expacaly with alsa buffer overrun.

stefets2112
Posts: 10
Joined: Sat Oct 18, 2014 3:21 pm

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 7:12 pm

Guys you are going to make my day :)

Awaiting binaries to start testing !

deivid
Posts: 46
Joined: Thu Oct 23, 2014 7:08 am

Re: Making videos with sound for Youtube possible ?

Wed Oct 29, 2014 7:39 pm

Link here (tar.gz)
If you get a "file not found" just run ldd on the file and check if you have some file placed somewhere else
This is compiled with x264 and fdk_aac, nothing else. (perfect for HLS/rtmp)

Code: Select all

$ ldd eba_os/ffmpeg 
        /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6fd4000)                                                                                                                                                                                                                
        libasound.so.2 => /usr/lib/arm-linux-gnueabihf/libasound.so.2 (0xb6f09000)                                                                                                                                                                                              
        libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6e98000)                                                                                                                                                                                                            
        librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xb6e89000)                                                                                                                                                                                                          
        libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6e61000)                                                                                                                                                                                                    
        libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6e42000)                                                                                                                                                                                                
        libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6d12000)                                                                                                                                                                                                            
        libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6d07000)
        /lib/ld-linux.so.3 => /lib/ld-linux-armhf.so.3 (0xb6fe2000)


stefets2112
Posts: 10
Joined: Sat Oct 18, 2014 3:21 pm

Re: Making videos with sound for Youtube possible ?

Thu Oct 30, 2014 2:30 am

Thanks for the file!

I started my test with this command line :

Code: Select all

raspivid -awb fluorescent -br 55 -t 0 -w 1280 -h 720 -ex fixedfps -fps 25 -b 6000000 -o - | ffmpeg -r 25.37 -i - -f alsa -ar 48000 -ac 1 -itsoffset 1 -i hw:1,0 -c:v copy -r 25 -vsync 1 -c:a aac -strict experimental output-mp4
I have errors with the audio device / channel, this is not a problem for me because the audio is created by another software. I don't want ffmpeg to synch with the audio, I will do that with another software. I just want ffmpeg to 'resize' the video at the real timeline.

Can you help me with a simple command line that will output a video with an adjustment of the fps ?

For example, recording 1 minute video than pipe the output with ffmpeg with no audio support ?

Many thanks for your support and time !

Stef

deivid
Posts: 46
Joined: Thu Oct 23, 2014 7:08 am

Re: Making videos with sound for Youtube possible ?

Thu Oct 30, 2014 3:11 am

Try this one:

Code: Select all

raspivid -awb fluorescent -br 55 -t 0 -w 1280 -h 720 -ex fixedfps -fps 25 -b 6000000 -o - | ffmpeg -r 25.37 -i - -c:v copy -r 25 -an output-mp4
But if you fix the problem you can get everything done at the same time

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Thu Oct 30, 2014 7:47 am

Haven´t test it jet but, i think he´s getting alsa buffer overrun errors.
Did you have the same problems before and do you know how to fix that?
Maybe an other USB soundcard?
Ive tryed to increase the Alsa Buffer, but that doesn´t work or didn´t fix the problem!

I´m starting testing tomorrow, because my pi isn´t here today.

Thx

stefets2112
Posts: 10
Joined: Sat Oct 18, 2014 3:21 pm

Re: Making videos with sound for Youtube possible ?

Fri Oct 31, 2014 12:30 am

Hi!

deivid you nailed it !

I have not enough tools on my windows pc to merge the video with the wave file but I was able to play the video with media player and the wave file with an audio player and synch manually.

I recorded a 3 minutes video and audio and no doubt ffmpeg do the job very well ! The ouput video was at 24.998pfs

I will try to replace the raspivid command line with a python script using the picamera object model. The script will call ffmpeg after the recording.

Many thanks for your help guys !

Stefets2112
Quebec, Canada

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Fri Oct 31, 2014 7:36 am

Got confused yesterday, geting alsa buffer xrun errors while recording.
Ive simply recorded in the wrong Partiton (root with ext4). If recording in the XFS formated Partition, everything is fine.

This is what if got so far, comes automaticly out of my system as discribted above. https://www.youtube.com/watch?v=szbtnqA ... Zb8sxAv_gQ Its 1080p pritty cool.

Next is to install deivids ffmpeg on the pi and let the pi merge and sync the files on the fly... Thanks Deivid!

trungtran
Posts: 9
Joined: Mon Oct 06, 2014 11:25 pm

Re: Making videos with sound for Youtube possible ?

Sun Nov 02, 2014 4:57 am

Does Anyone know that raspberry pi model b can display live camera feed on screen and play audio output to a speaker at the same time ?

deivid
Posts: 46
Joined: Thu Oct 23, 2014 7:08 am

Re: Making videos with sound for Youtube possible ?

Sun Nov 02, 2014 5:08 am

yes, but there might be a small delay (~100ms)
raspivid full screen for video
arecord | aplay for audio

trungtran
Posts: 9
Joined: Mon Oct 06, 2014 11:25 pm

Re: Making videos with sound for Youtube possible ?

Sun Nov 02, 2014 5:12 am

Here is the link to my original post. I been working on this project. But the code im using doesn't give me the correct audio output. http://www.raspberrypi.org/forums/viewt ... 63&t=90247

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Tue Nov 04, 2014 7:41 am

Hi, ive testing deivids ffmpeg for some days now.
Ive trouble with Alsa Buffer Xrun, i think it is possible that it is an underrun caused of unsync...

Ive also notice that no matter how low the input bitrate from raspivid is, ffmpeg is always writing with 5 mbits.
Ive tryed to set -b:v 1000k but that does not have any effect.

The code that ive actually use is
raspivid -awb fluorescent -br 55 -t 0 -w 1920 -h 1080 -ex verylow -fps 25 -b 1000000 -o - | ffmpeg -r 25.14 -i - -f alsa -ar 44100 -ac 1 -itsoffset 6 -i hw:1,0 -c:v copy -r 25 -c:a aac -strict experimental -b:v 1000k b:a 128k output.mp4

Is there any way to tell ffmpeg it should only use 1mbit?

deivid
Posts: 46
Joined: Thu Oct 23, 2014 7:08 am

Re: Making videos with sound for Youtube possible ?

Tue Nov 04, 2014 5:37 pm

If you copy the video codec, none of the options apply so what you are doing is the same as this

Code: Select all

raspivid -awb fluorescent -br 55 -t 0 -w 1920 -h 1080 -ex verylow -fps 25 -b 1000000 -o - | ffmpeg -r 25.14 -i - -f alsa -ar 44100 -ac 1 -itsoffset 6 -i hw:1,0 -c:v copy -c:a aac -strict experimental -b:a 128k output.mp4

I removed the audio parts (and the -ex verylow because it didn't work for me) because I have no mic atm.

Code: Select all

raspivid -awb fluorescent -br 55 -t 0 -w 1920 -h 1080  -fps 25 -b 1000000 -o - | ./eba_os/ffmpeg -r 25.14 -i - -c:v copy output.mp4
does record at 1mbit
frame= 323 fps= 42 q=-1.0 Lsize= 1577kB time=00:00:12.84 bitrate=1005.2kbits/s
also consider using for audio

Code: Select all

-c:a libfdk_aac -afterburner 0
since it uses less cpu and has better audio quality

EGO1981
Posts: 11
Joined: Fri Oct 03, 2014 11:29 pm

Re: Making videos with sound for Youtube possible ?

Wed Nov 05, 2014 7:48 am

Dont know why but this code,

Code: Select all

raspivid -br 55 -t 0 -w 1920 -h 1080 -ex verylong -fps 25 -br 1000000 -o - | ffmpeg -r 25.14 -i - -c:v copy -y output.mp4
gives me this results

Code: Select all

frame=  196 fps= 75 q=-1.0 size=    6110kB time=00:00:07.79 bitrate=6420.6kbits/
Maybe i did something wrong by installing it?

OMG ive set -br 1000000 (Brightness) instead of -b (bitrate)
sry for that

Return to “Camera board”