FFMpeg - Print Date and Time during recording like surveillance - datetime

I need to record video from RaspberryPi, using this Bash script:
#!/bin/sh
/usr/bin/ffmpeg -f video4linux2 -input_format h264 -video_size 320x240 -framerate 15 -i /dev/video0 -vcodec copy -an "/var/ayron/videotrap/videos/pctrace_$(date +"%Y_%m_%d_%H_%M_%S").h264"
In this way, I can report the date and time of start recording. But I need to show on video the Date and Time during registration. Which kind of filter must I use?
Thanks for your supply.

Use drawtext filter:
/usr/bin/ffmpeg -f video4linux2 -input_format h264 -video_size 320x240 -framerate 15 -i /dev/video0 -an -vf "drawtext=text='%{localtime\:%Y_%m_%d_%H_%M_%S}'" "/var/ayron/videotrap/videos/pctrace_$(date +"%Y_%m_%d_%H_%M_%S").h264"
You can't filter and stream copy the video at the same time so -vcodec copy has been omitted.
If you want to use colons (:) in the time then you'll have to do some ugly escaping as shown in How to drawtext colon with localtime in ffmpeg -filter_complex?

Related

Sync audio in video via ffmpeg?

I need to fit audio with video, but sync option is negative (audio is -350 ms) How to fit it with video? I see only examples when audio is +, but not -
ffmpeg -i "sample.mp4" -itsoffset 13.84 -i "sample.mp4" -map 1:v -map 0:a -c copy "movie-video-delayed.mp4"

Mixing audio stream into video stream using ffmpeg while retaining original audio from the video stream as background [duplicate]

Can I overlay/downmix two audio mp3 files into one mp3 output file using ffmpeg?
stereo + stereo → stereo
Normal downmix
Use the amix filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amix=inputs=2:duration=longest output.mp3
Or the amerge filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amerge=inputs=2 -ac 2 output.mp3
Downmix each input into specific output channel
Use the amerge and pan filters:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex "amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3" output.mp3
mono + mono → stereo
Use the join filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex join=inputs=2:channel_layout=stereo output.mp3
Or amerge:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amerge=inputs=2 output.mp3
mono + mono → mono
Use the amix filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amix=inputs=2:duration=longest output.mp3
More info and examples
See FFmpeg Wiki: Audio Channels
Check this out:
ffmpeg -y -i ad_sound/whistle.mp3 -i ad_sound/4s.wav -filter_complex "[0:0][1:0] amix=inputs=2:duration=longest" -c:a libmp3lame ad_sound/outputnow.mp3
I think it will help.
The amix filter helps to mix multiple audio inputs into a single output.
If you run the following command:
ffmpeg -i INPUT1 -i INPUT2 -i INPUT3 -filter_complex amix=inputs=3:duration=first:dropout_transition=3 OUTPUT
This command will mix 3 input audio streams (I used two mp3 files, in the example below) into a single output with the same duration as the first input and a dropout transition time of 3 seconds.
The amix filter accepts the following parameters:
inputs:
The number of inputs. If unspecified, it defaults to 2.
duration:
How to determine the end-of-stream.
longest:
The duration of the longest input. (default)
shortest:
The duration of the shortest input.
first:
The duration of the first input.
dropout_transition:
The transition time, in seconds, for volume renormalization when an input stream ends. The default value is 2 seconds.
For example, I ran the following command in Ubuntu:
FFMPEG version: 3.2.1-1
UBUNTU 16.04.1
ffmpeg -i background.mp3 -i bSound.mp3 -filter_complex amix=inputs=2:duration=first:dropout_transition=0 -codec:a libmp3lame -q:a 0 OUTPUT.mp3
-codec:a libmp3lame -q:a 0 was used to set a variable bit rate. Remember that, you need to install the libmp3lame library, if is necessary. But, it will work even without the -codec:a libmp3lame -q:a 0 part.
Reference: https://ffmpeg.org/ffmpeg-filters.html#amix
For merging two audio files with different volumes and different duration following command will work:
ffmpeg -y -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:0]volume=0.09[a];[1:0]volume=1.8[b];[a][b]amix=inputs=2:duration=longest" -c:a libmp3lame output.mp3
Here duration can be change to longest or to shortest, you can also change the volume levels according to your need.
If you're looking to add background music to some voice use the following command as in the gaps the music will become loud automatically:
ffmpeg -i bgmusic.mp3 -i audio.mp3 -filter_complex "[1:a]asplit=2[sc][mix];[0:a][sc]sidechaincompress=threshold=0.003:ratio=20[bg]; [bg][mix]amerge[final]" -map [final] final.mp3
In this threshold is something whose value will decide how much loud the audio should be, the less the threshold more the audio will be. Ratio gives how much the other audio should be compressed, the more the ratio the more the compression is.
If they are different length, you can use apad to add a silent sound to the shortest one
With Bash
set 'amovie=a.mp3 [gg]; amovie=b.mp3 [hh]; [gg][hh] amerge'
ffmpeg -f lavfi -i "$1" -q 0 c.mp3
Example
You can use the following command arguments:
// Command is here
let commandValue = "-y -i \(recordedAudioPath) -i \(backgroundAudio) -filter_complex [\(0):a][\(1):a]amerge=inputs=\(2)[a] -map [a] -ac \(2) -shortest -preset ultrafast \(outputPath)"
MobileFFmpeg.execute(commandValue)

