date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,552,663,800,000 |
I want to rename files with a .m4a extension recursively in child directories to remove unwanted characters in audio files such as [ ' ].
That's because that this below happened to this file 04 Tears Don't Fall.m4a without the other files:
Could not load file 2005-09-30 - The Poison (Deluxe Edition) [US -
88697-09021-2 - 2007]/04 Tears Don't Fall.m4a. Maybe it is not a
supported file format?
When trying to load using ffmpeg, got the following error: FFmpeg
could not read the file.
|
#!/bin/bash
shopt -s globstar
for fn in **/*\'*.m4a; do echo mv "$fn" "${fn/\'/}"; done
echo is needed for checking the result before real renaming.
| How to rename files recursively with a specific extension to remove unwanted characters in audio files |
1,552,663,800,000 |
I'm trying to record my screen losslessly (or at near lossless quality) with hardware acceleration on a 6700 XT with ffmpeg. I'm running Linux Mint with the 5.14.14-051414-generic kernel.
I've tried:
ffmpeg -vaapi_device /dev/dri/renderD128 -f x11grab -video_size 2560x1440 -i :0 -r 60 -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 0 output.mp4
ffmpeg says it's recording at 60 fps, but the recording is choppy and slightly miscolored. I'm assuming the color issue is from the color format nv12, but rgb or rgb8 gives an error.
I've also tried using kmsgrab:
ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=w=2560:h=1440:format=nv12' -c:v h264_vaapi -qp 0 output.mp4
But it gives the error:
[kmsgrab @ 0x558f001c8d80] Using plane 65 to locate framebuffers.
[kmsgrab @ 0x558f001c8d80] Failed to get framebuffer 127: Invalid argument.
pipe:: Invalid argument
The number after Failed to get framebuffer is usually 127 or somewhere from 134 to 136.
I got these commands here.
|
TL,DR: I think you've mostly hit bugs in ffmpeg and/or other parts of the stack that seem be fixed by now.
Your first command:
ffmpeg -vaapi_device /dev/dri/renderD128 -f x11grab -video_size 2560x1440 -i :0 -r 60 -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 0 output.mp4
Works for me, on Debian Bookworm with ffmpeg 5.1 (I only changed the size to match my monitor), with no color issue and 60 fps, on the same GPU (6700 XT). So maybe there was (at the time) a bug somewhere in your version of ffmpeg or in VA-API drivers or something.
It does not use the highest quality, -qp 0 may be out of the supported range for this encoder and subsequently ignored, apparently it falls back to a default value:
No quality level set; using default (20).
Values as low as -qp 1 seem to be accepted, and may bring enough quality for your needs.
Regarding kmsgrab, note that using it requires either running as root, or having the CAP_SYS_ADMIN capability set. This may well be the cause for your error, and a fix is to set the capability on ffmpeg:
setcap cap_sys_admin=ep /usr/bin/ffmpeg
This is not ideal for security, and will break when ffmpeg is updated, but it works, and your command line runs fine for me too.
Note also that using kmsgrab while also recording audio caused audio/video synchronization problems until at least ffmpeg 5.1:
https://trac.ffmpeg.org/ticket/8377
If you want to use it, you probably want to upgrade to ffmpeg 6, which in my experience fixed that last issue.
| Hardware accelerated lossless recording on a 6700 XT using ffmpeg |
1,552,663,800,000 |
I have composed the following bash script to automatically concatenate mp3 files using ffmpeg:
i=0
for f in "${@:2}"
do
filter+="[$i:a:0]"
i=`expr $i + 1`
files+="-i $f "
done
filter+="concat=n=$i:v=0:a=1[outa]"
ffmpeg $files -filter_complex $filter -map '[outa]' "$1.mp3"
However, I often have to deal with files that have spaces in their filenames, but when dragged to the terminal, all spaces get escaped, generating the following command call:
./mergemp3.sh outfilename /path/to/my\ file\ with\ spaces.mp3 /path/to/another\ file\ with\ spaces.mp3
which seems correct to me. However, ffmpeg fails with
/path/to/my: No such file or directory
So obviously, ffmpeg does not understand the space in the filename, although it is properly escaped by a backslash. I guess there's just a nifty detail going on regarding that filename list. Any ideas?
|
For clarity and safety when building command lines, arrays are your friend:
files=()
i=0
for f in "${@:2}"
do
filter+="[$((i++)):a:0]"
files+=(-i "$f")
done
filter+="concat=n=$i:v=0:a=1[outa]"
ffmpeg "${files[@]}" -filter_complex "$filter" -map '[outa]' "$1.mp3"
| ffmpeg: filenames with spaces from bash script |
1,552,663,800,000 |
I'm trying to identify files with high/low bitrate in my audio collection using a shell script. Doing file test.mp3 is very fast:
$time file test.mp3
test.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, Stereo
real 0m0.027s
However, file doesn't show the bitrate for .m4a files:
$time file test.m4a
test.m4a: ISO Media, Apple iTunes ALAC/AAC-LC (.M4A) Audio
real 0m0.056s
I tried using exiftool and ffprobe, but they seem to be at least 10 times slower:
$time exiftool test.m4a
Avg Bitrate : 131 kbps
real 0m0.532s
$time ffprobe test.m4a
Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)
real 0m0.621s
This is only about 100 files/minute, which is quite slow. Is there a faster way to find a bitrate of m4a files? I understand that ffprobe checks the stream data rather than tags so it's more precise than file. I'm OK with a less precise bitrate value as long as it's fast.
|
My experience with these tags is that they're not approximate, they're wrong, especially for older VBR-encoded MP3 files, like, off by a factor of 8, sometimes. In general, things aren't better for MP4 (which pretty much uses variable bitrate; but "MP4" contains a large family of very different audio codecs with different qualities at the same rate!)
That has to do with two things:
Audio that you compress for storage (not for sending via e.g. a digital radio station, a phone or as audio track in an online video) doesn't need to be compressed at a constant bit rate – that just makes no sense. Representing "silence" simply needs fewer bits than representing a complex moment in a multi-instrumental song. So, selecting one bitrate and sticking to it for every chunk of audio simply is either going to waste a lot of space, or to sound worse when you need more bits than average, and be good in passages where you don't notice it. Therefore, having a "sensible" constant bitrate is going to sound bad. Using a very high constant bitrate is something that we did around 2000 a lot, but it still sounded bad – simply because a lot of the encoders were simply not very good. I swear, around 2002 I could tell the different MP3 encoders I used for ripping my CDs apart by the audible artifacts – at 160 kbps. Not good; these were buggy beasts.
If, instead of constant bitrate, the encoder was set to constant quality, what bitrate do you then put into a header? The minimum ? Makes no sense, if there's a few milliseconds of silence in the song. The maximum? Makes no sense, that might just be the moment the drummer hit the crash cymbal. The average? Makes only slightly more sense, as some songs are just better to encode than others, but assuming you have songs at a relatively constant volume, genre, speed, production quality, spatial separation, in other words, if all your music sounds the same: You could get roughly the same by dividing the file size in bits by the duration of the song. That should be fast!
With that out of the way: the main time ffprobe spends is typically loading and internal setup; you can hide that well using @OleTange's GNU parallel:
# for bash, whose recursive globbing is off by default
# omit if on zsh
shopt -s globstar nullglob dotglob
# run all ffprobe in parallel.
# GNU parallel takes care of keeping output in correct order
parallel --eta \
ffprobe \
-loglevel fatal \
-output_format json \
-show_entries format=bit_rate:format=filename \
::: **/*.mp4 **/*.mp3 **/*.mpeg **/*.mpc **/*.wma **/*.opus **/*.ogg \
| jq \
'.[] | {(.filename): (.bit_rate|tonumber)} ' \
| jq --slurp \
'reduce .[] as $i ({}; . * $i)'
> allfiles.json
I tried, and for me this meant a speedup of ca 400%.
(the jq chain at the end is purely optional, but will give you a valid, nice-to-work-with document mapping file names to bit rates)
| Fast test for audio file bitrate |
1,552,663,800,000 |
I came accross this nice web. There are swf and mp3 files.
I'd like to convert them to mp4 or something, so it is viewable.
I tried gnash and ffmpeg without success.
I'm on Lubuntu 22.04
|
First of all, I'll mention some of the paths you shouldn't take and why nowadays (as long as you're running a modern distro):
Swivel can convert from swf to images/video, but it relies on Adobe AIR, which is not available on Linux.
Gnash has a dump-gnash command which might work and you might give it a go to export a raw rgb32 30fps video, but it didn't work on my system. I'll give you the command anyways:
dump-gnash -1 -D ./out.raw@30
According to this: https://stackoverflow.com/questions/20194270/convert-compressed-swf-to-mp4 you might succeed with Gnash as well.
But Gnash is an unfinished, abandoned project and that's why I'll show you how to do with a maintained project called Ruffle.
If you're getting the newest version of the software, you're gonna have to get the newest version of Rust and its components as well. To install that (at the time of writing) the command is:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
When I tried installing from the Package Manager I hit a brick wall, the command above gets the latest stable rust distribution.
You might also need to install Java (openJDK worked for me).
Now git clone ruffle master branch using git clone
cd into the ruffle folder:
git clone https://github.com/ruffle-rs/ruffle
cd ruffle/
WARNING: you apparently need a GPU for this so it won't work on a headless server :/
then run the following command:
cargo run --release --package=exporter -- path/to/file.swf
This will install the required dependencies, start the exporter and then export the slide in high quality (well in terms what quality Flash implemented back in the day... you can also play around with the command line arguments if you're not happy).
And yes, it will need to compile basically the main components of the project, but at least the end result will be good.
If the process didn't work you will need to decompress the SWFs used:
wget http://www.swftools.org/swftools-0.9.2.tar.gz
tar xvf swftools-0.9.2.tar.gz
cd swftools-0.9.2.tar.gz/
./configure
make
now cd into the src directory where you'll find the swfcombine binary which you will need for conversion:
swfcombine -d slide1.swf -o slide1dec.swf
rfxswf error: sprite doesn't end(1)
rfxswf error: sprite doesn't end(2)
Yes it will print out errors, but it seems to work.
You will need to go it for every slide, you can use find, xargs or similar to automate it (or maybe a wildcard if it's supported).
Then you can feed it into Ruffle like shown above.
According to your input (PNG or raw video) you might want to do something like this to combine the audio with the video:
ffmpeg -i /tmp/out.wav \
-f rawvideo \
-pix_fmt rgb32 \
-s:v 800x550 \
-r 30 \
-i /tmp/out.raw \
-c:v libx264 \
-r 30 \
-b 160k \
/tmp/out.mp4
Let me know if this works for your use case.
P.S. if you wanna do the mp3 merging in one go: https://superuser.com/questions/202809/join-multiple-mp3-files-lossless
Edit 1:
Please try the following for adding the audio to the image:
ffmpeg -loop 1 -i img.png -i slide1.mp3 -shortest slide1withaudio.mp4
| Convert swf files to mp4 |
1,552,663,800,000 |
The following script is meant to trim all media files in the current working directory.
#!/usr/bin/bash
trimmer() {
of=$(echo "${if}"|sed -E "s/(\.)([avimp4kvweb]{3,3}$)/\1trimmed\.\2/")
ffmpeg -hide_banner -loglevel warning -ss "${b}" -to "${ddecreased}" -i "${if}" -c copy "${of}"
echo "Success. Exiting .."
}
get_ddecreased() {
duration="$(ffprobe -v quiet -show_entries format=duration -hide_banner "${if}"|grep duration|sed -E s/duration=\([0-9]*\)\..*$/\\1/)"
echo ${duration}
ddecreased="$(echo "${duration} - ${trimming}"|bc -l)"
echo ${ddecreased}
}
rm_source() {
echo -e "Remove ${if}?[Y/n]?"
read ch
if [[ "${ch}" == 'y' ]]; then
rm "${if}"
fi
}
echo "How much of the beginning would you like to trim?"
read b
echo "How much of the end would you like to trim?"
read trimming
ls *.avi *.mkv *.mp4 *.vob >list_of_files
echo "Prompt before removing the source[Y/n]?"
read ch
while IFS="" read -r if || [[ -n "${if}" ]]; do
if [[ "${ch}" == 'y' ]]; then
get_ddecreased && trimmer && rm_source
elif [[ "${ch}" == 'n' ]]; then
get_ddecreased && trimmer && rm "${if}"
fi
echo $if
done <list_of_files
echo -e "Removing list_of_files."
rm list_of_files
If the user selected y when asked Prompt before removing the source[Y/n] and trimmer has finished trimming the first file rm_source is meant to prompt the user and wait for their input before removing the source file. This does not work as
the script does not wait for the input and proceeds straight away to echo -e "Removing list_of_files." much like there was no while loop at all.
Neither does the while loop get executed when the user selected n when asked Prompt before removing the source[Y/n] - the script proceeds straight away to echo -e "Removing list_of_files." instead of iterating through all the files listed in list_of_files. Why so?
Yet when I comment out all these lines
if [[ "${ch}" == 'y' ]]; then
get_ddecreased && trimmer && rm_source
elif [[ "${ch}" == 'n' ]]; then
get_ddecreased && trimmer && rm "${if}"
fi
within the while loop all the lines of list_of_files get printed to the screen.
What is wrong with my code?
|
Your code is essentially doing the following:
foo () {
read variable
}
while read something; do
foo
done <input-file
The intention is to have the read in foo read something from the terminal, however, it is being called in a context where the standard input stream is redirected from some file.
This means that the read in foo will read from the input stream coming from the input file, not from the terminal at all.
You may circumvent this by making the loop read from a another file descriptor than standard input:
foo () {
read variable
}
while read something <&3; do
foo
done 3<input-file
Here, the read in the loop reads from file descriptor 3, which is being connected to the input file after the done keyword. This leaves the read in the foo function free to use the original standard input stream.
In the bash shell, rather than using a hard-coded value for the extra filedescriptor, you can have the shell allocate the descriptor in a shell variable:
foo () {
read variable
}
while read something <&"$fd"; do
foo
done {fd}<input-file
This would likely set $fd to an integer like 10 or higher. The exact value is unimportant.
In your current code in the question, you may also fix your issue by avoiding creating and reading from the list of files, and instead use the file globs directly:
for filename in *.avi *.mkv *.mp4 *.vob; do
if [ ! -e "$filename" ]; then
# skip non-existing names
continue
fi
# use "$filename" here
# ... and call your rm_source function
done
This avoids redirections all-together. This also allows your code to handle the odd file with newline characters in its name.
The if statement in the loop, which tests for the existence of the named file, is necessary as the shell will, by default, retain the globbing pattern if there are no matching names for that pattern. You may get rid of the if statement in the bash shell by setting the nullglob shell option using shopt -s nullglob. Setting this option would make the bash shell remove non-matching globs completely.
Note too that this is not the same as in your code if any name matching the globbing patterns is a directory. If you have a directory called e.g. mydir.mp3, then ls would list the contents of that directory. Also, if a filename matching the patterns starts with a dash, the code using ls would likely mistake that name for a set of options.
| Why does the execution of these functions break out of this while loop? |
1,552,663,800,000 |
I'm following
Speeding up playback speed
https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
However, when I speed up my playback speed by 1.5, I'd anticipate a reduce of the video's size on par with/about the same level, yet, this is what I got:
-rwxrwxr-x 1 me me 10000000 2021-10-10 16:56 original_video.mp4*
-rwxrwxr-x 1 me me 10060896 2022-01-02 16:27 speed_up_output.mkv*
I.e., the file size is even bigger.
Is it possible to speed up playback and reduce of the video's size to somewhat same degree?
|
Most of the commands mentioned in that link change the playback speed. In order to reduce the number of frames, you do not necessarily need to change playback speed.
The minterpolate filter can reduce the number of frames, but it is a rather lossy process.
You could drop every other frame, but most people notice frame-rates below 24 fps.
Reducing the number of frames will reduce the amount of data. For uncompressed videos, you can expect a linear correlation.
This article includes some examples. Please note the graphs are crap as the x-tics are not evenly distributed.
In most end-user scenarios, compressed videos are used. H264 is a wide-spread compressor. It uses differential aka. predicted frames. Dropping frames will interfere with the optical flow detection, making the video harder to compress (provided you want to maintain the same per-frame quality). For this reason, reducing the frame-rate will yield a less-than-linear reduction of file-size. Related: https://superuser.com/questions/283515/video-encoding-how-much-does-the-video-file-size-increase-with-fps
I just tried it using ffmpeg's decimate filter:
ffmpeg -i raw_footage.ts -an -c:v libx264 -crf 21 30fps.mkv
ffmpeg -i 30fps.mkv -filter:v decimate=cycle=2 -c:v libx264 -crf 21 -t 30 15fps.mkv
File-sizes:
30fps.mkv 9,4M
15fps.mkv 8,2M
With a reduced frame-rate, the video is awfully jumpy and hard to look at. Totally butchered, in my opinion. Yet the file-size has only been reduced by 12 %. Not a good deal.
For most use-cases, it is way easier to keep the number of frames and reduce the image quality per-frame.
ffmpeg -i original_video.mp4 -c:v libx264 -crf 31 -c:a aac -b:a 64k -movflags +faststart output.mp4
crf is a quality setting. A higher number means "compress more".
Depending on what you are doing, switching to a higher profile can also help. Reducing the geometric resolution also helps. You may use a better compressor like libx265, if available.
| Speed up video by ffmpeg did not reduce file size |
1,619,126,357,000 |
I have a directory with some .flac files:
[test]$ ls
'test file (with $ign & parentheses).flac' 'test file with spaces.flac'
I want to run an ffmpeg test command on those files, i used find with -exec argument to achieve this:
find ./ -type f -iregex '.*\.flac' -exec sh -c 'ffmtest=$(ffmpeg -v error -i "{}" -f null - 2>&1);if [ -n "$ffmtest" ];then echo -e "{}\n" $ffmtest;fi ' \;
Little explanation for my code:
The find command will find the .flac files and pass the names to the ffmpeg command for testing.
The ffmpeg command tests the file and return an error string to stdout(because of the redirection at the end) or nothing if no error is found, the if statement following the ffmpeg command is used so that if ffmtest variable contains an error then print the name of the file with the error followed by the error string(if the file contains no error then nothing will be printed).
My code works as expected but it fails if the filename contains a $ sign followed by a letter so for the test files mentioned above the output i get is this
[test]$ find ./ -type f -iregex '.*\.flac' -exec sh -c 'ffmtest=$(ffmpeg -v error -i "{}" -f null - 2>&1);if [ -n "$ffmtest" ];then echo -e "{}\n" $ffmtest;fi ' \;
./test file (with & parentheses).flac
./test file (with & parentheses).flac: No such file or directory
you can see that the test file with no $ sign was tested properly and ffmpeg didn't output any errors but it failed to even open the file with the $ sign in the name, you can see from the output of ffmpeg and echo that the filename was interpreted and the $ sign followed by the letters were treated as a variable.
So how can I tell find to escape such characters ?
|
The {} is replaced literally by the filename, so put it somewhere that it doesn't get parsed specially. Since you're already using sh -c, the argument position seems ideal:
find ./ -type f -iregex '.*\.flac' -exec sh -c 'ffmtest=$(ffmpeg -v error -i "$1" -f null - 2>&1);if [ -n "$ffmtest" ];then echo -e "$1\n" $ffmtest;fi' -- {} \;
| use find -exec with a filename containing a dollar sign ($) [duplicate] |
1,619,126,357,000 |
I noticed if I extract frames with this command:
ffmpeg -i sample_nosound.mp4 $filename%03d.jpg
It will extract depends on fps by default. ffmpeg -i sample_nosound.mp4 shows this video has 6 fps, so it extracted 1630 jpg frame files, which 1630/6 = 271.6 seconds equivalent to the 4:32 total video duration.
But 1630 jpg frames total size is 13 MB:
$ du -h extracted_jpg_folder
13M extracted_jpg_folder
, while the file size of the mp4 is 1.8 MB, far lower than the total frames size:
$ ls -la sample_nosound.mp4
-rw-rw-r-- 1 xiaobai xiaobai 1814889 Feb 13 15:42 'sample_nosound.mp4'
That means ffmpeg extract frames by referring fps info with duplicated frames.
Therefore my question is, how to make ffmpeg extract frames by "stored frames" without rely on fps ?
I expect I can get total frames size which almost equivalent with the mp4 files size.
I don't expect exact match file size, since mp4 can contains some metadata.
Output of ffprobe -i sample_nosound.mp4:
ffprobe version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2007-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
WARNING: library configuration mismatch
avcodec configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample_nosound.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:04:32.00, start: 0.000000, bitrate: 53 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt709/bt709), 640x330 [SAR 1:1 DAR 64:33], 53 kb/s, 6 fps, 6 tbr, 12288 tbn, 12 tbc (default)
Metadata:
handler_name : VideoHandler
|
As far as I understand the question, you want to extract the frames from the video. Each frame should be stored a separate file. The sum of all file's sizes is expected to match the video's file size. This is only true for some specific videos. I'll try to explain things broadly.
TL;DR
Extracting frames from h264 encoded video with the same visual quality and file-size is not possible.
Video container formats are confusing
The video file in this case is an MP4 file. MP4 is a container for video data. The type of the container however does not really say anything about the actual content. In fact, many different kinds of video formats can reside inside a MP4 file – just like a zip archive (or a PDF file).
There are different kinds of video
A video is a sequence of images. There are many ways to store these images into a video stream (encode) and how to read them afterwards (decode). The algorithms are typically referred to as codecs.
Keep in mind that not all codecs do compression. In this example, h264 is the codec. By default, the h264 encoder calculates the difference from one frame to the next one. In case of a small difference, the encoder stores the difference only. The actual frame is discarded. Only the first¹ frame is stored as a complete image. This saves much space and is one of the compression strategies. The h264 decoder will apply the stored difference to the previous frame, recreating the original.
As you see, the frames in your video are depending on each other. If you want single files, you want them to be independent. This means you always need to store the complete information for each single frame. This means, you cannot simply take the existing data and copy them to files, but you must re-encode the video. Along the way, the sum of filesizes must increase.
You can read of the various picture types in video compression, specifically the "difference-based" inter-frames or an overview of video compression in gerneral.
h264 is not JPEG
Even if we are talking of individual images.
JPEG uses a compression method known as DCT.
H.264 uses a similar, but improved version. This means JPEG cannot possibly compress as efficient as h264. By the way, you can put a h264 compressed image into a file using HEIF (This essentially behaves like a one-frame video).
¹This is not entirely true, but I want to keep it simple for now. It is actually more like "the first frame of a scene". If you want to know the details:
The encoder notices the start of individual scenes (in cinematography, this is usually called a "cut"). The difference from one frame to another is very high and therefore not good to compress. The encoder decides not to use a "difference-based" inter-frame. Instead, it uses the complete picture (this is called an "intra-frame", also known as "key-frame").
There also is a technical reason: Only to intra-frames you may jump quicky when seeking through the video. Consequently, intra-frames are also put into the stream every now and then (regardless of the actual video content). Commonly, a video has one intra-frame per second.
Now we learned much about video compression. This video demonstrates some of the things:
Due to file corruption, this video lost an intra-frame. The decoder more or less successfully manages to play it back. The lost frame probably showed the woman looking to the side. Now she turns her head back, the decoder only has the data from inter-frames which include some movement information. It looks like the woman ended up with her face on the side of her head. Meanwhile, a person walks through the background. This person was not present in the lost intra-frame and therefore looks pretty okay.
| How to extract the “stored frames” without rely on fps? |
1,619,126,357,000 |
I have a command ffmpeg -loglevel panic -i source-video/test222.mp4 -acodec copy -f segment -segment_time 10 -vcodec copy -reset_timestamps 1 -map 0 ./tmp/%d.ts which break up a video into 10 second segments. This works on my Mac running ffmpeg 3.0.2 but not on my ec2. I have posted before and received no responses. I am trying to take steps to solve this problem and define the problem. I have now used this shell script which gets me version n3.0.5-6-g76961f4. It seems that this version is not able to run the command in question as well. I understand that the shell script is compiling software that it is fetching from the internet. How can I modify this to fetch version 3.0.2.
|
Ideally, you'd want to install packages into your Linux system from a package repository. That is the easiest way to install (its very similar to the "Homebrew" system used on Mac, where brew is essentially a "source package manager"), the fastest and allows you to get additional updates in the future with the rest of your system in a single step.
Most common package managers used on Linux are binary package managers and Amazon Linux, like RedHat, CentOS and Fedora use a package manager called "YUM" (in contrast with "Homebrew" discussed above, which is called a "source package manager" because its packages are source code that is downloaded and installed. There are some source package managers on Linux, but its a less common paradigm especially on the server side where you want consistency and fast setup).
As I've mentioned, your operating system already comes with a package manager and is already configured with some repositories - namely the operating system's own repositories. It is common to add other software repositories to allow installing software not offered by the operating system manufacturer in their repositories, like FFMPEG.
For example on Amazon Linux and similar "Enterprise Linux" operating systems its common to add the "EPEL" repositories. Unfortunately those repositories also do not include FFMPEG.
I suggest using the NegativeO17 multimedia repository that includes an up to date FFMPEG as well as a few other goodies. Easy to follow instructions to set up the repository you can find here (Please note that you use the dnf command instead of yum which I mentioned - don't worry about it - DNF is just the new version of YUM).
| ffmpeg command not working on ec2 [closed] |
1,619,126,357,000 |
I saw an answer here but when I tried it with dnf it says packages does not exist. I'm having the sample problem when I try to run videos in my built-in fedora 24 video player (I'm new to linux btw)
Any suggestions to solve this ?
|
Please install the below required packages using yum to resolve your isssue.
Enable the rpmfusion repository.
yum localinstall http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-24.noarch.rpm
yum localinstall http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-24.noarch.rpm
yum -y install gstreamer-plugins-bad gstreamer-plugins-bad-free-extras gstreamer-plugins-bad-nonfree gstreamer-plugins-ugly gstreamer-ffmpeg
yum -y install gstreamer1-libav gstreamer1-plugins-bad-free-extras gstreamer1-plugins-bad-freeworld gstreamer1-plugins-base-tools gstreamer1-plugins-good-extras gstreamer1-plugins-ugly gstreamer1-plugins-bad-free gstreamer1-plugins-good gstreamer1-plugins-base gstreamer1
ffmpeg
yum -y install ffmpeg
Mencoder
yum -y install mencoder
ffmpeg2 theora
yum -y install ffmpeg2theora
Mplayer
yum -y install mplayer
Play dvd
yum -y install libdvdread libdvdnav lsdvd libdvdcss
| H264 Mpeg-4 missing in fedora 24 |
1,619,126,357,000 |
I'm trying to stream my Gnome Desktop I installed on my OpenVZ VPS Server, and I'm not trying to run this from SSH, but the terminal inside the GNOME desktop,
I know it probably doesn't have a sound card, but it's not like i'm trying to play the sound, I just want to route it to the stream.
Inside my PulseAudio Volume Control
Here is how it looks like when I attempt to stream it.
More stuff I tried more errors happened here
Here is when I run the pacmd list-source-outputs
[removed@removed ~]$ pacmd list-source-outputs
Welcome to PulseAudio! Use "help" for usage information.
>>> 2 source outputs(s) available.
index: 0
driver: <protocol-native.c>
flags: DONT_MOVE
state: RUNNING
source: 0 <auto_null.monitor>
current latency: 3.08 ms
requested latency: 20.00 ms
sample spec: float32le 1ch 25Hz
channel map: mono
Mono
resample method: peaks
owner module: 6
client: 4 <PulseAudio Volume Control>
properties:
media.name = "Peak detect"
application.name = "PulseAudio Volume Control"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "16"
application.id = "org.PulseAudio.pavucontrol"
application.icon_name = "audio-card"
application.version = "0.9.10"
application.process.id = "997"
application.process.user = "removed_for_stackexchange(wasn't root)"
application.process.host = "removed_for_stackexchange"
application.process.binary = "pavucontrol"
window.x11.display = ":1.0"
application.language = "en_US.UTF-8"
application.process.machine_id = "27be3273f5d5332051ccdc3100000002"
application.process.session_id = "27be3273f5d5332051ccdc3100000002-1394085585.776225-694791372"
module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
index: 1
driver: <protocol-native.c>
flags: DONT_MOVE
state: RUNNING
source: 0 <auto_null.monitor>
current latency: 3.11 ms
requested latency: 20.00 ms
sample spec: float32le 1ch 25Hz
channel map: mono
Mono
resample method: peaks
owner module: 6
client: 4 <PulseAudio Volume Control>
direct on input: 2
properties:
media.name = "Peak detect"
application.name = "PulseAudio Volume Control"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "16"
application.id = "org.PulseAudio.pavucontrol"
application.icon_name = "audio-card"
application.version = "0.9.10"
application.process.id = "997"
application.process.user = "removed_for_stackexchange(wasn't root)"
application.process.host = "removed_for_stackexchange"
application.process.binary = "pavucontrol"
window.x11.display = ":1.0"
application.language = "en_US.UTF-8"
application.process.machine_id = "27be3273f5d5332051ccdc3100000002"
application.process.session_id = "27be3273f5d5332051ccdc3100000002-1394085585.776225-694791372"
module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
More information about sink i'm using
[removed@removed ~]$ pacmd list-sinks
Welcome to PulseAudio! Use "help" for usage information.
>>> 1 sink(s) available.
* index: 0
name: <auto_null>
driver: <module-null-sink.c>
flags: DECIBEL_VOLUME LATENCY FLAT_VOLUME DYNAMIC_LATENCY
state: RUNNING
suspend cause:
priority: 1000
volume: 0: 100% 1: 100%
0: 0.00 dB 1: 0.00 dB
balance 0.00
base volume: 100%
0.00 dB
volume steps: 65537
muted: no
current latency: 3.49 ms
max request: 3 KiB
max rewind: 3 KiB
monitor source: 0
sample spec: s16le 2ch 44100Hz
channel map: front-left,front-right
Stereo
used by: 1
linked by: 3
configured latency: 20.00 ms; range is 0.50 .. 10000.00 ms
module: 9
properties:
device.description = "Dummy Output"
device.class = "abstract"
device.icon_name = "audio-card"
|
(hopefully) IMPROVED CODE AT BOTTOM
Reading the script provided in your own answer, I've reached the following conclusions about your solution. Please correct me on any/all mistakes I might have made.
You append an xwininfo $GAME_WINDOW-specific dataset to a tmpfile dump after specifying $GAME_WINDOW's geometry via wmctl. Before initiating the dump you effectively truncate your tmpfile to 0-bytes with rm -f which presumably occurs only once per session either because the stream is session-specific or to avoid the tmpfile growing too large, though, again, I'm presuming both. I base the above conclusions on these three lines:
> rm -f twitch_tmp 2> /dev/null
> wmctrl -r "$GAME_WINDOW" -e 0, 411,51,160,144
> xwininfo -name "$GAME_WINDOW" >> twitch_tmp
While I'm not intimately familiar with either wmctl or xwininfo I do know that they're common xorg utilities for automating various X window behaviors. I'm assuming you're streaming that dataset just to keep up with any changes as they might occur so ffmpeg can do the right thing with its transcode rather than actually pumping the actual graphic/sound source data through the following two environment variables as I doubt very seriously the latter behavior would work for any more than a few seconds if at all:
> TOPXY=$(cat twitch_tmp | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/\+/,/' )
> INRES=$(cat twitch_tmp | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
Here you:
Open two $(command substitution) subshells, one each for $TOPXY and $INRES value assignments.
For $TOPXY you:
Concatenate your tmpfile with stdin and anonymously |pipe the results to grep's stdin which then ...
oEe Omits any line and any portion of any line not thereby omitted which does not contain the string:
"Corners:" followed by ...
at + least one \s whitespace character, then ...
a \+ literal plus sign, then ...
at + least one [0-9] digit ...
another \+ literal plus ...
and, finally, at least + one more [0-9] digit ...
The results are anonymously |piped to another instance of grep which subsequently -oEe omits everything before your first captured [0-9] digit then anonymously |pipe its results to ...
sed which transforms all literal \+ pluses it receives to , commas and dumps to its stdout which is ...
finally captured and stored in $TOPXY via the $(command substituted) subshell variable assignment.
The process for $INRES appears much the same, if a little less complex.
Most noteworthy to me is that the entire tmpfile is concatenated at least twice for every invocation, which is not to mention all of the |pipes. Probably there are a lot of ways to do this, but I can't imagine this would be among the better of them.
After this you invoke ffmpeg referencing the two variables above and various other options including other environment variables you've also specified:
ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i $DISPLAY+$TOPXY \
-f pulse -i default \
-vcodec libx264 -preset $PRESET -crf 30 -x264opts keyint=50:min-keyint=20 -s $INRES \
-acodec libmp3lame -ab $AUDIO_BITRATE -ar $AUDIO_RATE_HZ \
-threads 0 -pix_fmt yuv420p \
-f flv "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY"
PROBABLY MORE DIRECT
What follows involves no tmpfiles, a single |pipe, calls only a single invocation of sed and a single subshell command substitution for parsing your geometry settings, and is contained in a single function. All of the environment variables are defined in here-documents streamed to its stdin and are therefore effectively locally scoped. They are also defined via parameter-substitution and are therefore configurable. For instance to alter the value of $FPS for a single invocation you need only do:
% FPS=28 desk_stream
For what it's worth, though, I still think vlc would make a much better option.
desk_stream() { sed -rn '\
/.*((Corners:|geometry)\s*\+*([x|+|0-9]*\+)).*/{\
s//\3/;\
/X/s/.*/\
INRES="&";/p;\
s/(.*)\+(.*)\+$/\
DISPLAY='"${DISPLAY}"'"+\1,\2,";/p;\
};$a\. 0<&3 /dev/stdin\n' | . /dev/stdin
} <<FFOPTS 3<<-\FFCMD
${FPS="15"} # target FPS
${PRESET="ultrafast"} # one of the many FFMPEG preset on (k)ubuntu found in /usr/share/ffmpeg
${THREADS="0"} #0 autostarts threads based on cpu cores.
${AUDIO_BITRATE="1k"} #Audio bitrate to 96k
${AUDIO_RATE_HZ ="44100"} #Audio rate 44100 hz
${GAME_WINDOW="MYGAMETEST"}
${STREAM_KEY=live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx}
${SERVER="live-jfk"} # NY server
$(wmctrl -r "$GAME_WINDOW" -e 0, 411,51,160,144 &&\
xwininfo -name "$GAME_WINDOW")
FFOPTS
ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i $DISPLAY \
-f pulse -i default \
-vcodec libx264 -preset $PRESET -crf 30 -x264opts keyint=50:min-keyint=20 -s $INRES \
-acodec libmp3lame -ab $AUDIO_BITRATE -ar $AUDIO_RATE_HZ \
-threads 0 -pix_fmt yuv420p \
-f flv "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY"
FFCMD
| Alsa Pulse Audio cannot open audio device pulse (No such file or directory) pulse: Input/output error |
1,619,126,357,000 |
I’m on debian.
I am calling a ffmpeg process to generate a mp3. this gets called from a php script using shell_exec. This works fine 99% of the time.
Sometimes, the ffmpeg process doesn’t exit and I’m left with ffmpeg running for hours. I”m slowly tweaking the params and its happening less, but still crops up on occasion.
When I look at the top processes I sometimes find it sitting there eating the cpu and disk, the process hasn’t terminated.
993 www-data 20 0 252012 38904 27384 R 99.7 1.9 390:09.84 ffmpeg
I normally look for the process (and confirm it’s the right one by ensuring the params it executed with match my php script:
ps -eo args | grep ffmpeg
then get its process id and kill it, and go hunt down the file it was working on and trash that too
-rw-r--r-- 1 www-data www-data 14G Feb 9 21:20 cfcd208495d565ef66e7dff9f98764da.mp3 - uh oh
I’m not sure what words I should be googling for.
I’m looking for ideas for a supervisory process or script that I can run through a supervisord/cron job that can output all processes that run for longer than X seconds, and pipe their process details into a script that can match the process with arguments matching a pattern (using some kind of nasty regex I imagine), kill the process and go trash any files matching on their arguments.
|
You can use timeout that runs a command with a time limit.
For example:
timeout 2 yes
Will echo 'y' for two seconds (it would go on forever otherwise).
| How to detect if a process runs longer than X seconds, then do something with it? |
1,619,126,357,000 |
Can someone please explain to me what is happening here? This is what I have reduced my situation down to:
# make 20 test gifs out of the same source file.
for i in {1..20}; do cp -p ../some-random-source-file.gif "${i}.gif"; done
# grab, then process them.
while read f; do echo "→ $f"; ffmpeg -i "$f" -y -loglevel quiet "same.mp4"; done < <(find . -maxdepth 1 -type f -iname "*.gif" -printf "%f\n")
→ 11.gif
→ .gif
→ 9.gif
→ .gif
→ 14.gif
→ 9.gif
→ 0.gif
→ 13.gif
→ 7.gif
→ 5.gif
→ 2.gif
→ .gif
→ 3.gif
→ 0.gif
→ 16.gif
→ .gif
→ 8.gif
→ 8.gif
→ .gif
→ 4.gif
I am trying to process all gifs in a directory with mixed files (gifs and non-gifs). But for some reason, as soon as I add the ffmpeg step, the content of the $f variable is sometimes cut off at the beginning.
Extra info:
I'm using process substition because I am also logging the files that didn't work. if ! ffmpeg …; then FAILED+=("$f"); fi
I'm also generating the new filename via string substitution ${f%.gif}.mp4, but … turns out: that part isn't even relevant for the problem to occur.
bash version 5.1.16
I understand that the process substitution can cause timing issues – but then why does it randomly cut off the variable at the beginning and not at the end? And how is anyone to use this construct if it is so unreliable? How else am I to do this?
|
ffmpeg reads stdin by default so it is consuming some characters. You should add the flag -nostdin:
ffmpeg -nostdin -i "$f" -y -loglevel quiet
| ffmpeg inside while loop with find unintentionally alters iteration variable |
1,619,126,357,000 |
The official tutorial https://trac.ffmpeg.org/wiki/StreamingGuide uses the -pix_fmt yuv420p option.
I used it too, copied it from the tutorial, and streaming from FFmpeg to Youtube works for me. However, it is not clear what it is for, and especially if it is a necessary option with Youtube, or if there is a better one.
The Youtube documentation on the subject doesn't seem to cover this, or maybe it does but I haven't understood where: https://support.google.com/youtube/answer/1722171?hl=en.
Does anyone know of any accurate documentation on this?
|
YUV420 is a color space that uses chroma subsampling to reduce the amount of data needed to represent an image. Chroma subsampling is a method of encoding images by implementing less resolution for chroma (color) information than for luma (brightness) information. This takes advantage of the human visual system’s lower sensitivity to color differences than to brightness differences. As a result, YUV420 can be considered a space-saving format because it requires less data to represent an image compared to formats that do not use chroma subsampling.
Regarding my question about using -pix_fmt yuv420p when streaming, I found an answer that is both general and specific to YouTube.
The FFmpeg streaming guide linked in my question (https://trac.ffmpeg.org/wiki/StreamingGuide) uses the H.264 codec via the -vcodec libx264 option. This is also the codec suggested in YouTube's official recommendations (https://support.google.com/youtube/answer/1722171?hl=en#zippy=%2Cvideo-codec-h).
The specific answer for YouTube can be found in that documentation, in the sentence:
"Chroma subsampling: 4:2:0".
This corresponds exactly to the -pix_fmt yuv420p option.
The general answer can be found instead in the FFmpeg documentation for H.264: https://trac.ffmpeg.org/wiki/Encode/H.264. At the bottom of the page it says:
You may need to use -vf format=yuv420p (or the alias -pix_fmt yuv420p) for your output to work in QuickTime and most other players.
These players only support the YUV planar color space with 4:2:0
chroma subsampling for H.264 video. Otherwise, depending on your
source, ffmpeg may output to a pixel format that may be incompatible
with these players.
| ffmpeg "-pix_fmt yuv420p" option when streaming on Youtube |
1,619,126,357,000 |
Ive been researching all of today and yesterday trying to find a solution, none have worked for me so far.
For example: https://stackoverflow.com/questions/5784661/how-do-you-convert-an-entire-directory-with-ffmpeg
I want to be able to loop over all files in a folder (such as /Music/), find any files in any directory or subdirectory that ends with .flac, then convert those flac files to alac files using this command:
ffmpeg -i "$i" -c copy -acodec alac "${i%.*}.m4a"
the $i variable is the "name" of the file from the for loop. ${i%.*} should just return the name, not the .flac portion.
Anyways, after that command has been run, I want all of those saved .m4a alac files to then be sent to a "new library"... IE: Ill have two /Music/ libraries.
One has all the flac files
One has all the alac (m4a) files
Is this possible?
This is the commmand I have so far, definitely doesnt work, and even if it did, it doesnt create a new library like I want: for i in *.flac; do ffmpeg -i "$i" -c copy -acodec alac "${i%.*}.m4a"; done
Currently that command just throws the error *.flac: No such file or directory, which I assume is because its not searching subdirectories?...
|
#!/bin/bash
shopt -s globstar
src_dir="Music"
dest_dir="Music_new"
for orig_path in "${src_dir}"/**/*.flac; do
#Change first directory in the path
new_path=${orig_path/$src_dir/$dest_dir}
#Remove filename from new path. Only directories are left.
#They are needed for mkdir
dir_hier=${new_path%/*}
#Remove extension .flac from path, thus we have original path with first directory
#changed and file extension removed.
#Original path: "Music/one/two/song.flac"
#New path: "Music_new/one/two/song"
new_path=${new_path%.*}
echo mkdir -p "$dir_hier"
#New path with extension: "Music_new/one/two/song.m4a"
#ffmpeg should create new file by this path, necessary directories
#already created by mkdir
echo ffmpeg -i "$orig_path" -c copy -acodec alac "${new_path}.m4a"
done
echo before mkdir and ffmpeg should be removed after checking.
| How can I loop over all directories and subdirectories and find files with a specific extension, then run FFMPEG on them, then copy them to a new lib |
1,619,126,357,000 |
I'm trying to convert a bunch of video .ts files to .mp4, but the way I think I have to go, is that while finding the files with find pipe the results into a while loop, execute ffmpeg on each file and then remove the old .ts file that was converted.
This is what I get with find:
$ find ./ -iname "*.ts"
./Parent-Dir/video1.ts
./Parent-Dir/video2.ts
./Parent-Dir/video3.ts
./Parent-Dir/video4.ts
..
..
.. about a 100 more videos ..
Can I do this with find and a while loop, something like this?
find ./ -iname "*.ts" | while IFS= read video
do
ffmpeg -i "${video}" -c:v libx264 -c:a aac "${video}".mp4
rm -f ${video}.ts
done
|
After all, this was what worked perfectly for me:
find ./ -iname "*.ts" \
| while IFS= read -r video; do
ffmpeg -nostdin -i "${video}" -c:v libx264 -c:a aac "${video%.*}".mp4
rm -f "${video}"
done
From video.ts it will convert it to video.mp4. Exactly what I was looking for!
Inspired from this answer.
Thank you for the help @Romeo Ninov!
| Convert .ts videos to .mp4 with find piped into while and ffmpeg? |
1,619,126,357,000 |
I'm trying to record a specific window, so I tried this answer.
But it gave me this error: Unknown input format: 'gdigrab'
I'm using ffmpeg version n4.4.
|
gdigrab is specific to Windows. For linux, x11grab is the relevant device.
Run ffmpeg -h demuxer=x11grab to see its options.
| ffmpeg Unknown input format: 'gdigrab' |
1,619,126,357,000 |
Issue:
I have an FFmpeg command that I've been running for months now to stream video into the /dev/shm directory. It had been working fine until relatively recently (e.g. within a week), now it throws a permission issue.
The command:
ffmpeg -threads 2 -video_size 640x480 -i /dev/video2 -c:v libx264 -f dash -streaming 1 /dev/shm/manifest.mpd
This is not the exact command (paired down for brevity), however the outcome is the same:
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error: GLXBadContext
Request Major code 151 (GLX)
Request Minor code 6 ()
Error Serial #57
Current Serial #56
ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-cuda --enable-cuda-sdk --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, video4linux2,v4l2, from '/dev/video2':
Duration: N/A, start: 1900.558740, bitrate: 147456 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x55b15d8912c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55b15d8912c0] profile High 4:2:2, level 3.0, 4:2:2 8-bit
[libx264 @ 0x55b15d8912c0] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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=-2 threads=12 lookahead_threads=2 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
[dash @ 0x55b15d88f600] No bit rate set for stream 0
[dash @ 0x55b15d88f600] Opening '/dev/shm/init-stream0.m4s' for writing
Could not write header for output file #0 (incorrect codec parameters ?): Permission denied
Error initializing output stream 0:0 --
Conversion failed!
(tl;dr: Could not write header for output file #0 (incorrect codec parameters ?): Permission denied)
For contrast, this version of the command (writing to the home directory) works fine (/tmp/ also works):
ffmpeg -threads 2 -video_size 640x480 -i /dev/video2 -c:v libx264 -f dash -streaming 1 ~/manifest.mpd
As mentioned above, the strange thing is that I have not (knowingly) changed permissions on anything or altered the application; it seemingly just stopped working (although, not ruling out that I caused it). The last time I remember it working was probably a week ago (~March 20th, 2021).
What I tried:
Running ffmpeg as sudo (sudo ffmpeg...)
Result: sudo: ffmpeg: command not found. This hasn't been necessary in the past, and it had the same output as before.
sudo sysctl fs.protected_regular=0
Result: No change.
Ran the ffmpeg ... command as su
Result: No change
chmod +777 /dev/shm
Result: No change (ls -tls reveals that the directory is indeed rwxrwxrwt)
chown'd both root:root and my username on /dev/shm
Result: No change.
touch /dev/shm/test.txt and sudo touch /dev/shm/test.txt
Result: The file is created without issue.
I've exhausted everything I could think of relating to permissions to get it to work.
The Question What do I need to do to get FFmpeg write files to /dev/shm? Ideally, figuring out why this happened in the first place.
If anyone has any ideas for commands I should run to help diagnose this issue, feel free to add a comment.
System Info:
Kernel: 4.19.0-14-amd64
Distro: Debian
FFmpeg: version n4.3.1 (Was installed using Snapd, if it matters.)
== Solution ==
jsbilling's solution of using snap.<snapname>.* unfortunately did not work, however in the linked forum thread there was a post which basically got around the issue of writing to /dev/shm by mounting a directory in home ~/stmp and writing the ffmpeg output there:
$ mkdir ~/stmp/
$ sudo mount --bind /dev/shm/streaming_front/ ~/stmp/
...
$ ffmpeg -threads 2 -video_size 640x480 -i /dev/video2 -c:v libx264 -f dash -streaming 1 ./stmp/manifest.mpd
Not an ideal solution, but a working one.
|
If you are using snaps, this forum post indicates there are specific patterns that are allowed for files in /dev/shm:
/dev/shm/snap.<snapname>.*
Another forum member suggested this hack, although it is basically a security bypass:
$ mkdir /dev/shm/shared
$ mkdir ~/shmdir
$ sudo mount --bind /dev/shm/shared ~/shmdir
$ touch ~/shmdir/foo
$ ls /dev/shm/shared/
foo
| FFmpeg cannot write file to /dev/shm: Permission Denied |
1,619,126,357,000 |
I'm used to the reverb effect in Audacity, and was wondering if the same or at least, similar effect would be done using ffmpeg alone (or at least, commandline tools only).
Any ways to do this with commandline tools (like ffmpeg) only? (working example is appreciated)
|
This is one working example to use a convolution reverb with ffmpeg:
ffmpeg -i input.wav -i "CUSTOM_museum hall.wav" -lavfi afir temp.mp3
I used one of the Lexicon impulse responses from this page.
| How to apply reverb effect to audio files using commandline tools only? |
1,619,126,357,000 |
I'm attempting to record video (a screen capture) on a Debian 10.4 laptop.
I'm using a command that used to work fine on Mint 19.3, on the same hardware. I'm guessing the version of ffmpeg is newer on Debian 10.4.
The command is:
ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 10 -s 1366x768 -i :0.0 -qmin 1 -qmax 1 -vcodec flv -pix_fmt yuv420p -preset ultrafast -crf 0 -threads 0 -y screen-movie.temp.flv
And the output is:
ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'pulse':
Duration: N/A, start: 1597616399.164690, bitrate: 1536 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
[x11grab @ 0x55f7452a4380] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #1, x11grab, from ':0.0':
Duration: N/A, start: 1597616399.267230, bitrate: N/A
Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1366x768, 10 fps, 1000k tbr, 1000k tbn, 1000k tbc
Codec AVOption preset (Configuration preset) specified for output file #0 (screen-movie.temp.flv) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Codec AVOption crf (Select the quality for constant quality mode) specified for output file #0 (screen-movie.temp.flv) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo (native) -> flv1 (flv))
Stream #0:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[swscaler @ 0x55f7452beec0] Warning: data is not aligned! This can lead to a speed loss
[alsa @ 0x55f74527da40] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Output #0, flv, to 'screen-movie.temp.flv':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: flv1 (flv) ([2][0][0][0] / 0x0002), yuv420p(progressive), 1366x768, q=1-1, 200 kb/s, 10 fps, 1k tbn, 10 tbc
Metadata:
encoder : Lavc58.35.100 flv
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 48000 Hz, stereo, s16p
Metadata:
encoder : Lavc58.35.100 libmp3lame
frame= 69 fps= 10 q=31.0 Lsize= 2867kB time=00:00:06.88 bitrate=3409.7kbits/s speed=1.01x
video:2753kB audio:108kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.205926%
There it hangs. strace of that ffmpeg process shows:
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=3, revents=POLLIN}])
[pid 26482] getpid() = 26482
[pid 26482] poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}], 1, -1^C) = 1 ([{fd=3, revents=POLLIN}])
The version of ffmpeg I'm using on Debian is: 4.1.6-1~deb10u1 .
I tried removing the crf and preset, and I've also tried adding a -thread_queue_size of 512. Further, I tried -r 16 and -r 32. Some of these helped with eliminating warnings, but none of them eliminated the hang.
Does anyone know how to get this previously-working command working again?
Thanks!
|
I'm not sure this part is correct: -f alsa -ac 2 -i pulse
what about just -f pulse -ac 2 -i default instead?
| ffmpeg hangs with command that used to work |
1,619,126,357,000 |
The below command well works for trimming the output audio
ffmpeg -i input.mp3 -af silenceremove=1:0:-50dB output.mp3
However, I am concating several mp3 files,
ffmpeg -i 1.mp3 -i 2.mp3 -i 3.mp3 -filter_complex 'concat=n=3:v=0:a=1' out.mp3
and I need to trim the input audio before concat.
Is it possible to trim input audio before concating in ffmpeg?
|
ffmpeg \
-i 1.mp3 \
-i 2.mp3 \
-i 3.mp3 \
-filter_complex '[1]silenceremove=1:0:-50dB[a1];\
[2]silenceremove=1:0:-50dB[a2];\
[3]silenceremove=1:0:-50dB[a3];\
[a1][0][a2][0][a3]concat=n=5:v=0:a=1' out.mp3
Source: How to trim input audio in FFMPEG?
| How to trim input audio by FFMPEG? |
1,619,126,357,000 |
FFmpeg says in the 4.1 docs,
The Fraunhofer FDK AAC and OpenSSL libraries are under licenses which are incompatible with the GPLv2 and v3. To the best of our knowledge, they are compatible with the LGPL.
But it seems the OpenSSL license is Apache v2, and at least according to Apache,,
The Free Software Foundation considers the Apache License, Version 2.0 to be a free software license, compatible with version 3 of the GPL. The Software Freedom Law Center provides practical advice for developers about including permissively licensed source.
Why does FFmpeg claim that Apache 2 is incompatible with GPL v3?
|
The Github file you linked to clearly shows the license was modified, and that pretty recently:
@levitte Change license to the Apache License v2.0 1513331 on
Dec 6, 2018
The license before that seems to be some custom stuff, known as the "OpenSSL license", which may not have been compatible with GPL (2 or 3).
And the docs you link to has the footnote:
Generated on Tue Nov 6 2018 18:11:55 for FFmpeg by doxygen 1.8.6
| FFmpeg claims OpenSSL is not compatible with GPL v3? |
1,619,126,357,000 |
What I've tried:
gcc -L/path/to/lib/ -llib ...
gcc -l/path/to/lib/lib.so.x.x.x ...
Update ldconfig
Added path to LD_LIBRARY_PATH
file shows correct build version and link to the correct file
No matter what, I still get /usr/bin/ld: cannot find -lavfilter
Any ideas?
|
ld looks for shared libraries or linker scripts named libsomething.so, or static libraries named libsomething.a, where something matches the -lsomething parameter given to ld. Libraries named libsomething.so.x.y.z, where x.y.z is the library’s version, are used at runtime, not for building, and ld won’t use them.
You therefore need to install the development packages for libraries you want to link to, such as libavfilter-dev in your case (assuming Debian or a derivative).
| LD cannot find lib even with specified path |
1,619,126,357,000 |
I need to subtract two time codes from each other, I have multiple in an array and the output looks like this:
**Input:**
echo ${arr3[0]}
echo ${arr3[1]}
**Output:**
00:00:22.180 --> 00:00:25.600
00:00:24.070 --> 00:00:27.790
In this example the following equation needs to take place 00:00:25.600 - 00:00:22.180 = output into arrayand 00:00:27.790 - 00:00:24.070 = output into the same array It needs to be in the same format so can use it in FFMPEG.
I also need the first timecode of each array entry, so:
00:00:22.180
00:00:24.070
in another array so I can use these inputs in ffmpeg as well.
EDIT:
I'll use the data as follows
time=$(The first timecode of the array)
duration=$(Timecodes subtracted)
ffmpeg -i movie.mp4 -ss $time -t $duration -async 1 cut.mp4
|
Given an array arr3 that contains sample data:
declare -a arr3=([0]="00:00:22.180 --> 00:00:25.600"
[1]="00:00:24.070 --> 00:00:27.790")
You could loop through each element in the array, strip out the start time and end time, convert them to fractional seconds, compute the duration, then covert that duration back to hh:mm:ss.sss format for the ffmpeg command.
# converts HH:MM:SS.sss to fractional seconds
codes2seconds() (
local hh=${1%%:*}
local rest=${1#*:}
local mm=${rest%%:*}
local ss=${rest#*:}
printf "%s" $(bc <<< "$hh * 60 * 60 + $mm * 60 + $ss")
)
# converts fractional seconds to HH:MM:SS.sss
seconds2codes() (
local seconds=$1
local hh=$(bc <<< "scale=0; $seconds / 3600")
local remainder=$(bc <<< "$seconds % 3600")
local mm=$(bc <<< "scale=0; $remainder / 60")
local ss=$(bc <<< "$remainder % 60")
printf "%02d:%02d:%06.3f" "$hh" "$mm" "$ss"
)
subtracttimes() (
local t1sec=$(codes2seconds "$1")
local t2sec=$(codes2seconds "$2")
printf "%s" $(bc <<< "$t2sec - $t1sec")
)
declare -a arr3=([0]="00:00:22.180 --> 00:00:25.600"
[1]="00:00:24.070 --> 00:00:27.790")
for range in "${arr3[@]}"
do
duration=$(subtracttimes "${range%% -->*}" "${range##*--> }")
printf "%s\n" "ffmpeg -i movie.mp4 -ss ${range%% -->*} -t $duration -async 1 cut.mp4"
done
The codes2seconds function expects input in HH:MM:SS.sss format; it strips out the various elements using parameter expansion then passes them to bc for the conversion into total number of seconds.
The seconds2codes function expects a fractional number of seconds and reverses the conversion, resulting in an HH:MM:SS.sss string.
The subtracttimes function converts the two parameters to fractional seconds then asks bc for their difference.
The loop at the end goes through each element of arr3; it uses the above functions to calculate the duration (again using parameter expansion to retrieve the two times) then prints out a sample ffmpeg call to match your sample output.
Results:
ffmpeg -i movie.mp4 -ss 00:00:22.180 -t 3.420 -async 1 cut.mp4
ffmpeg -i movie.mp4 -ss 00:00:24.070 -t 3.720 -async 1 cut.mp4
| Subtract two time codes |
1,619,126,357,000 |
So I have an almost working script for FFMPEG that merges an .aif and an .mp4 file with the same name into a single filename_output.mp4 but when I execute it I get a weird error saying that a file is non exsistent but it the file it is searching for has two file extensions. The script is executed in the same folder as the files are.
The script that is executed in the folder:
#!/bin/bash
cd "`dirname "$0"`"
for file in *.aif
do
filename=$(basename "$file")
# do something on "$file"
ffmpeg -i "${filename}.aif" -i "${filename}.mp4" -map 0:0 -map 1:0 -acodec libfdk_aac -b:a 192k -vcodec copy -shortest "${filename}_output.mp4"
done
The output that i'm getting from the log:
++ dirname replace_audio_aif2mp4.bash
+ cd .
+ for file in '*.aif'
++ basename audio.aif
+ filename=audio.aif
+ ffmpeg -i audio.aif.aif -i audio.aif.mp4 -map 0:0 -map 1:0 -acodec libfdk_aac -b:a 192k -vcodec copy -shortest audio.aif_output.mp4
ffmpeg version 3.1.2-1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.1.1 (Debian 6.1.1-11) 20160802
configuration: --prefix=/usr --extra-version=1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-chromaprint --enable-libopencv --enable-libx264
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
audio.aif.aif: No such file or directory
|
You have a double extension because you start off with
for file in *.aif
followed by
filename=$(basename "$file")
which will give you $filename with an .aif suffix. Then you do
ffmpeg -i "${filename}.aif" -i "${filename}.mp4"
So you end up with filenames with a .aif.aif and .aif.mp4 suffixes.
Instead, use basename like this:
filename="$( basename "$file" .aif )"
This will strip off the original .aif suffix from $file (see the manual for basename).
Notice that you need to double-quote all variable expansions to cope with filenames with spaces (it's a very good habit).
| FFMPEG Merging Script Error |
1,619,126,357,000 |
Let's say I have a 2 hour movie and I want to extract/copy audio in another file say 5 minutes between 01:25:00 and 01:30:00, is there a way to do that.
The file is in .avi format -
Format : AVI
Format/Info : Audio Video Interleave
File size : 929 MiB
Duration : 2h 44mn
Overall bit rate mode : Variable
Overall bit rate : 790 Kbps
Writing application : VirtualDubMod 1.5.4.1 (build 2178/release)
Writing library : VirtualDubMod build 2178/release
Video
ID : 0
Format : MPEG-4 Visual
Format profile : Advanced Simple@L5
Format settings, BVOP : 1
Format settings, QPel : No
Format settings, GMC : No warppoints
Format settings, Matrix : Custom
Codec ID : XVID
Codec ID/Hint : XviD
Duration : 2h 44mn
Bit rate : 662 Kbps
Width : 672 pixels
Height : 288 pixels
Display aspect ratio : 2.35:1
Frame rate : 23.976 (23976/1000) fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.143
Stream size : 778 MiB (84%)
Writing library : XviD 1.2.1 (UTC 2008-12-04)
Audio
ID : 1
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 3
Mode : Joint stereo
Mode extension : MS Stereo
Codec ID : 55
Codec ID/Hint : MP3
Duration : 2h 44mn
Bit rate mode : Variable
Bit rate : 115 Kbps
Nominal bit rate : 128 Kbps
Channel(s) : 2 channels
Sampling rate : 48.0 KHz
Compression mode : Lossy
Stream size : 136 MiB (15%)
Alignment : Aligned on interleaves
Interleave, duration : 24 ms (0.58 video frame)
Interleave, preload duration : 485 ms
Writing library : LAME3.98r
Encoding settings : -m j -V 4 -q 2 -lowpass 17 --abr 128
|
Have you tried ffmpeg? Something like
ffmpeg -vn \ # no video
-ss 01:25:00 \ # start offset
-t 300 \ # duration
-i foo.avi bar.mp3
might do the trick.
| extracting/copying audio from a specific part of a video file, possible? |
1,619,126,357,000 |
Before I go ahead and wipe my whole system and start from scratch, is there a way I can avoid what just happened on trying to install ffmpeg? I still don't actually know the correct way to install it so it includes most functions which it DOES NOT on Centos 6.4 with STATIC version.
My /etc/lb folder is a mess after the command ldconfig -v which created symlinks and they conflict all over the place. The /etc/yum.repos.d folder is also a mess and the script I followed in a linux blog makes no sense to me and started errors in first place. I'd like to avoid that altogether next time around...is there a way I can do that? In other words not play around with writing repo scripts or touching that folder..that is when all the trouble began!
Better yet is there a safe method to employ that can be reversed? Starting to think Centos is a headache in as far as ffmpeg goes. Everyone else doing basic commands with it just downloads static version.
|
There are some licensing issues with some components of ffmpeg making it unpalatable to include in certain configurations for most distros, I think -- probably you are aware of this. Also, it includes a set of libraries that have been replaced some places with the libav fork.
If you are looking for static binaries, they're here. If that has not worked for you,1 it is not hard to build and install from source, in which case you can configure it anyway you want. The source tarballs are further down that page. The wiki has a page about compiling and installing on CentOS, although it is into $HOME, which is probably not what unless you have to (because, e.g., it's not your computer). Presuming it is your computer I'll give you a alternate-parallel guide to install it system-wide, which is preferable. You must do ALL of this su root or via sudo. It's simpler than it looks, BTW; 5 simple steps:
Make sure you have the pre-reqs: yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel.
mkdir -p /usr/local/src. Then move the tarball into there and unpack it: tar -xjf ffmpeg-2.1.3.tar.bz2 if you got the bzip2 ball or tar -xzf ffmpeg-2.1.3.tar.gz if you got the gzip ball. You may need to yum install tar (and/or bzip2 or gzip) if you don't have those already. Once all that's done, move into the created directory: cd ffmpeg-2.1.3.
The potentially complicated part is configuration. You haven't said exactly what you want this for, but if it is just recoding from one common format to another, the default should be fine; I did this recently and I think it includes everything it can, but to be sure you may want to have a look at the list of available encoders and decoders:
./configure --list-encoders
./configure --list-decoders
If there's anything there you know you want, you can make sure it gets built by including --enable-encoder=[whatever] (or --enable-decoder) when you configure. Presuming you are not re-distributing this, you might as well also use --enable-nonfree,1 which is the stuff the distros definitely leave out of their builds (and, I'd guess, the static binaries). So for example:
./configure --enable-encoder=mpeg4 --enable-encoder=pcm_u8 --enable-decoder=wmv3 --enable-nonfree --enable-gpl
The last one (--enable-gpl) isn't enabled by default but pretty much everyone will want it; for more information, look at ./configure --help | less. Don't go crazy with this by listing every single encoder; I'm pretty sure they almost all get build in anyway. Choose one or two if you want and then if something doesn't work out, you can rebuild and re-install; it is easier the second time.
Before you do the configure, have a look at the various libraries listed at the top of the wiki page under "Compilation & Installation" (x264, libfdk_aac, etc.) to see if there's anything there you want. You probably don't; if you don't recognize anything, don't worry about it. If you do:
Follow the directions there but leave out the --prefix="$HOME/ffmpeg_build" and --bindir="$HOME/bin switches to the individual ./configure commands.
Run ldconfig and make sure your $PATH is correct after that, see step #5.2 To be clear: you only need to do this now if you built third party libs.
Build, check, install. If configure does not exit cleanly, leave a comment here with the output. Otherwise go ahead and make. If you have a multi-core system, speed that up with make -j N where N is a number of cores (your total - 1 is good if you want to use the system during the compile, total + 1 is ideal if you don't).
If the build finished without error, make test (if that doesn't do anything make check -- I can't remember which is used). That should take a minute or two and finish without any failures. At that point you can do a make install.
Set paths. The tools were installed into /usr/local/bin, so make sure that is at the beginning of your path, e.g.:
> echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:[...]
Notice /usr/local/bin preceeds /usr/bin and likewise with sbin. This means if some distro version is installed, your custom one will take precedence. If your $PATH is not like that, create an /etc/profile.d/local.sh with one line in it:
export PATH=/usr/local/bin:$PATH
I'm not worried about sbin since nothing from ffmpeg (or generally, anything else) ends up there. Also execute that line now in in your current terminal. Other users will have to log in again to make it effective.
Finally, you need to make sure the libraries are available to the system linker (see man ldconfig). Check:
grep /usr/local/lib /etc/ld.so.conf.d/*
If you do not get any output, create a file /etc/ld.so.conf.d/local.conf with one line:
/usr/local/lib
You can add /usr/local/lib64 on a 64-bit system. Ffmpeg doesn't install to there but some things do and you may end up doing this again with those somethings one day.
Now run ldconfig. This is crucial. Without that, the system won't be able to find the libraries the ffmpeg binary is linked to.
You can undo all this with make uninstall. As mentioned in step #3, you can also re-built/install again later if you want to change the configuration. First make clean then start from #3 (you don't have to make uninstall first). At #5 all you'll have to do is ldconfig this time.
1. See my comment about --enable-nonfree in step #3. I haven't used the static binaries, but my guess is they do not include everything.
2. So the procedure if you are also building third party libs is to make and install all of them, then proceed with step #5, then #4, then all you have to do from #5 again afterward is run ldconfig.
| Linux re install order of events to include ffmpeg |
1,619,126,357,000 |
Could anybody explain, why
ffmpeg -i input.mov -ss 00:00:10 -to 00:00:15 output1.mov
produces a 5-second video, from second 10 to second 15, whereas
ffmpeg -ss 00:00:10 -i input.mov -to 00:00:15 output2.mov
produces a 15-second video, from second 10 to second 25?
|
man ffmpeg:
As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file.
So, -ss 00:00:10 before -i seeks the input to position 10s.
So, -ss 00:00:10 before the output skips the first ten seconds of the output, up to position 10s (not duration).
Your -to affects the output in both cases, and cancels on a position, not a duration.
| FFmpeg: The option 'to' works differently depending on where we put it. Why is it so? |
1,619,126,357,000 |
I'm trying to use FFmpeg to produce a stereoscopic side-by-side video (Full 3D SBS) from a left-right pair of videos.
If the two source videos were perfectly in sync, I could use:
ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack stereo.mp4
Unfortunately, the cameras were not synchronized and I determined that I need to trim the first 30 frames or 1.0 second from the left video to align it with the right one.
Referring to the FFmpeg wiki on Seeking, I could either use fast input seeking with -ss 1 -i left.mp4, or accurate output seeking with -i left.mp4 -ss 1. I want accurate seeking, but unfortunately -i left.mp4 -ss 1 -i right.mp4 doesn't work the way I'd hope.
How can I accurately skip the first second of left.mp4 while starting from the beginning of right.mp4?
|
I ended up using the tpad filter in conjunction with hstack to delay the right side 30 frames, rather than trim the left side:
ffmpeg -i left.mp4 -i right.mp4 -filter_complex \
"[0:v]null [left]; \
[1:v]tpad=30:start_mode=add [right]; \
[left][right]hstack" \
stereo.mp4
(However without electronically synchronized shutters, I found that the frame alignment does drift over time by quite a lot.)
| Stacking two videos with a precise time offset |
1,619,126,357,000 |
I know... there are a lot of questions out there already about reducing the file size with ffmpeg.
But, here's why my question is a bit different, it addresses having difficult content. I think that there's an issue with the significant area of moving sea water in my source video.
From an h624 video off the phone at 35MB, I got a 'compressed' video of 60MB, with
ffmpeg -i water.mp4 -vcodec libx265 -crf 28 small_water.mp4
An even simpler example also produced a much larger output.
ffmpeg -i water.mp4 new_water.mp4
So my question is, what do you do when the video contains a significant amount of fast moving background artefacts? Normal methods do not seem to reduce the size, but I'm assuming, there must be something that works. I suppose it's a similar problem to one with video of F1 racing where the video pans across the spectators while following the cars.
Background; I was converting several phone videos to h625 to shrink them for posting on Whatsapp, all the others shrank as expected, except the 'water' one which doubled in size. So more out of interest for future reference, I'd like to know if there's a solution.
|
So my question is, what do you do when the video contains a significant amount of fast moving background artefacts?
Leave it be and do not reencode. You could
Reduce its resolution or/and framerate
For videos with a lot of noise you could try using a noise removal filter
For videos with a lot of motion you could use AviSynth filters to stabilize them
Normal methods do not seem to reduce the size, but I'm assuming, there must be something that works.
H.264 is not as bad as you think it is. Secondly, hardware video encoders introduce their own artefacts which are very difficult to re-encode. Normally you need the source uncompressed video to compress it efficiently.
I've dealt with a situation like yours many times.
https://forum.doom9.org and https://forum.videohelp.com are two primary forums where where people discuss such issues.
| ffmpeg re-encoding to h625 with video of Sea Water doubles file size |
1,619,126,357,000 |
So I have frame series of JPEG in a folder let's say folder cctv where inside of that folder is only series of JPEG with unix timestamp named in nanosecond.
I mean like this ( I used tail because too much to display).
.../uwc/cctv $ ls | tail
1660282994647450349.jpg
1660282994732146495.jpg
1660282994809953109.jpg
1660282994883480141.jpg
1660282994965326703.jpg
1660282995051919515.jpg
1660282995128582224.jpg
1660282995203676963.jpg
1660282995296646495.jpg
1660282995373804099.jpg
I can display MJPEG from those series with OpenCV or Flask, but idk how to convert it to mp4.
I expect I can convert those series to mp4 with specifying frame rates I want for example 60 FPS. So how do I achieve it? I suspect ffmpeg can do it, but I never use so I don't know how to use it, maybe this will be my first time to use it.
Actually MJPEG is fine and playable in VLC but it will burden layman like entering URL stream of those JPEG or maybe need opening web browser.
And ofcourse I don't need audio.
|
here is one example command with ffmpeg how to create such video:
ffmpeg -framerate 30 -pattern_type glob -i '166*.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4
This video is set to 30 FPS, H.264 codec. Feel free to change them if required.
For more info check this answer.
| Create MP4 or another playable video format from frame series of JPEG in a directory |
1,619,126,357,000 |
I'm to capturing 10 images from camera. Like so:
ffmpeg -hide_banner -loglevel error -f video4linux2 -i /dev/video0 -vframes 10 -video_size 640x480 test%3d.jpg
Since JPG is lossly, at I need to change the image format. Let's say tiff. Like so:
ffmpeg -hide_banner -loglevel error -f video4linux2 -i /dev/video0 -vframes 10 -video_size 640x480 test%3d.tiff
Does this ensure, image files are lossless as we got from camera?
Or since It's using -vframes 10 it works like a 10 frame video, and ffmpeg uses some video compression at each frame (making some information loss)?
/I'm sorry if this is a stupid question/
|
That solely depends on your source. Some cameras provide MJPEG/H.264 output, so it's hard to talk about "lossless" at all. Check ffmpeg output for more info.
I'm not entirely sure about TIFF (it has some compressed lossy forms AFAIK) but BMP and PNG formats are 100% lossless.
Another point to consider is that your camera even in lossless mode may provide YUV output which doesn't translate into RGB losslessly, so writing raw data could be more desireable.
| How to make sure images captured by FFMPEG from USB is lossless? |
1,619,126,357,000 |
I am trying to create a bash script that moves/renames (and / or creates a symbolic link) to all video files that are shorter than 3 min.
So far I have this Find command:
find "$findpath" -maxdepth "2" -type f -name '*.mp4' -print -exec avprobe -v error -show_format_entry duration {} \;
and then
if [ $duration -ge $DUR_MIN -a $dur -le $DUR_MAX ]
cd "$path2"
ln -sFfhv "$path1$file" "$file2"
fi
|
Does this do what you want?
dur_min=180
dur_max=3600 # or whatever you want the max to be
# find the appropriate files and deal with them one at a time
find "$findpath" -maxdepth 2 -type f -iname '*.mp4' -print |
while read file ; do
# read duration
duration="$(ffprobe -v quiet -print_format compact=print_section=0:nokey=1:escape=csv -show_entries format=duration "$file")"
# trim off the decimals; bash doesn't do floats
duration=${duration%.*}
if [[ $duration -gt $dur_min ]] && [[ $duration -lt $dur_max ]] ; then
echo "$file is $duration seconds long (rounded down)"
# do whatever you want, mv, ln, etc.
fi
done
Note I used iname rather than name to make it case insensitive (*.MP4, etc.)
Also, I'm using ffprobe not avprobe (which I don't have), but you have ffmpeg tagged, so I guess that's OK?
| Move and rename video files (*.mp4) shorter than 3 min |
1,619,126,357,000 |
I wrote the following code which is meant to create a file with a list of low-resolution media files:
#!/usr/bin/bash
find "$PWD" -type f -iname "*.avi" -execdir ~/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh {} + >~/pCloudDrive/VisualArts/lowres.films
find "$PWD" -type f -iname "*.mkv" -execdir ~/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh {} + >>~/pCloudDrive/VisualArts/lowres.films
find "$PWD" -type f -iname "*.mp4" -execdir ~/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh {} + >>~/pCloudDrive/VisualArts/lowres.films
As you can see the above code calls printer.sh which in turn executes the following code:
#!/usr/bin/bash
#The script is meant to print only the results of low resolution, that is starting with 1, 2, 3, 4, 5
if [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 2* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
elif [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 3* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
elif [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 4* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
elif [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 5* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
fi
Wanting to substitute repetitions in my code with variables I modified printer.sh :
#!/usr/bin/bash
output=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1)
if [[ $($output) == 2* ]]; then
echo "$(realpath $1)" && eval "$output"
elif [[ $($output) == 3* ]]; then
echo "$(realpath $1)" && eval "$output"
elif [[ $($output) == 4* ]]; then
echo "$(realpath $1)" && eval "$output"
elif [[ $($output) == 5* ]]; then
echo "$(realpath $1)" && eval "$output"
fi
Now it does not work and I get the output that looks like this:
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 6: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 8: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 10: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 12: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 6: 1920x800: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 8: 1920x800: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 10: 1920x800: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 12: 1920x800: command not found
What have I done wrong? How should I rewrite it?
|
It looks like what you want is something like:
output=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$1")
if [[ $output == [2345]* ]]
then
echo "$(realpath "$1")" "$output"
fi
I'm not sure why you used eval here at all. eval is used to execute strings that contain shell code. The output of ffprobe isn't code.
| Why doesn't `eval` work in this code? |
1,619,126,357,000 |
When I use youtube-dl, I use --recode-video mp4 to ensure output to MP4 (as well as -f bestvideo[height<=1080]+bestaudio/best[height<=1080]/best to limit downloads to 1080p resolution, max). So, videos I download from YouTube are usually transcoded via ffmpeg (I’m not enough of a an A/V person to know if the video track itself is being converted, or just being muxed into a new container format, but I can say it takes a while) before ending up as MP4.
I can also say that the resulting videos are enormous. Fifteen-minute videos, even simple ones that should compress well, are often many hundreds of megabytes. I suppose this is the level of quality YouTube uses internally, which is fine, but when ffmpeg is already spending so much time post-processing each video I would hope I could do something like set a maximum bitrate for the resulting file so my hard drive doesn’t completely fill up with youtube-dl-downloaded videos. Any advice? (Again, I already know how to limit the resolution of videos downloaded.)
(Also, if I’m not mistaken, the --audio-quality setting does something like what I describe, but for audio; I’m looking for advice on the video side of things.)
|
This is a list of available formats for sample 15 minute video.
$ youtube-dl -F https://www.youtube.com/watch?v=ItR1ViLHeP4
[youtube] ItR1ViLHeP4: Downloading webpage
[info] Available formats for ItR1ViLHeP4:
format code extension resolution note
249 webm audio only tiny 46k , webm_dash container, opus @ 46k (48000Hz), 5.25MiB
250 webm audio only tiny 55k , webm_dash container, opus @ 55k (48000Hz), 6.27MiB
251 webm audio only tiny 124k , webm_dash container, opus @124k (48000Hz), 14.15MiB
140 m4a audio only tiny 127k , m4a_dash container, mp4a.40.2@127k (44100Hz), 14.47MiB
160 mp4 256x144 144p 81k , mp4_dash container, avc1.4d400c@ 81k, 25fps, video only, 9.28MiB
278 webm 256x144 144p 84k , webm_dash container, vp9@ 84k, 25fps, video only, 9.64MiB
242 webm 426x240 240p 169k , webm_dash container, vp9@ 169k, 25fps, video only, 19.26MiB
133 mp4 426x240 240p 170k , mp4_dash container, avc1.4d4015@ 170k, 25fps, video only, 19.38MiB
243 webm 640x360 360p 308k , webm_dash container, vp9@ 308k, 25fps, video only, 35.18MiB
134 mp4 640x360 360p 445k , mp4_dash container, avc1.4d401e@ 445k, 25fps, video only, 50.75MiB
244 webm 854x480 480p 563k , webm_dash container, vp9@ 563k, 25fps, video only, 64.19MiB
135 mp4 854x480 480p 842k , mp4_dash container, avc1.4d401e@ 842k, 25fps, video only, 95.99MiB
247 webm 1280x720 720p 1128k , webm_dash container, vp9@1128k, 25fps, video only, 128.56MiB
136 mp4 1280x720 720p 1634k , mp4_dash container, avc1.4d401f@1634k, 25fps, video only, 186.16MiB
248 webm 1920x1080 1080p 1993k , webm_dash container, vp9@1993k, 25fps, video only, 226.97MiB
137 mp4 1920x1080 1080p 3027k , mp4_dash container, avc1.640028@3027k, 25fps, video only, 344.79MiB
18 mp4 640x360 360p 611k , avc1.42001E, 25fps, mp4a.40.2 (44100Hz), 69.66MiB
22 mp4 1280x720 720p 1761k , avc1.64001F, 25fps, mp4a.40.2 (44100Hz) (best)
As you can see 1080p video takes ~350[MB]. You can compare your resulting video with format/s on YT and see whether there is any difference.
My guess is there won't be much of a difference.
An advice to not fill out your disk would be to download less, either lower resolution or less in general, or get more storage.
You can also get cheap mechanical hard drive where you can store all of this stuff. They are big and will fit tons of data. Speed is irrelevant here as to replay it one needs 0.4[MB/s].
| youtube-dl — optimizing transcoded videos with regard to file size |
1,619,126,357,000 |
This question will seems very weird, please take the time to read
1- I have a .sh containing a ffmpeg command (this commands works, here it's all ok)
2- I trigger the .sh via a API call to start recording (all good here too)
3- the ffmpeg start generating the .mp4
4- I want to symlink the .mp4 to .m3u8 (because safari won't read .mp4 as a manifest)
** You probably wondering : why not just changing the ffmpeg in the .sh to output .m3u8
***** I did try that but for UNKNOWN reasons the script don't like ANY extension except .mp4
***** If I output .mov .mkv .m3u8 => I don't know why, but it stops after 10 seconds :(
***** The solution I found is to let ffmpeg create the .mp4 and then create a symlink to .m3u8 so hls.js can make it play in all browser including safari...
I'm looking for a way to wait for this .mp4 to exists before creating a symlink.
I tested to create the symlink before with ln -s fileThatDontExistsYet.mp4 NewFile.m3u8 but when trying to access NewFile.m3u8 result in a 404 not found.... If I manually wait for .mp4 and then do the same command => it works.
so in this odd situation, I found that sleep x seconds before creating the symlink is risky and not very good practice... is there a way via linux command to loop until the file arrives to symlink it ?
-------- EDIT 1 ----------------
CONTEXT :
SERVER1 => website
SERVER2 => openvidu running with docker
-1- a user creates a chatroom (SERVER2)
-2- SERVER2 sends a webhook to SERVER1 telling a session began
-3- then, a API call : SERVER1 tells SERVER2 to records and composed.sh is triggered ---- ALSO : SERVER1 waits x seconds and remote ssh to create the symlink
-4- the .sh launch ffmpeg
-5- the ffmpeg creates the .mp4 while the chat is going on
-6- my modification (see below) is to generate a HLS format stream
-7- other users access to the .m3u8 via their browser (the page have hls.js to play the .m3u8) {SERVER1}
-8- I can achieve 4 seconds delay for the stream which is not bad ;)
The link to view the FULL raw .sh is here : https://raw.githubusercontent.com/OpenVidu/openvidu/master/openvidu-server/docker/openvidu-recording/scripts/composed.sh
****** LINE 79 ********
I REPLACED
-c:a aac -c:v libx264 -preset ultrafast -crf 28 -refs 4 -qmin 4 -pix_fmt yuv420p
WITH THIS
-c:a aac -c:v libx264 -movflags +dash
-preset ultrafast -crf 28 -refs 4 -qmin 4 -pix_fmt yuv420p
-tune zerolatency -c:a aac -ac 2 -profile:v main
-flags -global_header -bufsize 969k
-hls_time 1 -hls_list_size 0 -g 30
-start_number 0 -streaming 1 -hls_playlist 1
-lhls 1 -hls_playlist_type event -f hls
It seems weird but it works... my only worry is the "wait x seconds" to create a symlink... what is the server is very busy and the .mp4 gets generated after the x second... it would create issues for playing the stream.
|
I have to admit that i didn't read your whole question but judging from the title this should work:
while [ ! -f /tmp/originalfile ] ; do sleep 1 ; done ; ln -s /tmp/originalfile /tmp/symlink
| Linux is there a way to wait for a file to be created to make a symlink |
1,619,126,357,000 |
I have some .tta files I downloaded from internet. I can play them on VLC locally, but they cannot be played from certain media player app, for example, an android app. So here I need to convert "tta" files to "mp3" or "wav" files. Since they're high resolution sound, I'd like to know how to convert them to wav (or flac) rather than to mp3, but if you know I'd like to know both of the ways. So, is there any way to do that? Thanks.
|
for i in *.tta; do
ffmpeg -i "$i" "${i%.tta}.wav"
done
| Convert TTA file to MP3 or WAV file? |
1,619,126,357,000 |
I've got a directory with thousands of images (png, jpg, bmp, etc.) and thousands of videos (mp4, mpv, mpeg, etc.).
The png images may be ~10 MB and I can open them one at a time in GIMP, reduce quality from 100% down to 92% and the image size goes down to ~2MB and the quality (to the eye) hardly changes.
How can I do this process in bulk (ie batch) to everything (pics and video) in the directory using ffmpeg? And how do I overwrite everything in the directory so I don't have duplicates?
Are there any GUI tools for such a thing? Maybe it's better to stick with the command line.
|
You can do it in a for loop as below
for f in *
do
extension="${f##*.}"
filename="${f%.*}"
ffmpeg -i "$f" -q:v 1 "$filename"_lq."$extension"
rm -f "$f"
done
By increasing the number -q:v 1 the quality will be more reduced.
| ffmpeg batch command to reduce file quality |
1,619,126,357,000 |
I have a few video files which have "humm" sound in the audio. So, I created the following script for batch processing. I am using ffmpeg, to extract audio to .mp3, and sox to denoise, which will output noise free mp3 file.
mkdir -p ./tmp;
for f in *.mp4;
do
title=${f%.mp4};
echo "Working on $f";
mv ./"$f" ./tmp/ && ffmpeg -i ./tmp/"$f" -f mp3 -ab 128000 -vn ./tmp/"$title"_noise.mp3;
echo "Sox process started...";
sox -v 0.80 ./tmp/"$title"_noise.mp3 ./tmp/"$title"_128.mp3 noisered ./noise_profile 0.20 && sox ./tmp/"$title"_128.$mp3 -C 96 ./$title.mp3;
echo "Removing Audio from video file...";
ffmpeg -loglevel warning -stats -y -i ./tmp/"$f" -c copy -an ./"$f";
done
But the problem is, I observed that there is 00:00:00.050s (HH:MM:SS.ms - Checked with Audacity) of delay added to the final mp3 file. I believe Sox is adding this delay.
How can I solve this? Or, how can I remove/trim 00.050 seconds from the
beginning and add 00.050 seconds of silence at the end of the
audio track? OR
Is there any other better way to finish my task?
NOTE: I am trying to work with .wav instead of .mp3 after reading below reply, if it works I will update here.)
|
I found Answers for my own questions. There are 2 ways to solve this. Answer for my first question is...
1. How can I solve this? Or, how can I remove/trim 00.050 seconds from the beginning and add 00.050 seconds of silence at the end of the audio track?
Answer 1: This might be destructive as I am converting mp3 multiple times. Still if someone wants to know. Use below command to trim the beginning and use pad to add silence at the end.
sox Speech_01.mp3 Speech_01_Corrected.mp3 trim 0.049 pad 0 0.050
trim 0.049 will remove 049ms of silence from the beginning. pad 0 0.050 will add 050ms of silence at the end.
Answer 2: This is what solved my problem. I followed instructions from this page, and pieced together a batch script.
2. Is there any other better way to finish my task?
As @Artem S. Tashkinov pointed out, LAME adds delay because of sample differences between .wav and .mp3 formats. (That is what I understood). So, I used only .wav as mentioned in this page.
NOTE: Below sox command was deleting a small part from the end of the audio file, for some unknown reason. So, I had to use pad to add some silence at the end of the audio, and avoid loosing any part of the audio accidentally. Through trial and error I came to know that 0.010ms is enough for my case.
# You can observe pad here, which is adding silence at the end.
sox ./tmp/"$title"_noisy.wav ./tmp/"$title"_noisy_s.wav pad 0 0.010
# Below command will delete small part from the end of output wav file,
# Hence the above command.
sox -v 0.80 ./tmp/"$title"_noisy_s.wav ./"$title".wav noisered ./allnoise_profile 0.30
Collecting noises to generate a noise profile.
In my case, there were different variations of "hmm" noise in my files. As a result selecting just one noise sample, for all files, was not working for me. Hence I copied variations which were escaping and created one .wav file (allnoise_samples.wav), using Audacity. Note: Having silence between variations didn't work for me. So, samples are continuous.
# Use below command to generate a noise sample file.
sox ./allnoise_samples.wav -n noiseprof ./allnoise_profile
Here is the final script for batch processing.
Working with .wav files is heavy on storage. So, I am deleting them as soon as their purpose is fulfilled.
mkdir -p ./tmp;
for f in *.mp4;
do
title=${f%.mp4};
echo -e "\n\n$f - Splitting Audio and video files...";
mv ./"$f" ./tmp/"$title"_O.mp4 && ffmpeg -i ./tmp/"$title"_O.mp4 -c:a pcm_s16le -ar 128k -vn ./tmp/"$title"_noisy.wav;
ffmpeg -i ./tmp/"$title"_O.mp4 -c copy -an ./"$title"_v.mp4;
echo "Adding Silence at the end...";
sox ./tmp/"$title"_noisy.wav ./tmp/"$title"_noisy_s.wav pad 0 0.010 && rm -rf ./tmp/"$title"_noisy.wav;
echo "Sox process started...";
sox -v 0.80 ./tmp/"$title"_noisy_s.wav ./"$title".wav noisered ./allnoise_profile 0.30 && rm -rf ./tmp/"$title"_noisy_s.wav;
echo -e "Sox finished... \nMerging Audio and video files...";
ffmpeg -loglevel warning -stats -y -i ./"$title"_v.mp4 -i ./"$title".wav -map 0:v -map 1:a -c:v copy -c:a aac -b:a 96k ./"$f";
rm -rf ./"$title"_v.mp4 ./"$title".wav;
done
| sox command is automatically adding delay in the begining of mp3 |
1,619,126,357,000 |
I use the following command for my script to record the entire screen :
ffmpeg -f x11grab -y -r 24 -s 1366x768 -i :0.0 -f alsa -i default -vcodec libx264 out.avi
But after running that , out.avi doesn't contain video , just sound.
Here's the complete output of that (interrupted via Ctrl+C ) :
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[x11grab @ 0x56271f542e00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0':
Duration: N/A, start: 1592158154.433194, bitrate: N/A
Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1366x768, 24 fps, 1000k tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, alsa, from 'default':
Duration: N/A, start: 1592158154.486958, bitrate: 1536 kb/s
Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[swscaler @ 0x56271f57d220] Warning: data is not aligned! This can lead to a speed loss
[libx264 @ 0x56271f56c8c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x56271f56c8c0] profile High 4:4:4 Predictive, level 3.2, 4:4:4 8-bit
[alsa @ 0x56271f54cd20] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Output #0, avi, to 'out.avi':
Metadata:
ISFT : Lavf57.83.100
Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv444p(progressive), 1366x768, q=-1--1, 24 fps, 24 tbn, 24 tbc
Metadata:
encoder : Lavc57.107.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p
Metadata:
encoder : Lavc57.107.100 libmp3lame
frame= 14 fps=0.0 q=0.0 size= 10kB time=00:00:00.00 bitrate=N/A speed= frame= 26 fps= 26 q=0.0 size= 10kB time=00:00:00.00 bitrate=N/A speed= frame= 38 fps= 25 q=0.0 size= 10kB time=00:00:00.00 bitrate=N/A speed= frame= 50 fps= 25 q=0.0 size= 10kB time=00:00:00.00 bitrate=N/A speed= frame= 62 fps= 25 q=28.0 size= 10kB time=00:00:00.16 bitrate= 476.2kbits/frame= 74 fps= 24 q=28.0 size= 10kB time=00:00:00.67 bitrate= 118.1kbits/frame= 80 fps= 22 q=-1.0 Lsize= 516kB time=00:00:03.25 bitrate=1301.2kbits/s speed=0.906x
video:487kB audio:16kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.520141%
[libx264 @ 0x56271f56c8c0] frame I:1 Avg QP:19.01 size:112157
[libx264 @ 0x56271f56c8c0] frame P:20 Avg QP:16.66 size: 18812
[libx264 @ 0x56271f56c8c0] frame B:59 Avg QP:21.03 size: 181
[libx264 @ 0x56271f56c8c0] consecutive B-frames: 1.2% 0.0% 3.8% 95.0%
[libx264 @ 0x56271f56c8c0] mb I I16..4: 44.2% 0.0% 55.8%
[libx264 @ 0x56271f56c8c0] mb P I16..4: 2.4% 0.0% 5.3% P16..4: 2.4% 0.5% 0.4% 0.0% 0.0% skip:89.0%
[libx264 @ 0x56271f56c8c0] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 4.4% 0.0% 0.0% direct: 0.0% skip:95.5% L0:39.8% L1:58.9% BI: 1.3%
[libx264 @ 0x56271f56c8c0] coded y,u,v intra: 48.6% 8.6% 8.0% inter: 0.2% 0.0% 0.0%
[libx264 @ 0x56271f56c8c0] i16 v,h,dc,p: 55% 41% 3% 1%
[libx264 @ 0x56271f56c8c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 25% 17% 2% 5% 4% 5% 4% 4%
[libx264 @ 0x56271f56c8c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x56271f56c8c0] ref P L0: 71.9% 13.0% 12.4% 2.6%
[libx264 @ 0x56271f56c8c0] ref B L0: 77.7% 21.7% 0.6%
[libx264 @ 0x56271f56c8c0] ref B L1: 96.0% 4.0%
[libx264 @ 0x56271f56c8c0] kb/s:1197.83
Exiting normally, received signal 2.
I've also installed x264 and libx264-152 packages.
I use KDE Neon 5.19 (Ubuntu 18.04).
Thanks in advance.
|
Depends which app you are using to play your screencast. VLC simply failed, citing a "hardware accelerator failed to decode picture".
When changing to "X11 video output (XCB) I could see that video - with an offset due to a 2 display setup... The frames are captured but the codec seems strange: High 4:4:4 Predictive@L3. Changing the profile did not work, so it seems that that ffmeg is using XCB.
FFMPEG Documentation
| No video recorded when using x264 codec in ffmpeg |
1,619,126,357,000 |
Months ago I would occasionally record little snippets of audio as FLAC files using ffmpeg and ALSA. I used a command that looked more or less like this:
ffmpeg -f alsa -ar 48000 -ac 1 -acodec flac -i hw:0 testfile.flac
(hw:0 being my microphone's card via arecord -l)
If memory serves, there was one other option in there somewhere that made the difference, but I can't tell what it would've been. It might've been similar to the --format options for arecord? I even dug through every single option in ffmpeg to see if I would find something familiar; no dice. Either way, now ALSA just screams that sample format 0x1500c is not supported… whatever that means.
However, if I remove the -acodec flac option and change the file name to testfile.wav everything works like a charm. Except, of course, I don't get the file format I had intended.
I'm very confident I still have all the necessary packages installed, but I can't for the life of me get this thing to cooperate!
|
Ffmpeg is capable of applying the same options to different inputs and outputs, which result in ffmpeg being sensitive to the position of the options.
The following will use your settings and output to a FLAC file (recognized by the file ending):
ffmpeg -f alsa -ar 48000 -ac 1 -i hw:0 testfile.flac
The settings are applied to the next input or output, so while it is not needed in your example, you can use the -acodec after listing your input files or streams, and before your output e.g.:
ffmpeg -f alsa -ar 48000 -ac 1 -i hw:0 -acodec flac testfile.flac
| How can one record mic audio straight to a FLAC file? |
1,619,126,357,000 |
Example :
Content of the playlist file:
(0:00:00) Abcde efgh ijk
(0:04:28) bcdea gefgh idjk
(0:17:00) qbecde efgh ijk
(0:27:40) hebcde efgh ijk
(0:35:03) Abeds esdh dfk
(0:49:16) dfhks ierkld sls
(0:58:26) dhekd sdoemc ks
(1:09:40) whdjoc dlf fg
...
I am looking for a way to slice a video by taking the -ss, -t and output file name arguments from the playlist file.
ffmpeg -ss "$1" -i "$3" -to "$2" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "$4".mp4
Where the timestamp at the beginning becomes the -ss argument, the text becomes the name of the output file and the timestamp in the next line becomes the -t argument.
|
With awk:
awk -v input="bla.mp4" -v to_last="1:23:45" -F'[()]' '
BEGIN {
str="ffmpeg -ss \"%s\" -i \"%s\" -to \"%s\" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac \"%s_%s.mp4\"\n"
}
NR>1 {
printf str, ss, input, $2, ++cnt, output
}
{ ss=$2; sub(/^ /,"",$3); output=$3 }
END {
printf str, ss, input, to_last, ++cnt, output # print the last line
}
' playlist
The input file is split on ( and ) into fields and field2 is read as ss or t value and field3 as output filename (with the first space character removed).
You need to specify the input file for -i and the duration for the last playlist entry tlast.
Output:
ffmpeg -ss "0:00:00" -i "bla.mp4" -to "0:04:28" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "Abcde efgh ijk.mp4"
ffmpeg -ss "0:04:28" -i "bla.mp4" -to "0:17:00" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "bcdea gefgh idjk.mp4"
ffmpeg -ss "0:17:00" -i "bla.mp4" -to "0:27:40" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "qbecde efgh ijk.mp4"
ffmpeg -ss "0:27:40" -i "bla.mp4" -to "0:35:03" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "hebcde efgh ijk.mp4"
ffmpeg -ss "0:35:03" -i "bla.mp4" -to "0:49:16" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "Abeds esdh dfk.mp4"
ffmpeg -ss "0:49:16" -i "bla.mp4" -to "0:58:26" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "dfhks ierkld sls.mp4"
ffmpeg -ss "0:58:26" -i "bla.mp4" -to "1:09:40" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "dhekd sdoemc ks.mp4"
ffmpeg -ss "1:09:40" -i "bla.mp4" -to "1:23:45" -c copy -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a aac "whdjoc dlf fg.mp4"
I'm only familiar with Handbrake, let me know if something needs to be changed.
| Slicing a video with arbitrary seek times from an input file (playlist) |
1,619,126,357,000 |
I'm trying to convert some audio files from FLAC to ALAC (m4a) using ffmpeg. For my environment (Apple & Sonos), the lowest common denominator seems to be as follows:
ALAC (.m4a) encoding at 44.1kHz, & bit depth = 16 bits
The problem I'm having is that the output file produced by ffmpeg has a bit depth of '32p'; i.e. sample_fmt=s32p
I've done the conversion with several sets of arguments, but the results are the same. I've been unable to find anything that explains why this might be. Here's one of the commands I've tried:
$ file='01 Jubilee.flac'
$ ffmpeg -i "$file" -acodec alac -ar 44100 -sample_fmt:0 s16 -c:v png "${file/%.flac/.16.m4a}"
I've run ffprobe on the input file to determine its format:
$ ffprobe -i "$file" -show_streams
Which (in summary) yields:
Stream #0:0: Audio: flac, 176400 Hz, stereo, s32 (24 bit)
Stream #0:1: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 450x446 [SAR 72:72 DAR 225:223], 90k tbr, 90k tbn, 90k tbc (attached pic)
... and on the output file:
$ ffprobe -i "${file/%.flac/.16.m4a}" -show_streams
Which (in summary) yields:
Stream #0:0(und): Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s32p (24 bit), 1564 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:1: Video: png, rgb24(pc), 450x446 [SAR 1:1 DAR 225:223], 90k tbr, 90k tbn, 90k tbc (attached pic)
[STREAM]
index=0
codec_name=alac
codec_long_name=ALAC (Apple Lossless Audio Codec)
profile=unknown
codec_type=audio
codec_time_base=1/44100
codec_tag_string=alac
codec_tag=0x63616c61
sample_fmt=s32p
sample_rate=44100
...
etc, etc
I've posted only a small snippet of the ffprobe output, but can provide all of it if needed. Also, my ffmpeg version:
$ ffmpeg -version
ffmpeg version git-2020-01-13-7225479 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.8)
Finally, here's the output of the ffmpeg conversion above:
$ ffmpeg -v info -hide_banner -i "$file" -acodec alac -ar 44100 -sample_fmt:0 s16 -c:v png "${file/%.flac/.16.m4a}"
Input #0, flac, from '01 Jubilee.flac':
Metadata:
track : 1
TITLE : Jubilee
ARTIST : Bill Charlap Trio
album_artist : Bill Charlap Trio
ALBUM : Stardust The Music Of Hoagy Carmichael
DATE : 2003
GENRE : Jazz
TRACKTOTAL : 11
disc : 1
DISCTOTAL : 1
ALBUM ARTIST : Bill Charlap Trio
Duration: 00:02:23.17, start: 0.000000, bitrate: 6176 kb/s
Stream #0:0: Audio: flac, 176400 Hz, stereo, s32 (24 bit)
Stream #0:1: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 450x446 [SAR 72:72 DAR 225:223], 90k tbr, 90k tbn, 90k tbc (attached pic)
Metadata:
comment : Cover (front)
File '01 Jubilee.16.m4a' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (mjpeg (native) -> png (native))
Stream #0:0 -> #0:1 (flac (native) -> alac (native))
Press [q] to stop, [?] for help
[swscaler @ 0x10dc6b000] deprecated pixel format used, make sure you did set range correctly
[ipod @ 0x7fc3a1002200] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
Output #0, ipod, to '01 Jubilee.16.m4a':
Metadata:
track : 1
TITLE : Jubilee
ARTIST : Bill Charlap Trio
album_artist : Bill Charlap Trio
ALBUM : Stardust The Music Of Hoagy Carmichael
DATE : 2003
GENRE : Jazz
TRACKTOTAL : 11
disc : 1
DISCTOTAL : 1
ALBUM ARTIST : Bill Charlap Trio
encoder : Lavf58.35.102
Stream #0:0: Video: png, rgb24(progressive), 450x446 [SAR 1:1 DAR 225:223], q=2-31, 200 kb/s, 90k fps, 90k tbn, 90k tbc (attached pic)
Metadata:
comment : Cover (front)
encoder : Lavc58.65.103 png
Stream #0:1: Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s32p (24 bit), 128 kb/s
Metadata:
encoder : Lavc58.65.103 alac
frame= 1 fps=0.8 q=-0.0 Lsize= 27745kB time=00:02:23.22 bitrate=1587.0kbits/s speed= 113x
video:396kB audio:27342kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.026342%
|
This works here.
ffmpeg -i in -c:a alac -ar 44100 -sample_fmt s16p -c:v png -vsync 0 out.m4a
Note that ALAC encoder checks if the raw frame is 16-bit planar
| ffmpeg only outputs at bit depth s32p when converting from flac to alac |
1,619,126,357,000 |
The video created by this command:
ffmpeg -y -framerate 25 -i picture.png -i sound.wav -vcodec libx264 -crf 20 -preset medium -acodec aac -vf scale=1280:-2,format=yuv420p output.mp4
is not accepted ("Video assets: Your mezzanine file has failed.") by Amazon Prime.
How to make a video accepted by such a third party?
|
Your video input is a single frame, which lasts 0.04 seconds. Likely the cause of your submission failure. Loop the image indefinitely and then tell ffmpeg to stop output file with shortest stream (the audio).
ffmpeg -y -framerate 25 -loop 1 -i picture.png -i sound.wav -vf scale=1280:-2,format=yuv420p -vcodec libx264 -crf 20 -preset medium -acodec aac -shortest -fflags +shortest -max_interleave_delta 200M output.mp4
| ffmpeg creates a broken video |
1,576,367,634,000 |
I'm struggling to find a one line command to merge new subtitle and delete existing ones from video file.
Example:
test1.mkv (already contain softcoded subs, dont need them)
test1.srt (only subtitle that i want on video)
Working under ubuntu server 18.04 LTS 64bit
Any help?
SOLUTION UPDATE;
mkvmerge -o output.mkv -S 1.mkv --language 0:hrv --sub-charset 0:utf-8 1.srt
This will do the work
|
I will recommand to use mkvtoolnix
A package exits for ubuntu https://packages.ubuntu.com/bionic/mkvtoolnix
with the right combination of mkvextract and mkvmerge you can do what you want .
And you will use mkvinfo to display information about your file .
to install ...
apt-get install mkvtoolnix
to see a list of commands
dpkg -L mkvtoolnix | grep bin
and read man mkvmerge and man mkvextract
| ffmpeg add new srt and delete old ones |
1,576,367,634,000 |
When I tra to extract q frame at second 1 from a video file it says this:
(running via ssh on synology diskstation with ffmpeg installed)
Error with output (COMMAND ON TOP) (https://i.sstatic.net/hhUyA.jpg)
|
My ffmpeg was outdated and didnt support currrent switches and options.
| FFMPEG - Extracting a frame from .mov doesnt work (multiply errors) |
1,576,367,634,000 |
I like to compress large video files before storing them to hard disk. In Fedora-29-bash, I currently use the following ffmpeg command for re-encoding; it balances compression with quality:
ffmpeg -i $in_path -b:v 960k -bufsize 9600k -strict -2 $out_path
When executing the above command against a 2gb video file that has a 30 minute runtime, the execution will take about 20 minutes. My hardware is shown at the end of this query. Can this video re-encoding be sped up?
In other words, if I abandon ffmpeg in favor of any other software (e.g. handbrake), will I attain faster re-encoding? Based on my experiences copying files via bash (e.g. the cp or rsync commands) vs using the (nemo) file manager, my intuition is that nothing will beat the bash-ffmpeg performance.
I am submitting this query just to double check my intuition.
My Hardware
os : 64 bit fedora 29
cpu : Intel I5-4440 Processor BX80646I54440
mobo : (64 bit) Gigabyte H97 SATA Express M.2 SSD UEFI DualBIOS
: DDR3 1600 LGA
memory : 32 gb : 2 x [G.Skill F3-1600C10D-16GAO Ares 16GB (2x8GB)
: DDR3-1600Mhz Memory RAM]
psu : corsair cx series 600 watt
hdisk : 1tb internal western digital wd10ezex sata
video card : none - I use mobo's onboard video at 1920x1080.
sound card : none - I use mobo's onboard audio
|
For MKV or MP4, the default video codec is libx264, which has a set of presets, with different speed and quality tradeoffs. The default preset is medium. You can switch to a faster preset like veryfast. See list at https://trac.ffmpeg.org/wiki/Encode/H.264#crf
| Accelerating Video Conversion |
1,576,367,634,000 |
I use ffmpeg -i FILE_NAME -vf fps=1/1 FILE_NAME%05d.jpg -hide_banner to convert a single file to several images which keep the file name followed by 5 zeros, a counter and then ends with a .jpg.
How do I do the same thing to all, let's say .mov, files in a single folder, keeping the file naming convention the same?
I understand there will be a loop and a *.mov to select all files in the folder but I'm lost in the naming convention part.
|
for FILE_NAME in *.mov
do
ffmpeg -i "$FILE_NAME" -vf fps=1/1 "$FILE_NAME"%05d.jpg -hide_banner
done
This will result in output files named like something.mov00000.jpg. To remove the .mov or any other file type ending you can do
for FILE_NAME in *.mov
do
ffmpeg -i "$FILE_NAME" -vf fps=1/1 "${FILE_NAME%.*}"%05d.jpg -hide_banner
done
| Convert all video files in a folder to images per frame using ffmpeg iteratively |
1,576,367,634,000 |
I've got an .mkv with 1 video stream, 2 audio streams, and 12 subtitle tracks.
I want to turn it to greyscale, just use the first audio track, and use the eng subtitle track 6 (according to ffmpeg -i this is labeled as stream 0:11)
I'm running a filter to turn the video to greyscale (taken from ffmpeg documentation), which works fine, and by default it's picking the right audio stream, so I'm good there, but it also seems to be picking the first subtitle track, which is not the subtitle track I want.
The topics online out there about subtitles tend to map all the streams to accomplish this or they talk about importing subtitles, neither of these I want, but even if I try to map all the subtitle tracks I get an error saying that filtering and stream copying can't be used together.
Command I'm running:
$ ffmpeg -i color.mkv -vf colorchannelmixer=.3:.4:.3:0:.3:.4:.3:0:.3:.4:.3 \
-c:a copy grey.mkv
I've tried all sorts of variants using c:s (not even sure if that's the right way to call subtitle tracks), but the results I get tend to be worse than what I already have (when I do get them to run they seem to be missing, so they can't even play).
I've searched the ffmpeg documentation for this, but either this specific instance isn't there or I'm not understanding it when it's presented.
|
Use this:
$ ffmpeg -i color.mkv -vf format=gray -map 0:v -map 0:a:0 -map 0:11 \
-c:a copy -c:s copy grey.mkv
The maps set which tracks to include. The c with specifiers set the codec operation to copy for those specified streams.
| FFMPEG run a video filter and copy only 1 subtitle stream |
1,576,367,634,000 |
I have a video that first audio stream is aac and the second is DTS. I want to copy the first one but re-encode the second one to aac.
The code I use usually is:
#!/bin/bash
ffmpeg -hide_banner -stats -i "Movie.mkv" -c:v libx265 -x265-params crf=20 -map 0 -c:a copy "MovieOut.mkv"
How to do this?
|
Use
ffmpeg -i "Movie.mkv" -map 0 -c:v libx265 -x265-params crf=20 -c:a:0 copy -c:a:1 aac "MovieOut.mkv"
| ffmpeg; copy stream 1 encode stream 2 |
1,576,367,634,000 |
At some point, I had an error with dependencies and had to remove some forcefully with pacman -Rdd libvpx libx264.
I have since reinstalled them, however I get this error upon each yaourt -Syua:
error: missing 'libvpx.so=4-64' dependency for 'ffmpeg0.10'
error: missing 'libx264.so=148-64' dependency for 'ffmpeg0.10'
Here is what I did to track down the problem
~ $ pacman -Qs libvpx
local/libvpx 1.7.0-1
VP8 and VP9 codec
~ $ pacman -Qs libx264
local/libx264 2:152.20171224-1
Library for encoding H264/AVC video streams (8bit depth)
I do not get the error when I run pacman -Syu.
|
You don't get the error when you run pacman because these libraries are not part of the official repositories, they are dependencies of an AUR package.
Yaourt is not your package manager, it is an AUR helper: use it to help you install and manage AUR packages (or a better solution, use one that is not insecure and buggy, like auracle).
You fix the errors by rebuilding the AUR package, ffmpeg0.10 and the requisite dependencies.
| What is this ffmpeg dependency error telling me and how do I fix it? |
1,576,367,634,000 |
my HD Homerun for PLEX saves .TS files (transport stream).
in order to shrink this to 720 i use the following script:
#!/bin/bash
for INF in *.ts
do ffmpeg -i "$INF" -vf scale=-1:720 -c:v libx264 -crf 23 -preset ultrafast -c:a copy "${INF%.*}.mp4"
done
this works well and converts every .TS in folder .sh script is stored in to an mp4 container. I then run the following script:
#!/usr/local/bin/bash
for INF in *.mp4
do
echo "Extracting subtitles"
ccextractor "$INF" -o "/tmp/$(basename "$INF" .ts).srt"
echo "Moving subtitles"
mv -v /tmp/*.srt .
done
My goal is combine both these bash loops into one script. Ideally i would like, one script that will:
a) scan current folder and all sub-folders looking for .ts files.
b) remux .ts to .mp4
c) pull closed captions out of .ts and store as .srt
d) remove all .ts files
I am not sure I added a / after 'for INF in *.ts' would include sub-directories.
and not sure how to join these two scripts into one file or where to put the remove file(s) code
any ideas would be greatly appreciated.
-shaun
|
How about this:
for x in *.ts
do
y=$(basename "$x" .ts)
ffmpeg -i "$x" "$y".mp4
ffmpeg -i "$x" "$y".srt
done
| Bash Script with ffmpeg |
1,576,367,634,000 |
I often create digital animations by preparing all the frames in .png format (with minimal compression), that I need to convert to video format for upload to websites such as reddit, instagram, gfycat.
I know very little of all the different standards of compression, and these websites aren't very clear as to what format they accept, but I've found a recipe that usually works for me, and that creates files that get accepted by these websites:
# step 1
mencoder mf://frame*.png -mf w=$WIDTH:h=$HEIGHT:fps=$FPS:type=png \
-ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=16000:keyint=15:mbd=2:trell \
-oac copy -o step1.avi
# step 2
mencoder step1.avi -o step2.mp4 -of lavf -lavfopts format=mp4 -ovc x264 -sws 9 \
-x264encopts nocabac:level_idc=30:bframes=0:bitrate=2048:threads=auto:turbo=1:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh
However I'm not completely sure what it does*, therefore I'm not able to:
make it a single instruction
tune the compression rate.
Indeed, I'd often prefer a less compressed result.
What route can I follow to go from PNG frames to a web-friendly video file (that I believe is a H.264/MPEG-4 MP4) that gives me the ability to tune compression?
* for instance: this is an example frame
(note: honestly it seems to me that it looks much worse when watching it in VLC than when taking a snapshot through the VLC tool - this makes it very difficult to make the question understandable and the results comparable)
Even if in step 1 I have specified $WIDTH and $HEIGHT to match the ones of the original image, it has apparently changed both, and not preserved the aspect ratio. There is also more blur to the final image, that might be just an effect of such resize.
edit: see the actual system screenshot of the mplayer window below (would be the same with VLC). The tile grouts are very blurred compared to both the PNG source and the VLC "internal" screenshot feature
Detail:
|
ffmpeg
As pointed out in the comments, ffmpeg offers a good one-step solution with a simple "quality" parameter: crf, or "constant rate factor" (read this post explaining crf).
See this post for simple instructions for going from PNG to H.264 using ffmpeg.
In short:
# Assuming the frames are called frame0000.png, frame0001.png ...
#
# set $FPS, $WIDTH, $HEIGHT, $FIRSTFRAME,
# $CRF (see above) to the desired value, then run:
ffmpeg -r $FPS -f image2 -s ${WIDTH}x$HEIGHT -start_number $FIRSTFRAME \
-i frame%04d.png -vcodec libx264 -crf $CRF -pix_fmt yuv420p output.mp4
$CRF is 23 by default; values smaller than 23 give better quality and larger files, values larger than 23 increase the compression.
| H.264/MPEG-4 from PNG frames: how to, and how to tune compression |
1,576,367,634,000 |
I am trying to compile FFmpeg in CentOS from source code. I referenced the official compilation guide (https://trac.ffmpeg.org/wiki/CompilationGuide/Centos) for CentOS step by step, and have installed the listed dependencies. But when I tried to configure FFmpeg, I met with a problem as below:
The error lines (1249~1270) in file configure are:
check_exec(){
check_ld "cc" "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
}
check_exec_crash(){
log check_exec_crash "$@"
code=$(cat)
# exit() is not async signal safe. _Exit (C99) and _exit (POSIX)
# are safe but may not be available everywhere. Thus we use
# raise(SIGTERM) instead. The check is run in a subshell so we
# can redirect the "Terminated" message from the shell. SIGBUS
# is not defined by standard C so it is used conditionally.
(check_exec "$@") >> $logfile 2>&1 <<EOF
The config.log shows:
zscale_filter=yes
zscale_filter_deps=libzimg
mktemp -u XXXXXX
Ubjjqz
check_ld cc
check_cc
BEGIN /tmp/ffconf.rgbbriKe.c
1 int main(void){ return 0; }
END /tmp/ffconf.rgbbriKe.c
gcc -I/home/vis/guangli/local/include -c -o /tmp/ffconf.LLalSg6X.o /tmp/ffconf.rgbbriKe.c
gcc -L/home/vis/guangli/local/lib -ldl -o /tmp/ffconf.G3SYKa9M /tmp/ffconf.LLalSg6X.o
C compiler test failed.
My OS is CentOS x86_64, the gcc installed in system is gcc-4.4.6, but in order to compile FFmpeg with gcc-4.8.2, I add GCC482_HOME/{bin,include} to environment variables: PATH, C_INCLUDE_PATH correspondingly.
|
Turns out (for reasons yet unknown) that any executable placed in /tmp on your system segfaults. Even cp /bin/ls /tmp && cd /tmp && ./ls gives an ls that segfaults. But if moved to your home directory, then it works.
That is breaking configure; the obvious workaround is to create a subdirectory of your home directory and set TMPDIR to that.
| error while configuring FFmpeg in CentOS: Segmentation fault & gcc is unable to create an executable file |
1,576,367,634,000 |
In ncmpcpp (an itunes-like ncurses client for mpd) I sort my music files by ALBUMARTIST tag. In my collection I have mp4 files, then mp4 doesn’t support ALBUMARTIST tag and all mp4 goe to “empty” section in not with others files in the same album.
So, how can I force to set an ALBUMARTIST tag for mp4 or, if it isn’t possible, in witch format (probably of the MPEG family) supporting ALBUMARTIST tag can I export my mp4 without losing quality?
|
MP4s do apparently support the Album Artist tag. Using ffmpeg, the syntax is
ffmpeg -i in.mp4 -c copy -metadata album_artist="YourArtist" out.mp4
In Mediainfo, this shows up as "Artist/Performer: YourArtist"
BTW, the comment by @ridgy has it backwards. Tags are the purview of containers, not codecs. The tag writing functions are in the source code for the muxers, not encoders. My above command doesn't even require the presence of an audio stream in the MP4.
| ALBUMARTIST tag is not known for mp4 |
1,576,367,634,000 |
How can I make the waveform white in colour? No matter what I do I get brown. This is presumably green and red combined?
for i in *.mp3 ; do
ffmpeg -i "$i" -loop 1 -i background.jpg -filter_complex "[0:a]showwaves=s=1280x720:mode=line,format=rgba,colorkey=0x000000:0.1:0.5[fg]; \
[1:v]scale=1280:-1,crop=iw:720[bg]; \
[bg][fg]overlay=shortest=1,format=yuv420p[out]" -map "[out]" -map 0:a -c:v libx264 -preset fast -crf 18 -c:a libopus "$(basename "${i/.mp3}").mkv"
sleep 60
done
|
Each channel has it's own default color, and overlapping channels will combine colors but there are several options to deal with this.
Choose the channel colors
showwaves=s=1280x720:mode=line:colors=white
Split the channels
showwaves=s=1280x720:mode=line:colors=white:split_channels=1
Make a mono waveform
aformat=channel_layouts=mono,showwaves=s=1280x720:mode=line:colors=white
Also see
FFmpeg Filter Documentation: showwaves
Use parameter expansion instead of basename
Replace "$(basename "${i/.mp3}").mkv" with "${i%.mp3}.mkv" for one less process.
| Change FFmpeg waveform colour overlaid over image |
1,576,367,634,000 |
I'm having trouble installing the ffmpeg on my CentOS 6.8.
Before I settled from this tutorial.
Today can no longer, key links returns a 'Not found' on the island.
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
curl: (22) The requested URL returned error: 404 Not Found
error: http://apt.sw.be/RPM-GPG-KEY.dag.txt: import read failed (2).
I also tried this tutorial but it still fails.
Can someone help me? I take much of ffmpeg!
|
After many attempts to get installed and made an explanatory tutorial on how to install FFmpeg on CentOS!
Link: http://central.lpservidor.org/knowledgebase.php?action=displayarticle&id=36
| Error Installing ffmpeg on CentOS 6.8 |
1,576,367,634,000 |
Help me debugs this script to create control ffmpeg from a bash script.
for f in $FILES
do
INPUT_MOVIE=`basename "${f%.*}.mkv"`
OUTPUT_MOVIE=${MOVIE:1}
OUTPUT_MOVIE=${OUTPUT_MOVIE:0:2}") processed "${OUTPUT_MOVIE:2}
/usr/bin/ffmpeg -i $INPUT_MOVIE -map 0:0 -vcodec copy -map 0:1 -acodec copy $OUTPUT_MOVIE
/usr/bin/sleep 3
done
I've tried attaching the sleep but the processes seems to start to pile up. Is there a way to do them sequentially so that one video is processed after the other?
|
Would this work for your purposes?
for i in *.mkv; do ffmpeg -i "$i" … ;done
| bash script controlling ffmpeg to convert from mkv |
1,576,367,634,000 |
I'm using i3wm and I want a script to run after I've unlocked my
screen. I can get this to work when I manually lock my screen,
e.g. using the steps outlined in
this
post.
But I can't get this to work after my screen is automatically unlocked,
e.g. via xautolock. For example,
xautolock -time 5 -locker "blurlock -n && my_script.sh"
doesn't work – the screen locks after 5 minutes, but the script is not
run after unlock. In fact, it doesn't seem to be run at all.
Is there some way to get this to work? Maybe using xss-lock or
similar?
EDIT
Based on the suggestion by @aviro in the comments, I changed the script to read
#!/usr/bin/bash
echo "Hello" >> $HOME/temp.txt
blurlock -n
echo "Unlocked" >> $HOME/temp.txt
and then ran xautolock -time 1 -locker "my_script.sh &". The screen locked, and the file temp.txt contained both lines from the script. So it is possible to have a command run after unlocking when used in xautolock.
Part of what I want my script to do is to capture an image from a camera via ffmpeg. I changed my script to the following:
#!/usr/bin/bash
blurlock -n
ffmpeg -f video4linux2 -s vga -i /dev/video-cam $HOME/Pictures/test.jpg
notify-send -t 30000 'Unlocked'
This works when run manually -- the screen is locked, and after unlocking a notification pops up saying "Unlocked", and an image from the web-cam is written to the file as specified.
But when run via xautolock -locker "my_script.sh", after unlocking, there's no image capture or notification. Since I'm running xautolock from the terminal (and send it to the background with &), I get the following message
[1] + 581665 suspended (tty output) xautolock -time 1 -locker "my_script.sh"
Adding > /dev/null 2>&1 to the ffmpeg command doesn't help either.
|
After a lot of experimenting, I'm reasonably sure that using nohup before the ffmpeg command fixes the problem. That is, the above line in my_script.sh should be changed to:
nohup ffmpeg -f video4linux2 -s vga -i /dev/video-cam $HOME/Pictures/test.jpg > /dev/null 2>&1
| Use `xautolock` to run script which captures image with `ffmpeg` after unlocking |
1,576,367,634,000 |
I'm capturing an RTMP stream as HLS (saving playlist files) using FFMPEG wihout any stream processing, merely copying it.
Thanks to such setup I'm able to run tens of processes (I've tried 80 at most), with memory and CPU consumption not exceeding 30%.
This is my command:
ffmpeg -i <RTMP__STREAM_URL> -hls_init_time 10 -hls_time 10 -hls_list_size 0 -f hls -strftime 1 -hls_segment_filename '%H-%M-%S-%s.ts' -hls_flags split_by_time -codec:v copy -codec:a copy ./play$(date -d "today" +"%M%S-%s").m3u8
Unfortunately, as the number of processes grows, I start losing some HLS segments (HLS consists of a playlist file, and segments composing that file).
For example the HLS plays fine from 0:00 until 0:40, but then freezes at 0:40 for 10s (my segments are 10s long) and unfreezes at 0:50.
With 20 FFMPEG processes running, the loss rate is about 5%, at 80 processes its close to 50%.
I'm performing those benchmarks at AWS EC2 instances using Ubuntu 22.x, and various machine types. No matter the machine type, the error's frequency remains the same, thus I assume it's not CPU or Memory related.
I suspect that's something related to I/O and file writes, either an EC2 or Ubuntu setup.
Any ideas?
|
Solved.
Turns out that had nothing to do with resources or any sort of performance. The videos were freezing because the processes had been overwriting each other's segments.
Apparently timestamps with milliseconds precision were not unique enough. I've fixed it by adding a randomly generated value to each process, which then was used in the file names.
Ofc. the same would be achieved if I used a different directory for each process, etc.
Here's the command working perfectly even with 100 processes:
ffmpeg -i <RTMP_STREAM_URL> -hls_init_time 10 -hls_time 10 -hls_list_size 0 -f hls -strftime 1 -hls_segment_filename $(rand)'%H-%M-%S-%s.ts' -hls_flags split_by_time -codec:v copy -codec:a copy play_$(rand)_$(date -d "today" +"%M%S-%s").m3u8 </dev/null >/dev/null 2>&1 &
| Linux I/O issue? Multiple FFMPEG saving streams as HLS, lose segments despite low CPU and Memory consumption |
1,576,367,634,000 |
I installed the v4l2loopback kernel module on my machine and enabled it with sudo modprobe v4l2loopback exclusive_caps=1.
I created a camera on /dev/video0 with the rust bindings and started piping a static image to the camera (command from the wiki):
sudo ffmpeg -loop 1 -re -i 60828015.jpg -f v4l2 -vcodec rawvideo -pix_fmt yuv420p /dev/video0
I'm running this on a VPS with no desktop environment, so I quickly spun up a Docker container with noVNC and a desktop environment to test everything (sudo docker run --rm -it --device /dev/video0 --privileged -p 8090:8080 theasp/novnc). Everything looks fine and if i run ffplay /dev/video0, I can successfully view the image in the camera. The problem now is with other applications.
Cheese doesn't even detect the camera. Chromium detects the camera but cannot use it:
[15749:15755:1024/025614.520951:ERROR:v4l2_capture_delegate.cc(1138)] Dequeued v4l2 buffer contains invalid length (11441 bytes).
Not sure what I'm doing wrong and why Chromium cannot read from the camera.
kernel version: 5.4.0-164-generic
v4l2loopback version: commit 5bb9bed on the main branch (latest one right now)
module paramaters: exclusive_caps=1
FFmpeg pipe logs:
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, image2, from 'input.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 1854 kb/s
Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 360x287 [SAR 96:96 DAR 360:287], 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[swscaler @ 0x55b19c9fab80] deprecated pixel format used, make sure you did set range correctly
Output #0, video4linux2,v4l2, to '/dev/video0':
Metadata:
encoder : Lavf58.29.100
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 360x287 [SAR 1:1 DAR 360:287], q=2-31, 30996 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc58.54.100 rawvideo
frame= 2277 fps= 25 q=-0.0 size=N/A time=00:01:31.08 bitrate=N/A speed= 1x
|
From https://github.com/umlaeute/v4l2loopback/wiki/Faq
Depending on the color encoding, odd-sized frames can be problematic (eg YUV420p requires that the U and V planes are downsampled by a factor of 2, which works best if the width and height can be divided by 2). See also Issue #561
I changed the image size and the error disappeared.
| Chromium cannot read camera: Dequeued v4l2 buffer contains invalid length #561 |
1,688,329,302,000 |
Id like to create a video C with audio from video A but video from video B.
Video A and video B have nearly the same length in seconds.
Since the videos are a couple GBs, I guess it would be slower if I first extract audio from video A, then later merge that audio into video B (I mean, one step should be faster than two steps, right?). However, if this is the only way (extract audio, then merge), then I will do it.
Actually, video B was generated from video A and it took a 4 consecutive days of video processing to generate it (but lost the audio due to a mistake); that is why I am initially seeking a solution to do everything "at once".
|
I've been using this for a while:
ffmpeg -y \
-i "$videofile" \
-i "$audiofile" \
-c:v copy -c:a aac \
-map 0:v:0 -map 1:a:0 \
"$outfile"
I haven't tried it with files that are only "nearly" the same length, though.
| how to insert audio from video A into video B (no audio)? |
1,688,329,302,000 |
Resolve is a commercial video editor with a free version that can be run on linux.
On the linux version, some videos in mp4 format will have no video content when they are imported. This is apparently because the AAC codec is not supported by the free version Resolve on linux.
Apparently these videos can be transformed before being imported into Resolve, so that AAC support isn't required. Apparently ffmpeg is the correct tool for this job.
If I simply copy ffmpeg commands that I find on the web, I get errors that I do not understand. At present I'm trying this command:
ffmpeg -i video-to-transform.mp4 -c:v prores_ks -profile:v 3 -vendor
apl0 -bits_per_mb 8000 -pix_fmt yuv422p10le
outout.mp4
... I get the following error:
[mp4 @ 0x56120e725340] Could not find tag for codec prores in stream
#0, codec not currently supported in container Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
How can I make my mp4's editable in Resolve?
|
MPEG video files are not supported in free version of Davinci Resolve. You will have to convert to .mov file in order to use them.
The command you enter in your terminal is:
ffmpeg -i input.mp4 -c:v dnxhd -profile:v dnxhr_hq -pix_fmt yuv422p -c:a pcm_s16le -f mov output.mov
This is one solution. More solutions can be found here. This wiki can be helpful for other distros as well, not only for Arch or any Arch-based distribution. I used this solution in my Nobara Project distro (which is based on Fedora).
| How do transform mp4 videos so that they can be read by Davinci Resolve on Linux? |
1,688,329,302,000 |
I'm trying to record my screen, my mic, and my game audio with ffmpeg. This command records only my screen.
ffmpeg \
-video_size 2560x1440 \
-framerate 60 \
-f x11grab -i :0 \
-map 0 \
-c:a copy \
-c:v libx264rgb \
-crf 0 \
-preset ultrafast \
video.mkv
It records at a steady 60 fps, and ffmpeg gives the output
[x11grab @ 0x55717ef22dc0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0':
Duration: N/A, start: 1635606965.195981, bitrate: N/A
Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 2560x1440, 60 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264rgb))
Press [q] to stop, [?] for help
[libx264rgb @ 0x55717ef30a40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264rgb @ 0x55717ef30a40] profile High 4:4:4 Predictive, level 5.1, 4:4:4 8-bit
[libx264rgb @ 0x55717ef30a40] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to 'video.mkv':
Metadata:
encoder : Lavf58.29.100
Stream #0:0: Video: h264 (libx264rgb) (H264 / 0x34363248), bgr0, 2560x1440, q=-1--1, 60 fps, 1k tbn, 60 tbc
Metadata:
encoder : Lavc58.54.100 libx264rgb
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 174 fps= 60 q=-1.0 Lsize= 3866kB time=00:00:02.91 bitrate=10854.0kbits/s dup=0 drop=1 speed=1.01x
If I try to record my audio by adding inputs to the command:
ffmpeg \
-video_size 2560x1440 \
-framerate 60 \
-f x11grab -i :0 \
-f pulse -i "alsa_output.usb-DeSheng_Electronics_Inc._XIBERIA-00.iec958-stereo.>
-f pulse -i "alsa_input.usb-DeSheng_Electronics_Inc._XIBERIA-00.mono-fallback" \
-map 0 -map 1 -map 2 \
-c:a copy \
-c:v libx264rgb \
-crf 0 \
-preset ultrafast \
video.mkv
ffmpeg gives the output
[x11grab @ 0x55bf9b4e80c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0':
Duration: N/A, start: 1635606747.731781, bitrate: N/A
Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 2560x1440, 60 fps, 1000k tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, pulse, from 'alsa_output.usb-DeSheng_Electronics_Inc._XIBERIA-00.iec958-stereo.monitor':
Duration: N/A, start: 1635606747.770507, bitrate: 1536 kb/s
Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Guessed Channel Layout for Input Stream #2.0 : stereo
Input #2, pulse, from 'alsa_input.usb-DeSheng_Electronics_Inc._XIBERIA-00.mono-fallback':
Duration: N/A, start: 1635606747.811649, bitrate: 1536 kb/s
Stream #2:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264rgb))
Stream #1:0 -> #0:1 (copy)
Stream #2:0 -> #0:2 (copy)
Press [q] to stop, [?] for help
[libx264rgb @ 0x55bf9b519d80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264rgb @ 0x55bf9b519d80] profile High 4:4:4 Predictive, level 5.1, 4:4:4 8-bit
[libx264rgb @ 0x55bf9b519d80] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to 'video.mkv':
Metadata:
encoder : Lavf58.29.100
Stream #0:0: Video: h264 (libx264rgb) (H264 / 0x34363248), bgr0, 2560x1440, q=-1--1, 60 fps, 1k tbn, 60 tbc
Metadata:
encoder : Lavc58.54.100 libx264rgb
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Stream #0:2: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
[pulse @ 0x55bf9b4f4000] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[matroska @ 0x55bf9b518280] Non-monotonous DTS in output stream 0:1; previous: 364, current: 358; changing to 364. This may result in incorrect timestamps in the output file.
frame= 21 fps=0.0 q=0.0 size= 1kB time=00:00:01.01 bitrate= 7.7kbits/sframe= 21 fps= 21 q=0.0 size= 1kB time=00:00:01.01 bitrate= 7.7kbits/s
[matroska @ 0x55bf9b518280] Non-monotonous DTS in output stream 0:1; previous: 843, current: 838; changing to 843. This may result in incorrect timestamps in the output file.
[x11grab @ 0x55bf9b4e80c0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
and records at 20 fps while printing "Non-monotonous DTS" and "Thread message queue blocking" messages every few seconds. I'm assuming the audio is somehow slowing the video recording down, how do I fix it?
|
For anyone having this problem in the future, I fixed it by opening pavucontrol during recording.
| ffmpeg recording slows down when audio inputs are added |
1,688,329,302,000 |
ffmpeg -f x11grab -s 1920x1080 -i :0.0 -f alsa -i default -c:a aac -c:v libx264 -crf 18 -preset slower ~/Videos/recording-(date +%F-%I-%M).mp4
I'm using this command to record the screen and my intention is to record only the internal audio. But seems like the source is set to microphone. What will be correct command here?
|
Okay, after fiddling for an hour I found the solution.
At first I got pulseaudio output source by running pactl list short sources. Which showed me this list -
0 alsa_input.usb-046d_0825_3AC10B90-02.mono-fallback module-alsa-card.c s16le 1ch 48000Hz RUNNING
1 alsa_output.pci-0000_06_00.1.hdmi-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz RUNNING
2 alsa_output.pci-0000_06_00.6.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz RUNNING
3 ladspa_output.mbeq_1197.mbeq.monitor module-ladspa-sink.c float32le 2ch 44100Hz RUNNING
In my case the source is ladspa_output.mbeq_1197.mbeq.monitor.
Finally I ran this command selecting the output source -
ffmpeg -f x11grab -s 1920x1080 -i :0.0 -f pulse -i ladspa_output.mbeq_1197.mbeq.monitor -c:a ac3 -c:v libx265 -crf 22 -preset slower ~/Videos/Recording-$(date +%F-%I-%M-%N).mp4
Hope this helps.
| How do I record just the internal audio with ffmpeg? |
1,688,329,302,000 |
I'm trying to write a simple shell script that I can use in my file manager Dolphin to merge selected images to GIF.
The following don't work, and I can't figure out the reason:
OUTPUT="$(kdialog --title "Merge to GIF" --inputbox "Please enter new file name:").gif"
INPUT="$(echo ${@} | sed -e 's/^/"/' -e 's/$/"/' -e 's/ /" "/g')"
convert -delay 60 "$INPUT" "$OUTPUT"
|
I don't know why that one doesn't work, but this works:
OUTPUT="$(kdialog --title "Merge to GIF" --inputbox "Please enter new file name:").gif"
convert $(for i in "${@}"; do printf -- "-delay 60 %s " "$i"; done;) "$OUTPUT"
| Shell script to merge selected images to gif |
1,688,329,302,000 |
I've setup a webcam viewer that detects when a USB webcam is plugged in with a udev rule, then starts a systemd service that executes a script that starts an FFmpeg/FFplay webcam stream. I noticed when setting DISPLAY=:0 and XAUTHORITY=/home/pi/.Xauthority in the script before FFmpeg is started FFmpeg will run the stream very poorly (Pi Zero W < 1fps).
On the Pi Zero W I left this bit out and it runs great when a webcam is plugged in but on a Pi 4 4GB the webcam viewer never comes up unless these environment variables are set. The logs say XDG_RUNTIME_DIR not set in the environment. Why would the stream work fine on the Zero W without these variables and not work at all on the Pi 4? Better yet, why does FFmpeg run terribly when these variables are set?
On the Pi 4 setting these variables does not seem to affect FPS.
|
After updating to Raspberry Pi OS Bullseye this issue appears to be fixed most likely due to them consolidating the video driver across all hardware. Unfortunately performance on Pi Zero W is worse on Bullseye. Oh well.
| Setting DISPLAY=:0 and XAUTHORITY=/home/pi/.Xauthority causes FFmpeg to run poorly |
1,688,329,302,000 |
I want to do something similar to the one on this guide but in that case both inputs have the same fps, I want to sync two distinct framerate inputs, here a sample:
ffmpeg \
-f x11grab \
-video_size 1920x1080 \
-framerate 60 \
-i :0.0 \
-f v4l2 \
-video_size 320x240 \
-framerate 15 \
-i /dev/video0 \
-filter_complex '[0:v][1:v]overlay=10:(H-h)/2[o]' \
-map '[o]' \
-r 60 \
-vcodec libx264 \
-an \
-f mpegts \
udp://127.0.0.1:3333
Then to watch: vlc udp://@127.0.0.1:3333
In my case it awkwardly gives about 10 fps and seems to be freezing, though I expected 60 I believe it would be more likely to be 15 since it is the lowest one, who knows...
However if I remove the webcam input and the filter it gives the full 60 fps I wanted, as well as when I stream only the webcam it gives the 15 fps.
Based on this other guide I also tried the filter [1:v]fps=fps=60[wc];[0:v][wc]overlay=10:(H-h)/2[o] but with no success.
I expect the output fps to be 60 and the frames to be nicely distributed someway avoiding the freezing effect. How can I sync two different fps videos inputs with ffmpeg?
Evidences:
screen recording with webcam
screen recording without webcam it implies that the computer is capable to record the fullscreen in realtime.
logs - Stream with and without webcam
|
I still don't know exactly why, but the following worked:
ffmpeg \
-f x11grab \
-video_size 1920x1080 \
-framerate 60 \
-i :0.0 \
-f v4l2 \
-video_size 320x240 \
-framerate 15 \
-i /dev/video0 \
-filter_complex '[0:v]setpts=RTCTIME-RTCSTART[dt];[1:v]setpts=PTS-STARTPTS[wc];[dt][wc]overlay=10:(H-h)/2[o]' \
-map '[o]' \
-r 60 \
-vcodec libx264 \
-an \
-f mpegts \
udp://127.0.0.1:3333
Although the documentation said RTCTIME is deprecated, and most people use PTS-STARTPTS, it seems I forced the stream to be time based stead of a number sequence.
Edit:
With the following filter also works and I believe it is better suitable:
[0:v]setpts=N/FRAME_RATE/TB[dt];[1:v]setpts=N/FRAME_RATE/TB,fps=fps=60[wc];[dt][wc]overlay=10:(H-h)/2[o]
It insures the fixed framerate and also adjust the webcam to have the same one as expected on the output.
| How to sync different fps video inputs |
1,688,329,302,000 |
I'm trying to create a command for converting all audio files selected in vifm using ffmpeg. Here's what I've tried so far:
command opus ffmpeg -i %f -q 7 %f:s|flac|opus|
This has two problems, however.
First, it only works if only one file is selected. If, for example, two are selected, ffmpeg stops with the question, File 'foo.flac' already exists. Overwrite ? [y/N], where foo.flac is the second file.
Second, it only works if the extension of the original files is flac. (I used vifm's substitution macro for replacing flac with opus in the file name in the example.) I don't know how to include other extensions, too.
|
After hours of trial and error, I've managed to figure it out.
Write a bash script in a separate file, like ffmpeg-opus.sh:
#!/bin/bash
for file; do
ffmpeg -i "$file" -ab 128k "${file%.*}".opus
done
And create a command for it in vifmrc:
command opus ffmpeg-opus.sh %f
| Convert selected audio files in vifm using ffmpeg |
1,594,316,180,000 |
I am using Debian 9 with an older Radeon GPU (5450). I am interested in using the snap package of ffmpeg (which is version 4.1) because of some issues I may be able to fix with the newer snap instead of the Debian version (which is version 3.2.12-1~deb9u1). I have installed the snap package but receive the following error.
~$ ffmpeg
libGL error: unable to load driver: r600_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: r600
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error: GLXBadContext
Request Major code 155 (GLX)
Request Minor code 6 ()
Error Serial #49
Current Serial #48
The snap package does not work properly for me in Debian 9. For example, it does not detect my microphone. I will plan to report this bug, but I am curious if anyone has any ideas for a workaround.
|
My solution was to compile the newest version of ffmpeg. I use ffmpeg for screencasting, video compression, webcam recording, and film trimming. Therefore, it is likely you may need other options which you can see by running the following in your ffmpeg source folder:
./configure --help
Here were my options:
./configure --prefix=/usr/local --enable-libxcb-xfixes --enable-libxcb --enable-gpl --enable-nonfree --enable-libx264 --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libpulse
I first needed to install these dependencies:
sudo apt install libx264-dev libfdk-aac-dev libmp3lame-dev libopus-dev libpulse-dev libxcb1-dev libxcb-xfixes0-dev
I still have the Debian 9 ffmpeg version installed. I just did a symbolic link to my ~/bin with:
sudo ln -s /usr/local/bin/ffmpeg $HOME/bin/
With the symbolic link, the system will default to the latest version instead of the version in /usr/bin/ffmpeg.
| ffmpeg snap package error in Debian 9: libGL error: unable to load driver: r600_dri.so |
1,594,316,180,000 |
So I am using the following to convert all our videos in /home/vids to mp4 and output them in /home/vids2 but now I would like to add another video that plays before and after each video in /home/vids.
The video link is /home/intro/play.mp4 this video should be played before and after each of the videos in /home/vids. To clarify if /home/intro/play.mp4 is 10 seconds long and if a video in `/home/vids' is 30 seconds long then the finished video should be 50 seconds long after you combine them.
find /home/vids -type f -execdir ffmpeg -i '{}' -filter:v drawtext="fontfile=/root/FreeSans.ttf:text='TEXT EXAMPLE':[email protected]:fontsize=24:y=h-line_h-30:x=w/20*mod(t\,60)" -f mp4 -vcodec libx264 -preset fast -profile:v main -acodec aac -movflags +faststart '/home/vids2/{}.mp4' \;
|
If the videos are encoded using the same codecs you can utilize the concat operator.
If you have media files with exactly the same codec and codec parameters you can concatenate them as described in "Concatenation of files with same codecs". If you have media with different codecs you can concatenate them as described in "Concatenation of files with different codecs" below.
$ cat build_ffmpegs.bash
#!/bin/bash
intro=/home/intro/play.mp4
outro=/home/intro/play.mp4
cd /home/vid
for i in vid*; do
ffmpeg -f concat -safe 0 \
-i < <(printf "file '%s'\n" $intro $(readlink -f $i) $outro) \
-c copy /home/vid2/output_${i}
done
Running this will generate ffmpeg commands like so:
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid1.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid1.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid2.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid2.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid3.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid3.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid4.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid4.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid5.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid5.mp4
You should be able to adapt the ffmpeg commands to whatever other specifics you need from here.
References
https://trac.ffmpeg.org/wiki/Concatenate
| ffmpeg add video to the start and end of another |
1,594,316,180,000 |
No idea why this is happening it's the first time I see this error. There seems to be enough space left in ram and drive.
First vnc fails now if I don't run it with -noshm option. Second one that fails is my screen grab inside ffmpeg. How can I prevent this from happening and how to fix it? Do I need to fully restart the server?
[x11grab @ 0x558615a2b220] Cannot get 1126032 bytes of shared memory:
No space left on device. [x11grab @ 0x558615a2b220] Stream #0: not
enough frames to estimate rate; consider increasing probesize
total used free shared buff/cache
available
Mem: 3762 662 547 967 2553
1898
Swap: 0 0 0
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 377M 39M 338M 11% /run
/dev/xvda1 20G 5.3G 14G 28% /
tmpfs 1.9G 47M 1.8G 3% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 377M 32K 377M 1% /run/user/116
tmpfs 377M 4.0K 377M 1% /run/user/1000
Output of ipcs command: https://gist.github.com/cAstraea/a204591c838f95c95d863ea04709ffa7
|
The problem in huge count of SystemV Shared memory Segments. You need to delete it with ipcrm command. But before check nattch field, that shows number of programs that using this segment. For example:
Your fragment:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 0 root 644 80 2
0x00000000 32769 root 644 16384 2
0x00000000 2065989638 ubuntu 777 1128032 0
0x00000000 1363181575 ubuntu 777 1126032 0
You can safely delete last 2 segments:
ipcrm --shmem-key 2065989638
ipcrm --shmem-key 1363181575
| Programs started to fail suddenly with messages pertaining to shared memory |
1,594,316,180,000 |
I am attempting to batch download a number of videos using ffmpeg. A list of the site addresses and save names is stored in a text file in the following format.
"site",filename.mp4
The code that I have is looping through the file and attempting to download each line by line.
#!/bin/bash
while IFS=, read dl nm
do
echo $dl
echo $nm
/usr/bin/ffmpeg -loglevel error -protocol_whitelist file,http,https,tcp,tls,crypto -i $dl -c copy $nm
done < $1
The expected output is that on each loop ffmpeg would download the file indicated by each line and then proceed to the next iteration of the loop.
Instead, ffmpeg outputs the error message
"site": No such file or directory
When I run the same command directly in the terminal with the site name and save name directly inserted into the command, it works without any issue.
Looking at other posts seemingly related to this I have tried appending
< /dev/null
to the end of the ffmpeg call but it still has the same affect.
|
There's some issues with your script, in that you're using quotes in the file with download URLs/locations.
Namely, that when you have the file the way you do, $dl becomes "site" and$nm` remains as you'd expect.
In order to do this, you either need to change the file so that the site download locations don't have quotes, and then you need to set quotes around $dl in the script.
So you'd end up with this:
input file list:
site,foobar.baz
Script:
#!/bin/bash
while IFS=, read dl nm
do
echo $dl
echo $nm
/usr/bin/ffmpeg -loglevel error -protocol_whitelist file,http,https,tcp,tls,crypto -i "$dl" -c copy $nm
done < $1
You might also want to wrap $nm in quotes as well in case you have a filename that has spaces in it, but that's your decision or not.
| ffmpeg does not accept variable name read from file [closed] |
1,594,316,180,000 |
I basicly have this script:
#!/bin/bash
#Asks For filname and Word
echo 'Which word are you looking for?'
read word
echo 'What's the name of the file?'
read fileName
#Searches word and parses the line-numbers
wordOut=$(grep -i -n -w $word $fileName.srt |cut -f1 -d:)
#Sets all outputs to diffrent line numbers and saves a temp file
for word in $wordOut
do
echo $word
done >file.tmp
#Parses lines to array, removes temp file
mapfile -t arr <file.tmp
rm file.tmp
#Declares variable for the number of array entries (not used anywhere atm)
ln=${#arr[@]}
#Subtract all array entries with one
one=1
for i in "${arr[@]}"
do
crc=`expr $i - $one`
echo $crc
done >two.tmp
#Subtraction result to array2
mapfile -t arr2 <two.tmp
rm two.tmp
echo ${arr2[@]}
#retrieve times
for h in "${arr2[@]}"
do
line=$(sed "${h}q;d" $fileName.srt)
echo $line
done >three.tmp
#replace all commas with decimal points
sed 's/,/./g' three.tmp >four.tmp
#remove temp file 3 and parse 'decimal pointed' to array
rm three.tmp
mapfile -t arr3 <four.tmp
rm four.tmp
echo ${arr3[0]}
echo ${arr3[1]}
# converts HH:MM:SS.sss to fractional seconds
codes2seconds() (
local hh=${1%%:*}
local rest=${1#*:}
local mm=${rest%%:*}
local ss=${rest#*:}
printf "%s" $(bc <<< "$hh * 60 * 60 + $mm * 60 + $ss")
)
# converts fractional seconds to HH:MM:SS.sss
seconds2codes() (
local seconds=$1
local hh=$(bc <<< "scale=0; $seconds / 3600")
local remainder=$(bc <<< "$seconds % 3600")
local mm=$(bc <<< "scale=0; $remainder / 60")
local ss=$(bc <<< "$remainder % 60")
printf "%02d:%02d:%06.3f" "$hh" "$mm" "$ss"
)
subtracttimes() (
local t1sec=$(codes2seconds "$1")
local t2sec=$(codes2seconds "$2")
printf "%s" $(bc <<< "$t2sec - $t1sec")
)
for range in "${arr3[@]}"
do
mod=$(sed 's/[^0-9]//g' <<< $range)
duration=$(subtracttimes "${range%% -->*}" "${range##*--> }")
printf "%s\n" "ffmpeg -i $fileName.mp4 -ss ${range%% -->*} -t $duration -async 1 $word.$mod.$fileName.cut.mp4"
done >final.tmp
sudo chmod 755 final.tmp
./final.tmp
rm final.tmp
Which works perfectly fine. What it does: it searches the srt file, which has the same name has the mp4 file for a keyword, then finds the timestamp which matches this keyword, and cuts away the video from the starting point to the end point.
SRT file, for example:
**video.srt**
1
00:00:00,000 --> 00:00:04,950
welkom bij eerste toekomst reizen dus
2
00:00:02,639 --> 00:00:05,670
onderdeel aan de achterhoekse toekomst
3
00:00:04,950 --> 00:00:07,290
stoere
4
00:00:05,670 --> 00:00:11,250
mijn heren nu al heel veel dingen
So basically if you're looking for the keyword "toekomst", it will output two mp4's, one which originally started at 00:00:00,000 and ended at 00:00:04,950, and one which started at 00:00:02,639 and ended at 00:00:05,670.
I have multiple MP4's in the same directory, all with an corresponding .srt file with the same name as the mp4, which all need to be run through this script. So I want to build a script extensions which looks for all the files with the same names, and runs it through the script.
So I wrote this piece of code to test this:
#!/bin/bash
cd "`dirname "$0"`"
for file in *.srt
do
fileName="$( basename "$file" .srt)"
echo $fileName
echo $fileName.mp4
echo $fileName.srt
done >temp
and it indeed gives the output of all the .mp4 files and .srt files in the directory:
h
h.mp4
h.srt
r
r.mp4
r.srt
So then I build this for loop around the existing code as follows:
#!/bin/bash
cd "`dirname "$0"`"
#Asks For filname and Word
echo 'Which word are you looking for?'
read word
for file in *.srt
do
fileName="$( basename "$file" .srt)"
#Searches word and parses the line-numbers
wordOut=$(grep -i -n -w $word $fileName.srt |cut -f1 -d:)
#Sets all outputs to diffrent line numbers and saves a temp file
for word in $wordOut
do
echo $word
done >file.tmp
#Parses lines to array, removes temp file
mapfile -t arr <file.tmp
rm file.tmp
#Declares variable for the number of array entries (not used anywhere atm)
ln=${#arr[@]}
#Subtract all array entries with one
one=1
for i in "${arr[@]}"
do
crc=`expr $i - $one`
echo $crc
done >two.tmp
#Subtraction result to array2
mapfile -t arr2 <two.tmp
rm two.tmp
echo ${arr2[@]}
#retrieve times
for h in "${arr2[@]}"
do
line=$(sed "${h}q;d" $fileName.srt)
echo $line
done >three.tmp
#replace all commas with decimal points
sed 's/,/./g' three.tmp >four.tmp
#remove temp file 3 and parse 'decimal pointed' to array
rm three.tmp
mapfile -t arr3 <four.tmp
rm four.tmp
echo ${arr3[0]}
echo ${arr3[1]}
# converts HH:MM:SS.sss to fractional seconds
codes2seconds() (
local hh=${1%%:*}
local rest=${1#*:}
local mm=${rest%%:*}
local ss=${rest#*:}
printf "%s" $(bc <<< "$hh * 60 * 60 + $mm * 60 + $ss")
)
# converts fractional seconds to HH:MM:SS.sss
seconds2codes() (
local seconds=$1
local hh=$(bc <<< "scale=0; $seconds / 3600")
local remainder=$(bc <<< "$seconds % 3600")
local mm=$(bc <<< "scale=0; $remainder / 60")
local ss=$(bc <<< "$remainder % 60")
printf "%02d:%02d:%06.3f" "$hh" "$mm" "$ss"
)
subtracttimes() (
local t1sec=$(codes2seconds "$1")
local t2sec=$(codes2seconds "$2")
printf "%s" $(bc <<< "$t2sec - $t1sec")
)
for range in "${arr3[@]}"
do
mod=$(sed 's/[^0-9]//g' <<< $range)
duration=$(subtracttimes "${range%% -->*}" "${range##*--> }")
printf "%s\n" "ffmpeg -i $fileName.mp4 -ss ${range%% -->*} -t $duration -async 1 $word.$mod.$fileName.cut.mp4"
done >final.tmp
sudo chmod 755 final.tmp
./final.tmp
rm final.tmp
done
and for the first run, with the first file it gives the correct output mp4's but after that it shuffles the variables in some way that I can't get the proper output.
|
I've fixed it myself by using another script and exporting the variables to the main script, so in the end I've used these two scripts.
Main script:
#!/bin/bash
echo 'Welk woord zoek je?'
read word
export word
for file in *.srt
do
fileName="$( basename "$file" .srt)"
export fileName
./actualScript
done
Actual script:
#!/bin/bash
#Asks For filname and Word
#Searches word and parses the line-numbers
wordOut=$(grep -i -n -w $word $fileName.srt |cut -f1 -d:)
#Sets all outputs to diffrent line numbers and saves a temp file
for word in $wordOut
do
echo $word
done >file.tmp
#Parses lines to array, removes temp file
mapfile -t arr <file.tmp
rm file.tmp
#Declares variable for the number of array entries (not used anywhere atm)
ln=${#arr[@]}
#Subtract all array entries with one
one=1
for i in "${arr[@]}"
do
crc=`expr $i - $one`
echo $crc
done >two.tmp
#Subtraction result to array2
mapfile -t arr2 <two.tmp
rm two.tmp
echo ${arr2[@]}
#retrieve times
for h in "${arr2[@]}"
do
line=$(sed "${h}q;d" $fileName.srt)
echo $line
done >three.tmp
#replace all commas with decimal points
sed 's/,/./g' three.tmp >four.tmp
#remove temp file 3 and parse 'decimal pointed' to array
rm three.tmp
mapfile -t arr3 <four.tmp
rm four.tmp
echo ${arr3[0]}
echo ${arr3[1]}
# converts HH:MM:SS.sss to fractional seconds
codes2seconds() (
local hh=${1%%:*}
local rest=${1#*:}
local mm=${rest%%:*}
local ss=${rest#*:}
printf "%s" $(bc <<< "$hh * 60 * 60 + $mm * 60 + $ss")
)
# converts fractional seconds to HH:MM:SS.sss
seconds2codes() (
local seconds=$1
local hh=$(bc <<< "scale=0; $seconds / 3600")
local remainder=$(bc <<< "$seconds % 3600")
local mm=$(bc <<< "scale=0; $remainder / 60")
local ss=$(bc <<< "$remainder % 60")
printf "%02d:%02d:%06.3f" "$hh" "$mm" "$ss"
)
subtracttimes() (
local t1sec=$(codes2seconds "$1")
local t2sec=$(codes2seconds "$2")
printf "%s" $(bc <<< "$t2sec - $t1sec")
)
for range in "${arr3[@]}"
do
mod=$(sed 's/[^0-9]//g' <<< $range)
duration=$(subtracttimes "${range%% -->*}" "${range##*--> }")
printf "%s\n" "ffmpeg -i $fileName.mp4 -ss ${range%% -->*} -t $duration -async 1 $word.$mod.$fileName.cut.mp4"
done >final.tmp
sudo chmod 755 final.tmp
./final.tmp
rm final.tmp
| Building a for loop around exsisting loop, to replace user input |
1,594,316,180,000 |
I am successfully capturing frames from a small USB IR camera on the small Raspberry Pi Linux board. I am using the 'libseek' code to do this:
https://github.com/zougloub/libseek
I can see alot of garbage being printed on the terminal when I remove the '|' symbol from the following command:
sudo ./build/seek-test \
| ffplay -i - -f rawvideo -video_size 208x156 -pixel_format gray16le
If I startx I can see frames displayed in a window.
The problem is I don't want to have X started ( or even installed ) on the Pi. I have a small Adafruit TFT touchscreen that shows the console on /dev/fb1. I can use fbi to show images on that display.
What can I use instead of ffplay to show the raw video feed on /dev/fb1 without X? Thanks!
|
I would suggest to do something with gstreamer, like /build/seek-test | gst-launch-1.0 fbsrc ! videoparse width=208 height=156 format=gray16-le ! fbdevsink. Note that I didn't test it.
| Alternative to ffplay for Raw Video Playback without X Windows |
1,594,316,180,000 |
I want to create a movie from a bunch of png's by using the command:
avconv -i pics/*.png out.mp4
or
ffmpeg -r 1/1 -start_number 1 -i pics/*.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
However, in both cases I get:
Error while opening encoder for output stream #18:0 - maybe incorrect parameters such as bit_rate, rate, width or height
The complete log message for the second command is:
ffmpeg version 1.0.10 Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 25 2014 07:50:40 with gcc 4.7 (Debian 4.7.2-5)
configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ' --extra-ldflags='Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libfdk-aac --enable-libdc1394 --disable-altivec --dis libavutil 51. 73.101 / 51. 73.101
libavcodec 54. 59.100 / 54. 59.100
libavformat 54. 29.104 / 54. 29.104
libavdevice 54. 2.101 / 54. 2.101
libavfilter 3. 17.100 / 3. 17.100
libswscale 2. 1.101 / 2. 1.101
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100
Input #0, image2, from 'pics/1.png':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgba, 594x557, 25 tbr, 25 tbn, 25 tbc
File 'output.mp4' already exists. Overwrite ? [y/N] y
height not divisible by 2 (594x557)
Output #0, image2, to 'pics/10.png':
Stream #0:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #1, image2, to 'pics/11.png':
Stream #1:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #2, image2, to 'pics/12.png':
Stream #2:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #3, image2, to 'pics/13.png':
Stream #3:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #4, image2, to 'pics/14.png':
Stream #4:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #5, image2, to 'pics/15.png':
Stream #5:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #6, image2, to 'pics/16.png':
Stream #6:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #7, image2, to 'pics/17.png':
Stream #7:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #8, image2, to 'pics/18.png':
Stream #8:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #9, image2, to 'pics/19.png':
Stream #9:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #10, image2, to 'pics/2.png':
Stream #10:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #11, image2, to 'pics/3.png':
Stream #11:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #12, image2, to 'pics/4.png':
Stream #12:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #13, image2, to 'pics/5.png':
Stream #13:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #14, image2, to 'pics/6.png':
Stream #14:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #15, image2, to 'pics/7.png':
Stream #15:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #16, image2, to 'pics/8.png':
Stream #16:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #17, image2, to 'pics/9.png':
Stream #17:0: Video: png, rgba, 594x557, q=2-31, 200 kb/s, 90k tbn, 1 tbc
Output #18, mp4, to 'output.mp4':
Stream #18:0: Video: h264, yuv420p, 594x557, q=-1--1, 90k tbn, 30 tbc
Stream mapping:
Stream #0:0 -> #0:0 (png -> png)
Stream #0:0 -> #1:0 (png -> png)
Stream #0:0 -> #2:0 (png -> png)
Stream #0:0 -> #3:0 (png -> png)
Stream #0:0 -> #4:0 (png -> png)
Stream #0:0 -> #5:0 (png -> png)
Stream #0:0 -> #6:0 (png -> png)
Stream #0:0 -> #7:0 (png -> png)
Stream #0:0 -> #8:0 (png -> png)
Stream #0:0 -> #9:0 (png -> png)
Stream #0:0 -> #10:0 (png -> png)
Stream #0:0 -> #11:0 (png -> png)
Stream #0:0 -> #12:0 (png -> png)
Stream #0:0 -> #13:0 (png -> png)
Stream #0:0 -> #14:0 (png -> png)
Stream #0:0 -> #15:0 (png -> png)
Stream #0:0 -> #16:0 (png -> png)
Stream #0:0 -> #17:0 (png -> png)
Stream #0:0 -> #18:0 (png -> libx264)
Error while opening encoder for output stream #18:0 - maybe incorrect parameters such as bit_rate, rate, width or height
How can I make this work?
|
The text with asterisk needs the sequential digit indicator %d instead, I think:
avconv -i 'pics/%d.png' out.mp4
ffmpeg -r 1/1 -start_number 1 -i 'pics/%d.png' -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
quoting from avconv man page:
The pattern may contain the string "%d" or "%0Nd", which specifies the position of the characters representing a
sequential number in each filename matched by the pattern. If the form "%d0Nd" is used, the string representing
the number in each filename is 0-padded and N is the total number of 0-padded digits representing the number.
The literal character '%' can be specified in the pattern with the string "%%".
If the pattern contains "%d" or "%0Nd", the first filename of the file list specified by the pattern must
contain a number inclusively contained between 0 and 4, all the following numbers must be sequential. This
limitation may be hopefully fixed.
The pattern may contain a suffix which is used to automatically determine the format of the images contained in
the files.
For example the pattern "img-%03d.bmp" will match a sequence of filenames of the form img-001.bmp, img-002.bmp,
..., img-010.bmp, etc.; the pattern "i%%m%%g-%d.jpg" will match a sequence of filenames of the form i%m%g-1.jpg,
i%m%g-2.jpg, ..., i%m%g-10.jpg, etc.
The size, the pixel format, and the format of each image must be the same for all the files in the sequence.
The following example shows how to use avconv for creating a video from the images in the file sequence
img-001.jpeg, img-002.jpeg, ..., assuming an input framerate of 10 frames per second:
avconv -i 'img-%03d.jpeg' -r 10 out.mkv
| Error while making movie from png's with avconv or ffmpeg |
1,339,486,512,000 |
Since today when I run ffmpeg I have the error in the title of this question.
I tried this, but can't apply the solution because I have a directory /etc/ld.so.conf.d and in that directory there are the following files:
fakeroot-x86_64-linux-gnu.conf i386-linux-gnu.conf libc.conf x86_64-linux-gnu.conf
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
|
If you're encountering an error with ffmpeg that suggests a library issue and you've noted the presence of various .conf files in /etc/ld.so.conf.d, it sounds like there might be a mismatch or a missing path in your library configuration. Given that you have Ubuntu 22.04.4 LTS, here's a streamlined approach to troubleshoot and potentially solve your problem:
First, ensure that ffmpeg is correctly installed and try to identify which version you're running. If you installed it from Ubuntu's repositories, it should be configured correctly, but if it's a custom build or from a third-party repository, you might need to ensure it's compatible with your system.
then run ffmpeg from the terminal and pay close attention to any error messages regarding missing libraries. The specific name of the missing file can give a clue on what to fix.
Since the system might not be aware of the location of some newly installed libraries, update the linker run-time bindings with:
sudo ldconfig
The above command I gave updates the cache of the dynamic linker to include paths to all known libraries in the directories listed in /etc/ld.so.conf and its included files in /etc/ld.so.conf.d/.
Also
If ffmpeg is complaining about a library that you know is installed, make sure the path to this library is included in the linker configuration. You can add a new .conf file in /etc/ld.so.conf.d/ that contains the path to the directory where the missing library resides. For example, if your library is in /usr/local/lib, you can do:
echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/mycustomlib.conf
sudo ldconfig
Please always replace /usr/local/lib with the actual path where the problematic library is located.
If the issue persists, consider reinstalling ffmpeg to ensure it's properly set up:
sudo apt-get update
sudo apt-get install --reinstall ffmpeg
This can help resolve any corrupt installations or incorrect configurations.
| ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: Error 74 |
1,339,486,512,000 |
So I have been trying filter out H265/HEVC and only show videos that are not the previous codec and then execute a command that I have that will transcode the video using my settings.
Every time I find a solution or a way I may manipulate into how I want it done, it doesn't work. Either an error of some kind or where it's outdated and that's not how it is done now.
But it should be something like this:
find /mnt/videos -type f *.mp4 exec $filtercmd; $transcodecmd
The command should only print the file's absolute path, that way I can have it be used by the second command so that it can be transcoded.
I would prefer using ffprobe as it seems to be a cleaner method. And I hate to basically ask someone write up a command or script but I just don't have the knowledge for something like this. Also it would be nice if this was written with the purpose of being on a schedule.
Thanks in advance!
EDIT:
I think I may have found a solution.
#!/bin/bash
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
# Bold
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
for i in $(find /mnt/movies/ -type f -name '*.mkv' -o -name '*.mp4' -o -name '*.wmv' -o -name '*.flv' -o -name '*.webm' -o -name '*.mov'); do
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "${i}"
if [[ $1 == 'h264' ]]; then
echo "Video is a ${BGreen}H264${Color_off} video file"
python sickbeard_mp4_automator/manual.py -i "$i" -a
elif [[ $1 == hevc ]]; then
echo "Video is alread transcoded to ${BRed}HEVC${Color_Off}"
fi
done
But it seems to be escaping the spaces. Can't seem to get it to quit. What do you guys think?
|
I found the answer!
#!/bin/bash
IFS=$'\n'
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
# Bold
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
for i in $(find /mnt/movies/ -type f -name '*.mkv' -o -name '*.mp4' -o -name '*.wmv' -o -name '*.flv' -o -name '*.webm' -o -name '*.mov'); do
# ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$i"
if [ $(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$i") = h264 ]; then
echo -e "Video is a ${BGreen}H264${Color_Off} video file"
python2 sickbeard_mp4_automator/manual.py -i "$i" -a
elif [ $(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$i") == hevc ]; then
echo -e "Video is already transcoded to ${BRed}HEVC${Color_Off}"
elif [ $(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$i") == vp8 ]; then
echo -e "Video is a ${BGreen}WEBM${Color_Off} video file"
python2 sickbeard_mp4_automator/manual.py -i "$i" -a
fi
done
This will check for H264 and will transcode the file. Otherwise it leaves it alone. Thanks guys for the help and realized that I can be an idiot sometimes. :)
| How to sort videos by codec and execute a command |
1,339,486,512,000 |
I have a video that I recorded with an interface using an XLR microphone (mono). The video recording software (Simple Screen Recorder), and my PulseAudio all saw that as a stereo source. Now I have a video with a stereo stream but only one audio channel. How can I correct this so sound plays from both speakers? Currently sound only plays from the left speaker.
|
One method to correct this is to use ffmpeg, using -c:v copy to leave the video screen alone and -map_channel to mark the new video as being stereo.
ffmpeg -i /tmp/in.mkv -map_channel 0.1.0 -c:v copy /tmp/out.mkv
| How can I reencode a video's audio when it was recorded in stereo with a mono source? |
1,339,486,512,000 |
I run
cmake -D CMAKE_BUILD_TYPE=RELEASE ..
to configure opencv
and here are some of the check result
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: NO
-- FFMPEG: NO
-- avcodec: YES (ver 57.64.101)
-- avformat: YES (ver 57.56.100)
-- avutil: YES (ver 55.34.100)
-- swscale: YES (ver 4.2.100)
-- avresample: NO
-- GStreamer: NO
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- OpenNI2: NO
to confirm I do have ffmpeg installed I run
ffmpeg
and the result shows
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8.2 (GCC)
configuration: --enable-shared --enable-gpl --enable-libx264 --enable- libxvid --enable-pic --enable-ffplay --extra-cflags='-I/usr/include/SDL:/usr /local/include/SDL2' --extra-ldflags=-L/usr/local/lib64 --extra-libs=-lSDL
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
So I do have ffmpeg installed,then why cmake won't recongnise it?What is missing?
|
I happen to be reinstalling my OpenCV recently and here are the steps to configure ffmepg.
1.Download the yum repository here to ~/Desktop
https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
2.Install the repository
sudo rpm -i ~/Desktop/rpmfusion-free-release-7.noarch.rpm
3.Install FFMPEG
sudo yum -install ffmpeg.x86_64 ffmpeg-devel.x86_64 ffmpeg-libs.x86_64
4.Edit common.h file
sudo gedit /usr/include/ffmpeg/common.h
Insert the following code at line:28
#ifndef UINT64_C
#define UINT64_C(value) __CONCAT(value, ULL)
#endif
And It is done
| How do I make FFMPEG check yes while installing OPENCV |
1,339,486,512,000 |
how to convert video into webm format using ffmpeg and libvpx in centos
I have install ffmpeg and libvpx in centos.but it's doesn't convert mp4 format into webm format. but in windows i have check, it's working fine. what's wrong with my code / installation.how to find that.The code below,
FFMPEG path
/usr/bin/ffmpeg
Convert Code
$cmd1= "$ffmpeg -i $video -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis $webmpath";
$cmdstr = $cmd1;
$locale = 'en_IN.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL='.$locale);
exec($cmd1);
console output while run ffmpeg command
root@ip-104-238-95-12 [~]# ffmpeg
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.19. 0 / 1.19. 0
libswscale 0.11. 0 / 0.11. 0
libpostproc 51. 2. 0 / 51. 2. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
root@ip-104-238-95-12 [~]#
|
The ffmpeg version packaged in CentOS is too old to understand some of the options provided.
I'd suggest you to download a more recent version.
The easy way is to download the latest static build for your platform, you can find it here: http://johnvansickle.com/ffmpeg/ (choose 32 or 64 bit depending on your arch).
For instance:
$ cd /opt/
$ wget http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz
$ tar xvf ffmpeg-release-64bit-static.tar.xz
$ ln -s /opt/ffmpeg-2.6.3-64bit-static /opt/ffmpeg
And use /opt/ffmpeg/ffmpeg rather than /usr/bin/ffmpeg.
| how to convert video into webm format using ffmpeg in centos |
1,339,486,512,000 |
As I had to install my system from scratch I decided to play it safe this time around and follow the documentation for compiling ffmpeg on Centos via the ffmpeg.org site. I followed every command line by line without any errors until the very final one which was to do with the bash_profile.
If I look for ffmpeg on my system it just keeps saying command not found?
I don't understand why the documentation installs everything in ~/ when I thought it needs to be in /usr/bin.
I don't understand why the documentation doesn't include ldconfig command or any kind of instructions on setting the path and executing the software.
update: I decided to undo what I had done because couldn't work out file paths and instead I downloaded and installed ffmpeg with rpmforge and yum and finally it is all working. I literally began learning terminal last year and it has been a very steep learning curve for me so what may seem very obvious to some eg file paths for setting up ffmpeg is not for me. Hence my great confusion.
|
Based on your previous question, it seems that you followed the instructions too literally. I don't know which part exactly you should focus on (since I installed my ffmpeg manually instead of make install), but one of the arguments to ./configure needs to reflect the proper destination of the program (in your case, I think that means change $HOME/... to /usr/bin/... This will then be used by make install to move the file.
If you don't want to repeat the configuration and install processes, you might be able to modify the install target of the makefile directly (if you still have it).
| ffmpeg not found [closed] |
1,339,486,512,000 |
I'm trying to use Ubuntu Linux 19.04 to convert an OpenShot video into a more efficient file-size.
The video only contains two still images, and 20 minutes of audio, but for each file-type I save-as, the output-file is larger than 600MB.
Apparently I'm choosing the wrong lossless output file-type; you'd think a video like this would only be 10MB, since almost all the frames, in the entire video, are one of two frames.
Using ffmpeg, how can I convert this video to a format that understands how to compress all the duplicate frames efficiently?
|
Your question is answered in the ffmpeg examples. You can use something like this:
ffmpeg -loop 1 -framerate 1 -i banner.png -i audio.wav -map 0 -map 1 -c:v libx264 -crf 16 -c:a aac -b:a 92k -shortest -movflags +faststart ready_to_upload.mp4
Detailed explanation:
-loop 1 repeat image potentially forever
-framerate 1 have a low frame-rate
-i banner.png -i audio.wav input image and audio
-map 0 -map 1 use both stream
-c:v libx264 -crf 16 have high-quality image
-c:a libfdk_aac -b:a 92k have high-quality
-shortest stop repeating banner image when audio is finished
-movflags +faststart include index at beginning of MP4 container for early start
It compresses to approximately 1 MB per minute.
Note: YouTube is likely (but not guaranteed) to re-encode your video. Image quality will degrade.
| Using ffmpeg to Compressed a Two Frame Video |
1,387,878,201,000 |
If I'm logged in to a system via SSH, is there a way to copy a file back to my local system without firing up another terminal or screen session and doing scp or something similar or without doing SSH from the remote system back to the local system?
|
Master connection
It's easiest if you plan in advance.
Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.
So while you have your active connection, you can quickly:
copy a file with scp or rsync;
mount a remote filesystem with sshfs.
Forwarding
On an existing connection, you can establish a reverse ssh tunnel. On the ssh command line, create a remote forwarding by passing -R 22042:localhost:22 where 22042 is a randomly chosen number that's different from any other port number on the remote machine. Then ssh -p 22042 localhost on the remote machine connects you back to the source machine; you can use scp -P 22042 foo localhost: to copy files.
You can automate this further with RemoteForward 22042 localhost:22. The problem with this is that if you connect to the same computer with multiple instances of ssh, or if someone else is using the port, you don't get the forwarding.
If you haven't enabled a remote forwarding from the start, you can do it on an existing ssh session. Type Enter ~C Enter -R 22042:localhost:22 Enter.
See “Escape characters” in the manual for more information.
There is also some interesting information in this Server Fault thread.
Copy-paste
If the file is small, you can type it out and copy-paste from the terminal output. If the file contains non-printable characters, use an encoding such as base64.
remote.example.net$ base64 <myfile
(copy the output)
local.example.net$ base64 -d >myfile
(paste the clipboard contents)
Ctrl+D
More conveniently, if you have X forwarding active, copy the file on the remote machine and paste it locally. You can pipe data in and out of xclip or xsel. If you want to preserve the file name and metadata, copy-paste an archive.
remote.example.net$ tar -czf - myfile | xsel
local.example.net$ xsel | tar -xzf -
| Copy a file back to local system with ssh |
1,387,878,201,000 |
I have two directories images and images2 with this structure in Linux:
/images/ad
/images/fe
/images/foo
... and other 4000 folders
and the other is like:
/images2/ad
/images2/fe
/images2/foo
... and other 4000 folders
Each of these folders contain images and the directories' names under images and images2 are exactly the same, however their content is different. Then I want to know how I can copy-merge the images of /images2/ad into images/ad, the images of /images2/foo into images/foo and so on with all the 4000 folders..
|
This is a job for rsync. There's no benefit to doing this manually with a shell loop unless you want to move the file rather than copy them.
rsync -a /path/to/source/ /path/to/destination
In your case:
rsync -a /images2/ /images/
(Note trailing slash on images2, otherwise it would copy to /images/images2.)
If images with the same name exist in both directories, the command above will overwrite /images/SOMEPATH/SOMEFILE with /images2/SOMEPATH/SOMEFILE. If you want to replace only older files, add the option -u. If you want to always keep the version in /images, add the option --ignore-existing.
If you want to move the files from /images2, with rsync, you can pass the option --remove-source-files. Then rsync copies all the files in turn, and removes each file when it's done. This is a lot slower than moving if the source and destination directories are on the same filesystem.
| How to copy-merge two directories? |
1,387,878,201,000 |
Having migrated to Linux from Windows, I would like to find an alternative software to Winmerge or rather learn command line tools to compare and sync two folders on Linux. I would be grateful if you could tell me how to do the following tasks on the command line... (I have studied diff and rsync, but I still need some help.)
We have two folders: "/home/user/A" and "/home/user/B"
Folder A is the place where regular files and folders are saved and folder B is a backup folder that serves as a complete mirror of folder A. (Nothing is directly saved or modified by the user in folder B.)
My questions are:
How to list files that exist only in folder B? (E.g. the ones deleted from folder A since the last synchronization.)
How to copy files that exist in only folder B back into folder A?
How to list files that exist in both folders but have different timestamps or sizes? (The ones that have been modified in folder A since last synronization. I would like to avoid using checksums, because there are tens of thousands of files and it'd make the process too slow.)
How to make an exact copy of folder A into folder B? I mean, copy everything from folder A into folder B that exists only in folder A and delete everything from folder B that exists only in folder B, but without touching the files that are the same in both folders.
|
This puts folder A into folder B:
rsync -avu --delete "/home/user/A" "/home/user/B"
If you want the contents of folders A and B to be the same, put /home/user/A/ (with the slash) as the source. This takes not the folder A but all of its content and puts it into folder B. Like this:
rsync -avu --delete "/home/user/A/" "/home/user/B"
-a archive mode; equals -rlptgoD (no -H, -A, -X)
-v run verbosely
-u only copy files with a newer modification time (or size difference if the times are equal)
--delete delete the files in target folder that do not exist in the source
Manpage: https://download.samba.org/pub/rsync/rsync.html
| How to sync two folders with command line tools? |
1,387,878,201,000 |
I've seen in many places used install -d to create directories and install -c to copy a file. Why not use mkdir and cp? Is there an advantage in using install?
|
It depends on what you're doing.
The install command is normally used in installation scripts that come with packages and source code for installing a binary to your system. It can also be used to install any other file or directory. In addition to the -d and -c options you have -m for specifying the new permissions of the file to be installed, so you don't have to do a cp and a chmod to get the same result. For instance:
install -m644 "$srcdir/$pkgname-$pkgver-linux64" "$pkgdir/opt/$pkgname"
You also have options -g and -o for setting the target group and owner, respectively. This avoids separate calls to chown. In general, using install shortens your script and makes it more concise by doing file creation, copying, mode setting and related stuff in one command instead of many.
For reference, see man install. For usage, just take a look at any installation script shipped with some package source code.
| Why use install rather than cp and mkdir? |
1,387,878,201,000 |
On occasion I've seen comments online along the lines of "make sure you set 'bs=' because the default value will take too long," and my own extremely-unscientific experiences of, "well that seemed to take longer than that other time last week" seem to bear that out. So whenever I use 'dd' (typically in the 1-2GB range) I make sure to specify the bytes parameter. About half the time I use the value specified in whatever online guide I'm copying from; the rest of the time I'll pick some number that makes sense from the 'fdisk -l' listing for what I assume is the slower media (e.g. the SD card I'm writing to).
For a given situation (media type, bus sizes, or whatever else matters), is there a way to determine a "best" value? Is it easy to determine? If not, is there an easy way to get 90-95% of the way there? Or is "just pick something bigger than 512" even the correct answer?
I've thought of trying the experiment myself, but (in addition to being a lot of work) I'm not sure what factors impact the answer, so I don't know how to design a good experiment.
|
dd dates from back when it was needed to translate old IBM mainframe tapes, and the block size had to match the one used to write the tape or data blocks would be skipped or truncated. (9-track tapes were finicky. Be glad they're long dead.) These days, the block size should be a multiple of the device sector size (usually 4KB, but on very recent disks may be much larger and on very small thumb drives may be smaller, but 4KB is a reasonable middle ground regardless) and the larger the better for performance. I often use 1MB block sizes with hard drives. (We have a lot more memory to throw around these days too.)
| Is there a way to determine the optimal value for the bs parameter to dd? |
1,387,878,201,000 |
I have a really strange situation here. My PC works fine, at least in most cases, but there's one thing that I can't deal with. When I try to copy a file from my pendrive, everything is ok -- I got 16-19M/s , it works pretty well. But when I try to copy something to the same pendrive, my PC freezes. The mouse pointer stops moving for a sec or two, then it moves a little bit and it stops again. When something is playing, for example, in Amarok, the sound acts like a machine gun. The speed jumps from 500K/s to 15M/s, average 8M/s. This occurs only when I'm copying something to a pendrive. When the process of copying is done, everything backs to normal.
I tried everything -- other pendrive, a different USB port on front panel or those ports from back, I even changed the USB pins on motherboard (front panel), but no matter where I put my USB stick, it's always the same. I tried different filesystem -- fat32, ext4. I have no problem with the device on Windows, on my laptop. It has to be my PC or something in my system. I have no idea what to look for. I'm using Debian testing with standalone Openbox. My PC is kind of old -- Pentium D 3GHz, 1GiB of RAM, 1,5TB WD Green disk. If you have something that would help me to solve this issue, I'd be glad to hear that.
I don't know what else info I should provide, but if you need something, just ask, I'll update this post as soon as possible.
I tried to reproduce this problem on ubuntu 13.04 live cd. I mounted my encrypted partition + encrypted swap and connected my pendrive to a usb port. Next I tried to start some apps, and now I have ~820MiB in RAM and about 400MiB in SWAP. There's no problem with copying, no freezing at all, everything is as it should be. So, it looks like it's a fault of the system, but where exactly? What would cause such a weird behavior?
|
Are you using a 64-bit version of Linux with a lot of memory? In that case the problem could be that Linux can lock for minutes on big writes on slow devices like for
example SD cards or USB sticks. It's a known bug that should be fixed in newer kernels.
See http://lwn.net/Articles/572911/
Workaround: as root issue:
echo $((16*1024*1024)) > /proc/sys/vm/dirty_background_bytes
echo $((48*1024*1024)) > /proc/sys/vm/dirty_bytes
I have added it to my /etc/rc.local file in my 64bit machines.
TANSTAAFL; this change can (and probably will) reduce your throughput to these devices --- it's a compromise between latency and speed. To get back to the previous behavior you can
echo 0 > /proc/sys/vm/dirty_background_bytes
echo 0 > /proc/sys/vm/dirty_bytes
...which are the default values, meaning that the writeback behavior will be controlled by the parameters dirty_ratio and dirty_background_ratio.
Note for the not-so-expert-with-linux people: the files in /proc are pseudofiles --- just communication channels between the kernel and user space. Never use an editor to change or look at them; get instead a shell prompt --- for example, with sudo -i (Ubuntu flavors) or su root and use echo and cat).
Update 2016/04/18 it seems that, after all, the problem is still here. You can look at it at LWN.net, in this article about writeback queues.
| Why is my PC freezing while I'm copying a file to a pendrive? |
1,387,878,201,000 |
I am a graduate student, and the group in which I work maintains a Linux cluster. Each node of the cluster has its own local disk, but these local disks are relatively small and are not equipped with automatic backup. So the group owns a fileserver with many TBs of storage space. I am a relative Linux novice, so I am not sure what are the specs of the fileserver in terms of speed, networking ability, etc. I do know from experience that the local disks are significantly faster than the fileserver in terms of I/O. About a dozen or so people use the fileserver.
Using cp to copy a ~20 GB file from the fileserver to one of the local disks takes about 11.5 minutes in real time on average (according to time). I know that this cp operation is not very efficient because (1) time tells me that the system time for such a copy is only ~45 seconds; and because (2) when I examine top during the copy, %CPU is quite low (by inspection, roughly 0-10% on average).
Using cp to copy the same ~20 GB file from one folder on the local disk to another folder on the same local disk takes less time -- about 9 minutes in real time (~51 seconds in system time, according to time). So apparently the fileserver is somewhat slower than the local disk, as expected, but perhaps not significantly slower. I am surprised that copying from local to same local is not faster than 9 minutes.
I need to copy ~200 large files -- each ~20 GB -- from the fileserver to one of the local disks. So, my question is: Is there a faster alternative to cp for copying large files in Linux? (Or are there any flags within cp that I could use which would speed up copying?) Even if I could somehow shave a minute off this copying time, that would help immensely.
I am sure that buying new, faster hardware disks, but I don't have access to such resources. I am also not a system administrator -- I am only a (novice) user -- so I don't have access to more detailed information on the load that is on the disks. I do know that while about a dozen people use the fileserver daily, I am the only person using this particular node/local disk.
|
%CPU should be low during a copy. The CPU tells the disk controller "grab data from sectors X–Y into memory buffer at Z". Then it goes and does something else (or sleep, if there is nothing else). The hardware triggers an interrupt when the data is in memory. Then the CPU has to copy it a few times, and tells the network card "transmit packets at memory locations A, B, and C". Then it goes back to doing something else.
You're pushing ~240mbps. On a gigabit LAN, you ought to be able to do at least 800mbps, but:
That's shared among everyone using the file server (and possibly a connection between switches, etc.)
That's limited by the speed the file server can handle the write, keeping in mind its disk I/O bandwidth is shared by everyone using it.
You didn't specify how you're accessing the file server (NFS, CIFS (Samba), AFS, etc.). You may need to tune your network mount, but on anything half-recent the defaults are usually pretty sane.
For tracking down the bottleneck, iostat -kx 10 is going to be a useful command. It'll show you the utilization on your local hard disks. If you can run that on the file server, it'll tell you how busy the file server is.
The general solution is going to be to speed up that bottleneck, which of course you don't have the budget for. But, there are a couple of special cases where you can find a faster approach:
If the files are compressible, and you have a fast CPU, doing a minimal compress on-the-fly might be quicker. Something like lzop or maybe gzip --fastest.
If you are only changing a few bits here and there, and then sending the file back, only sending deltas will be much faster. Unfortunately, rsync won't really help here, as it will need to read the file on both sides to find the delta. Instead, you need something that keeps track of the delta as you change the file... Most approaches here are app-specific. But its possible that you could rig something up with, e.g., device-mapper (see the brand new dm-era target) or btrfs.
If you're copying the same data to multiple machines, you can use something like udpcast to send it to all the machines at once.
And, since you note you're not the sysadmin, I'm guessing that means you have a sysadmin. Or at least someone responsible for the file server & network. You should probably ask him/her/them, they should be much more familiar with the specifics of your setup. Your sysadmin(s) should at least be able to tell you what transfer rate you can reasonably expect.
| Is there a faster alternative to cp for copying large files (~20 GB)? |
1,387,878,201,000 |
I try to duplicate a video file x times from the command line by using a for loop, I've tried it like this, but it does not work:
for i in {1..100}; do cp test.ogg echo "test$1.ogg"; done
|
Your shell code has two issues:
The echo should not be there.
The variable $i ("dollar i") is mistyped as $1 ("dollar one") in the destination file name.
To make a copy of a file in the same directory as the file itself, use
cp thefile thecopy
If you use more than two arguments, e.g.
cp thefile theotherthing thecopy
then it is assumed that you'd like to copy thefile and theotherthing into the directory called thecopy.
In your case with cp test.ogg echo "test$1.ogg", it specifically looks for a file called test.ogg and one named echo to copy to the directory test$1.ogg.
The $1 will most likely expand to an empty string. This is why, when you delete the echo from the command, you get "test.ogg and test.ogg are the same files"; the command being executed is essentially
cp test.ogg test.ogg
This is probably a mistyping.
In the end, you want something like this:
for i in {1..100}; do cp test.ogg "test$i.ogg"; done
Or, as an alternative
i=0
while (( i++ < 100 )); do
cp test.ogg "test$i.ogg"
done
Or, using tee:
tee test{1..100}.ogg <test.ogg >/dev/null
Note: This would most likely work for 100 copies, but for thousands of copies it may generate a "argument list too long" error. In that case, revert to using a loop.
| Duplicate file x times in command shell |
1,387,878,201,000 |
I have a folder with a number of files in it ABC.* (there are roughly 100 such files). I want to duplicate them all to new files with names starting with DEF.*
So, I want
ABC.Page1
ABC.Page2
ABC.Topic12
...etc
copied to
DEF.Page1
DEF.Page2
DEF.Topic12
...etc
What is the simplest way to do this with a batch command (in BASH or similar)? I am thinking something involving sed or awk or xargs, but I'm having difficulty figuring out the syntax. I could write a Python script, but I'm thinking there is probably a command line solution that is not too complicated.
|
How about something like this in bash:
for file in ABC.*; do cp "$file" "${file/ABC/DEF}";done
you can test it by putting echo in front of the cp command:
for file in ABC.*; do echo cp "$file" "${file/ABC/DEF}";done
| How do I copy multiple files by wildcard? |
1,387,878,201,000 |
To make the story short, I did an rsync:
rsync -avP [email protected]:/tmp/
And I forgot to put in my source directory...
I really meant to run:
rsync -avP /tmp/ [email protected]:/tmp/
It printed a bunch of files, but I don't know where it copied them because I didn't specify a destination. Does anyone know what happened? I did an ls on the current folder, but I didn't find anything.
|
From man rsync:
Usages with just one SRC arg and no DEST arg will list the source files
instead of copying.
this as explanation below the invocation options, for you the invocation matches:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
| What happens when you rsync without a destination? |
1,387,878,201,000 |
I need to copy some files from a particular directory to a different location on a daily basis. I want to copy the changes only, so planning to use rsync. These files follows the following naming convention mysql-bin.*
My command looks as follows
# rsync --update -raz --progress /var/lib/mysql/mysql-bin.* /dbdata/binarylog/
My confusion is since I am planning to copy only few files from a directory rather than full directory contents , I have used * to copy only required files.
Just want to know whether my command is correct to achieve the same.
|
It looks OK. Although why are you using the -z option to compress the transfer? This option is normally used when you are copying to a remote rsync server over a slow network. In this instance it will compress and instantly decompress the files which will only increase your CPU uage with no benefit.
The -a (archive) option implies the -r (recursive) option so there is no need to explicitly specify that on the command line.
You can use the -n option (or --dry-run) to check your command. It will show what it would do without actually copying any files. To actually see what happens you should also use the -v option (or --verbose).
Therefore:
rsync -uanv /var/lib/mysql/mysql-bin.* /dbdata/binarylog/
and once you're happy that the files are listed correctly on the dry-run, remove the nv:
rsync -ua --progress /var/lib/mysql/mysql-bin.* /dbdata/binarylog/
| rsync to copy files which has changed |
1,387,878,201,000 |
Is there a method of slowing down the copy process on Linux?
I have a big file, say 10GB, and I'd like to copy it to another directory, but I don't want to copy it with full speed. Let's say I'd like to copy it with the speed of 1mb/s, not faster. I'd like to use a standard Linux cp command.
Is this possible? (If yes, how?)
Edit: so, I'll add more context to what I'm trying to achieve.
I have a problem on the ArchLinux system when copying large files over USB (to a pendrive, usb disk, etc). After filling up the usb buffer cache, my system stops responding (even the mouse stops; it moves only sporadically). The copy operation is still ongoing, but it takes 100% resources of the box. When the copy operation finishes, everything goes back to normal -- everything is perfectly responsive again.
Maybe it's a hardware error, I don't know, but I do know I have two machines with this problem (both are on ArchLinux, one is a desktop box, second is a laptop).
Easiest and fastest "solution" to this (I agree it's not the 'real' solution, just an ugly 'hack') would be to prevent this buffer from filling up by copying the file with an average write speed of the USB drive, for me that would be enough.
|
You can throttle a pipe with pv -qL (or cstream -t provides similar functionality)
tar -cf - . | pv -q -L 8192 | tar -C /your/usb -xvf -
-q removes stderr progress reporting.
The -L limit is in bytes.
More about the --rate-limit/-L flag from the man pv:
-L RATE, --rate-limit RATE
Limit the transfer to a maximum of RATE bytes per second.
A suffix of "k", "m", "g", or "t" can be added to denote
kilobytes (*1024), megabytes, and so on.
This answer originally pointed to throttle but that project is no longer available so has slipped out of some package systems.
| Make disk/disk copy slower |
1,387,878,201,000 |
I am trying to copy files over SSH, but cannot use scp due to not knowing the exact filename that I need. Although small binary files and text files transfer fine, large binary files get altered. Here is the file on the server:
remote$ ls -la
-rw-rw-r-- 1 user user 244970907 Aug 24 11:11 foo.gz
remote$ md5sum foo.gz
9b5a44dad9d129bab52cbc6d806e7fda foo.gz
Here is the file after I've moved it over:
local$ time ssh [email protected] -t 'cat /path/to/foo.gz' > latest.gz
real 1m52.098s
user 0m2.608s
sys 0m4.370s
local$ md5sum latest.gz
76fae9d6a4711bad1560092b539d034b latest.gz
local$ ls -la
-rw-rw-r-- 1 dotancohen dotancohen 245849912 Aug 24 18:26 latest.gz
Note that the downloaded file is bigger than the one on the server! However, if I do the same with a very small file, then everything works as expected:
remote$ echo "Hello" | gzip -c > hello.txt.gz
remote$ md5sum hello.txt.gz
08bf5080733d46a47d339520176b9211 hello.txt.gz
local$ time ssh [email protected] -t 'cat /path/to/hello.txt.gz' > hi.txt.gz
real 0m3.041s
user 0m0.013s
sys 0m0.005s
local$ md5sum hi.txt.gz
08bf5080733d46a47d339520176b9211 hi.txt.gz
Both file sizes are 26 bytes in this case.
Why might small files transfer fine, but large files get some bytes added to them?
|
TL;DR
Don't use -t. -t involves a pseudo-terminal on the remote host and should only be used to run visual applications from a terminal.
Explanation
The linefeed character (also known as newline or \n) is the one that when sent to a terminal tells the terminal to move its cursor down.
Yet, when you run seq 3 in a terminal, that is where seq writes 1\n2\n3\n to something like /dev/pts/0, you don't see:
1
2
3
but
1
2
3
Why is that?
Actually, when seq 3 (or ssh host seq 3 for that matters) writes 1\n2\n3\n, the terminal sees 1\r\n2\r\n3\r\n. That is, the line-feeds have been translated to carriage-return (upon which terminals move their cursor back to the left of the screen) and line-feed.
That is done by the terminal device driver. More exactly, by the line-discipline of the terminal (or pseudo-terminal) device, a software module that resides in the kernel.
You can control the behaviour of that line discipline with the stty command. The translation of LF -> CRLF is turned on with
stty onlcr
(which is generally enabled by default). You can turn it off with:
stty -onlcr
Or you can turn all output processing off with:
stty -opost
If you do that and run seq 3, you'll then see:
$ stty -onlcr; seq 3
1
2
3
as expected.
Now, when you do:
seq 3 > some-file
seq is no longer writing to a terminal device, it's writing into a regular file, there's no translation being done. So some-file does contain 1\n2\n3\n. The translation is only done when writing to a terminal device. And it's only done for display.
similarly, when you do:
ssh host seq 3
ssh is writing 1\n2\n3\n regardless of what ssh's output goes to.
What actually happens is that the seq 3 command is run on host with its stdout redirected to a pipe. The ssh server on host reads the other end of the pipe and sends it over the encrypted channel to your ssh client and the ssh client writes it onto its stdout, in your case a pseudo-terminal device, where LFs are translated to CRLF for display.
Many interactive applications behave differently when their stdout is not a terminal. For instance, if you run:
ssh host vi
vi doesn't like it, it doesn't like its output going to a pipe. It thinks it's not talking to a device that is able to understand cursor positioning escape sequences for instance.
So ssh has the -t option for that. With that option, the ssh server on host creates a pseudo-terminal device and makes that the stdout (and stdin, and stderr) of vi. What vi writes on that terminal device goes through that remote pseudo-terminal line discipline and is read by the ssh server and sent over the encrypted channel to the ssh client. It's the same as before except that instead of using a pipe, the ssh server uses a pseudo-terminal.
The other difference is that on the client side, the ssh client sets the terminal in raw mode (and disables local echo). That means that no translation is done there (opost is disabled and also other input-side behaviours). For instance, when you type Ctrl-C, instead of interrupting ssh, that ^C character is sent to the remote side, where the line discipline of the remote pseudo-terminal sends the interrupt to the remote command.
When you do:
ssh -t host seq 3
seq 3 writes 1\n2\n3\n to its stdout, which is a pseudo-terminal device. Because of onlcr, that gets translated on host to 1\r\n2\r\n3\r\n and sent to you over the encrypted channel. On your side there is no translation (onlcr disabled), so 1\r\n2\r\n3\r\n is displayed untouched (because of the raw mode) and correctly on the screen of your terminal emulator.
Now, if you do:
ssh -t host seq 3 > some-file
There's no difference from above. ssh will write the same thing: 1\r\n2\r\n3\r\n, but this time into some-file.
So basically all the LF in the output of seq have been translated to CRLF into some-file.
It's the same if you do:
ssh -t host cat remote-file > local-file
All the LF characters (0x0a bytes) are being translated into CRLF (0x0d 0x0a).
That's probably the reason for the corruption in your file. In the case of the second smaller file, it just so happens that the file doesn't contain 0x0a bytes, so there is no corruption.
Note that you could get different types of corruption with different tty settings. Another potential type of corruption associated with -t is if your startup files on host (~/.bashrc, ~/.ssh/rc...) write things to their stderr, because with -t the stdout and stderr of the remote shell end up being merged into ssh's stdout (they both go to the pseudo-terminal device).
You don't want the remote cat to output to a terminal device there.
You want:
ssh host cat remote-file > local-file
You could do:
ssh -t host 'stty -opost; cat remote-file' > local-file
That would work (except in the writing to stderr corruption case discussed above), but even that would be sub-optimal as you'd have that unnecessary pseudo-terminal layer running on host.
Some more fun:
$ ssh localhost echo | od -tx1
0000000 0a
0000001
OK.
$ ssh -t localhost echo | od -tx1
0000000 0d 0a
0000002
LF translated to CRLF
$ ssh -t localhost 'stty -opost; echo' | od -tx1
0000000 0a
0000001
OK again.
$ ssh -t localhost 'stty olcuc; echo x'
X
That's another form of output post-processing that can be done by the terminal line discipline.
$ echo x | ssh -t localhost 'stty -opost; echo' | od -tx1
Pseudo-terminal will not be allocated because stdin is not a terminal.
stty: standard input: Inappropriate ioctl for device
0000000 0a
0000001
ssh refuses to tell the server to use a pseudo-terminal when its own input is not a terminal. You can force it with -tt though:
$ echo x | ssh -tt localhost 'stty -opost; echo' | od -tx1
0000000 x \r \n \n
0000004
The line discipline does a lot more on the input side.
Here, echo doesn't read its input nor was asked to output that x\r\n\n so where does that come from? That's the local echo of the remote pseudo-terminal (stty echo). The ssh server is feeding the x\n it read from the client to the master side of the remote pseudo-terminal. And the line discipline of that echoes it back (before stty opost is run which is why we see a CRLF and not LF). That's independent from whether the remote application reads anything from stdin or not.
$ (sleep 1; printf '\03') | ssh -tt localhost 'trap "echo ouch" INT; sleep 2'
^Couch
The 0x3 character is echoed back as ^C (^ and C) because of stty echoctl and the shell and sleep receive a SIGINT because stty isig.
So while:
ssh -t host cat remote-file > local-file
is bad enough, but
ssh -tt host 'cat > remote-file' < local-file
to transfer files the other way across is a lot worse. You'll get some CR -> LF translation, but also problems with all the special characters (^C, ^Z, ^D, ^?, ^S...) and also the remote cat will not see eof when the end of local-file is reached, only when ^D is sent after a \r, \n or another ^D like when doing cat > file in your terminal.
| Why is this binary file transferred over "ssh -t" being changed? |
1,387,878,201,000 |
If I want to make the contents of file2 match the contents of file1, I could obviously just run cp file1 file2.
However, if I want to preserve everything about file2 except the contents—owner, permissions, extended attributes, ACLs, hard links, etc., etc., then I wouldn't want to run cp.* In that case I just want to plop the contents of file1 into file2.
It seems like the following would do it:
< file1 > file2
But it doesn't work. file2 is truncated to nothing and not written to. However,
cat < file1 > file2
does work.
It surprised me that the first version doesn't work.
Is the second version a UUOC? Is there a way to do this without invoking a command, merely by using redirections?
Note: I'm aware that UUOC is more of a pedantic point than a true anti-pattern.
*As tniles09 discovered, cp will in fact work in this case.
|
cat < file1 > file2 is not a UUOC. Classically, < and > do redirections which correspond to file descriptor duplications at the system level.
File descriptor duplications by themselves don’t do a thing (well, > redirections open with O_TRUNC, so to be accurate, output redirections do truncate the output file). Don’t let the < > symbols confuse you. Redirections don’t move data—they assign file descriptors to other file descriptors.
In this case you open file1 and assign that file descriptor to file descriptor 0 (<file1 == 0<file1) and file2 and assign that file descriptor to file descriptor 1 (>file2 == 1>file2).
Now that you’ve got two file descriptors, you need a process to shovel data between the two—and that’s what cat is for.
| Is it a UUOC (useless use of cat) to redirect one file to another? |
1,387,878,201,000 |
I am using PuTTY on Windows 7 to SSH to my school computer lab. Can I transfer files from my Windows machine to my user on the school machines using SSH?
|
Use the PSCP tool from the putty download page:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
PSCP is the putty version of scp which is a cp (copy) over ssh command.
PSCP needs to be installed on your windows computer (just downloaded, really, there is no install process. In the Packaged Files section, pscp.exe is already included). Nothing needs to be installed on the school's servers. PSCP and scp both use ssh to connect.
To answer the usage question from the comments:
To upload from your computer to a remote server:
c:\pscp c:\some\path\to\a\file.txt user@remote:\home\user\some\path
This will upload the file file.txt to the specified directory on the server.
If the final part of the destination path is NOT a directory, it will be the new file name. You could also do this to upload the file with a different name:
c:\pscp c:\some\path\to\a\file.txt user@remote:\home\user\some\path\newname.txt
To download a file from a remote server to your computer:
c:\pscp user@remote:\home\user\some\file.txt c:\some\path\to\a\
or
c:\pscp user@remote:\home\user\some\file.txt c:\some\path\to\a\newfile.txt
or
c:\pscp user@remote:\home\user\some\file.txt .
With a lone dot at the end there. This will download the specified file to the current directory.
Since the comment is too far down, I should also point out here that WinSCP exists providing a GUI for all this, if that's of interest: http://winscp.net/eng/download.php
| Can I transfer files using SSH? |
1,387,878,201,000 |
I have a folder SOURCE that contains several sub-level folders, each with its own files.
I want to copy this folder in a new folder COPY where I need to copy the directory structure but keep the files as symbolic links to the original files in SOURCE and its subfolders.
|
Here's the solution on non-embedded Linux and Cygwin:
cp -as SOURCE/ COPY
Note that SOURCE must be an absolute path and have a trailing slash. If you want to give a relative path, you can use
cp -as "$(pwd)/SOURCE/" COPY
| How to copy a folder structure and make symbolic links to files? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.