Cut video with ffmpeg in Ubuntu - linux

I execute the command in Ubuntu to cut a video:
/usr/bin/ffmpeg -i video.mp4 -an -ss 00:00:1 -t 00:00:08 -async 1
In Windows 10 its work, but not work in Ubuntu.
I receive in Ubuntu the warning:
Trailing options were found on the commandline.
and receive the error:
At least one output file must be specified
What do I do?

do:
ffmpeg -i video.mp4 -ss 00:00:01 -t 00:00:08 -async 1 cut.mp4
just add output file name, in this situation - cut.mp4

Related

Having issues with FFMPEG

Im using the following code to timelapse a set of files in the format of yyyy-mm-dd-hh-mm
It is using fswebcam to make the image and does so every minute with a crontab, that works fine, however the ffmpeg isn't working, im using the following command for it
cat $(ls | sort -V) | ffmpeg -framerate 10 -i - -vcodec libx264 -pix_fmt yuv420p -r 20 outputvideo.avi
When running the code I get a
pipe:: Invalid data found when processing input
I got this from https://youtu.be/_uVaZalaSbI to make the image creator and https://youtu.be/miYSR8yjbAM to make the video processor.
Any help would be nice, thanks.
Thanks for mivk for helping on this, and in my case the command
for f in *.jpg; do cat "$f"; done | ffmpeg -r 10 -f image2pipe -i - -vcodec libx264 -pix_fmt yuv420p outputvideo.avi
worked perfectly for me and outputted a timelapse as planned.

How to log ffmpeg process to file using background terminal?

I'm facing a big misunderstanding with bash.
Executing line
ffmpeg -y -i "file.mp4" -map 0:v:0 -map 0:a:0 -c:v copy -c:a copy -c:s copy "file.mkv" 2> output.log
process is logged to the file.
But executing
xfce4-terminal -e "ffmpeg -y -i \"file.mp4\" -map 0:v:0 -map 0:a:0 -c:v copy -c:a copy -c:s copy \"file.mkv\"" 2> /home/$(whoami)/Desktop/output.log"
the logging to file doesn't work.
What could cause this issue?
It can get tricky escaping things when passing a script to a terminal. I would recommend putting your ffmpeg command into a file (e.g. your-file.sh, making it executable (by running chmod +x your-file.sh), then telling the terminal to run that file.
Alright, I found one solution to my problem by adding nohup before ffmpeg like this:
xfce4-terminal -e "nohup ffmpeg -y -i \"file.mp4\" -map 0:v:0 -map 0:a:0 -c:v copy -c:a copy -c:s copy \"file.mkv\""
At least this stores me all terminal output data to /home/$(whoami)/nohup.out file.
Thanks anybody for trying to help me! :)

Get PID of process in one line

I have a bash script that is called by a phone system that gets some audio from a URL and (using ffmpeg, mplayer etc.) then pipes it back to the application. The file can have several URL's that are called so if the first one say goes off line or gives a 404 it will go to the next line.
I have an issue where some times the server will produce content however there is no audio. In such a case I want to kill the current PID of ffmpeg, mplayer etc. so that the script should move on.
I can't foreground it and get the last PID since once it's ran in the foreground the media is no longer being piped to the application calling it. I can't use exec in the beginning since if I then issue a kill to the PID the script dies which I don't want.
The script looks something like this:
#!/bin/bash
/usr/bin/ffmpeg -i 'http://1.1.1.1/soft_music' -vn -ar 8000 -ac 1 -f s16le -
/usr/bin/ffmpeg -i 'http://2.2.2.2/soft_music' -vn -ar 8000 -ac 1 -f s16le -
I assume I need to add something that will allow me to log the pid of the current ffmpeg command running so my external script can get it and kill it. Once that's done it will go to the next line and try the next stream from 2.2.2.2
It seems the script below would do what I am looking for:
#!/bin/bash
/usr/bin/ffmpeg -i 'http://1.1.1.1/soft_music' -vn -ar 8000 -ac 1 -f s16le - & echo $! > /tmp/my_pid
%1
/usr/bin/ffmpeg -i 'http://2.2.2.2/soft_music' -vn -ar 8000 -ac 1 -f s16le - & echo $! > /tmp/my_pid
%1
What this does is put the ffmpeg process into the background just for one moment to store the PID in a file. As soon as it goes to the next line we recover it with the job ID which will be 1.