What different video formats RTMP streaming support?

In almost all the online references related to FFMPEG and RTMP, I am getting -f as flv. Is there any other formats.
(I have tried avi, mpeg and h264, but no success.)
Currently, I am running following command -
ffmpeg -re -i video.mp4 -f s16le -ar 48000 -ac 2 -i audio.wav -c copy -f flv rtmp://192.168.0.1:1935/myapp/stream
The issues with -f flv in my case are -
It doesn't support 48k sample rate.
None of my input videos are in flv format (I have to convert it to flv externally).
P.S. - I am using VLC as RTMP player.
EDIT -
I am getting following error with 48k audio file -
[flv # 0x5650ba7afb80] FLV does not support sample rate 48000, choose from (44100, 22050, 11025)

Combine two ffmpeg commands

Is there a way to combine the following two ffmpeg commands into one?
ffmpeg -i OutputAudioEN.mp4 -acodec aac -strict -2 german.mp4
ffmpeg -i german.mp4 -c copy -f segment
-segment_list audio-de.m3u8 -segment_time 10 output%03d.ts
Is this possible to use the output from the first command for the second line, without using two separate commands?
Well, here I'm making my comment as a proper answer. What I'm suggesting here is you can directly segment the video and then encode the audio using acc according to your need. Following command works for me.
ffmpeg -i OutputAudioEN.mp4 -f segment -segment_list audio-de.m3u8 -segment_time 10 -acodec aac -strict -2 output%03d.ts
Like this you can segment the video while audio encoding also happens at the meantime.
Hope this helps you!

MPEG-TS audio synchronization lost on segmentation

I use FFmpeg for encoding my iphone video (on debian) and mediafilesegmenter (on mac OS server). For encoding this is my commande :
ffmpeg -i INPUT -y -acodec libfaac -ar 22000 -ab 40k -vcodec libx264 -b 600k \
-bt 600k -vpre slow -vpre baseline -threads 1 -level 30 -r 10 -s 400x224 \
-map_chapters -1:-1 -f ipod INPUT.mp4
When i read the INPUT.mp4 everything is OK with audio.
But when I use the Apple Segmenter (mediafilesegmenter) i have a descync between audio & video.
Is my command line is wrong ? or it's a Apple segmenter bug. The mediastreamvalidator show me :
WARNING: Media segment contains a video track but does not contain any IDR access unit with a SPS and a PPS
But i don't know if cause the audio desync.
I have the latest mediafilesegmenter download from connect.apple.com.

Resources