Recording with arecord stops after 1h 33m Under Fedora 23

I'm using this command to record audio in Linux Fedora 23
/usr/bin/arecord -d 11400 -D hw:1,0 -f S32_LE -c2 -r48000 -t wav | lame -b 192 - longrec.mp3 >> output.txt 2>&1 & echo $!
Basically I want an mp3 record of 3 hours and 10 minutes (11400 seconds) from the input soundcard. Everything works fine when started, but it always stops after 1h33m12s. File output.txt shows nothing of any interest:
LAME 3.99.5 64bits (http://lame.sf.net)
Using polyphase lowpass filter, transition band: 18774 Hz - 19355 Hz
Encoding <stdin> to longrec.mp3
Encoding as 48 kHz j-stereo MPEG-1 Layer III (8x) 192 kbps qval=3
Any clue of what the problem is?
[SOLVED] instead of using arecord I have switched to ffmpeg, command:
ffmpeg -f pulse -i alsa_input.usb-Focusrite_Scarlett_Solo_USB-00.analog-stereo -t 11400 -c:a libmp3lame -b:a 192k longrec.mp3
Has the same effect as arecord one and it also doesn't block sound-card resource (I can run multiple ffmpeg record instance from the same source, while with arecord I can do only one).

How to record audio with ffmpeg on linux?

I'd like to record audio from my microphone. My OS is ubuntu. I've tried the following and got errors
$ ffmpeg -f alsa -ac 2 -i hw:1,0 -itsoffset 00:00:00.5 -f video4linux2 -s 320x240 -r 25 /dev/video0 out.mpg
ffmpeg version 0.8.8-4:0.8.8-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav
developers
built on Oct 22 2013 12:31:55 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release.
Please use avconv instead.
ALSA lib conf.c:3314:(snd_config_hooks_call) Cannot open shared library
libasound_module_conf_pulse.so
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM hw:1,0
[alsa # 0xbda7a0] cannot open audio device hw:1,0 (No such file or directory)
hw:1,0: Input/output error
Then I tried
$ ffmpeg -f oss -i /dev/dsp audio.mp3
ffmpeg version 0.8.8-4:0.8.8-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav
developers
built on Oct 22 2013 12:31:55 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release.
Please use avconv instead.
[oss # 0x1ba57a0] /dev/dsp: No such file or directory
/dev/dsp: Input/output error
I haven't been able to get ffmpeg to find my microphone. How can I tell ffmpeg to record from my microphone?
It seems the 'Deprecated' message can be ignored because of this topic
I realise this is a bit old. Just in case anyone else is looking:
ffmpeg -f alsa -ac 2 -i default -itsoffset 00:00:00.5 -f video4linux2 -s 320x240 -r 25 -i /dev/video0 out.mpg
This way it will use the default device to record from. You were also missing a -i before the video capture device - /dev/device0
If you want to get more specific you should take a look in /proc/asound.
Check the cards, devices, pcm files and the card subdirectories. You should be able to glean enough information there to be able to make an educated guess; e.g hw:1,0 or hw:2,0
The documentation may provide further clues:
http://www.alsa-project.org/main/index.php/DeviceNames
The same goes for the webcam - it may not be /dev/video0, perhaps you have an external webcam plugged in and its at /dev/video1 - Have a look in the /dev directory and see whats available
solved !
ffmpeg -f pulse -ac 2 -i default -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -threads 0 -y /media/t/TBVolume/desktop/output.mkv
First, list your AV devices using:
ffmpeg -list_devices true -f dshow -i dummy
Assuming your audio device is "Microphone Array", you can use:
ffmpeg -f dshow -i audio="Microphone Array" -c:a libmp3lame -b:a 128k OUTPUT.mp3
Here, 128k is the sampling rate. You can check all options for sampling rates (CBR) here.

Resources