FFmpeg Convert to JPEG works in VLC but not in Mac Preview? - image

I'm trying to convert a PNG image to a JPEG image using ffmpeg. As far as I can tell, it's working fine, but it doesn't display properly in Mac Preview.
I'm running the following:
$ ffmpeg -i foo.png foo.jpg
And it produces the following output:
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.3_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
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
Input #0, png_pipe, from 'foo.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, rgba(pc), 200x231, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler # 0x7ffeaf00ae00] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'foo.jpg':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: mjpeg, yuvj444p(pc), 200x231, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc58.35.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 1 fps=0.0 q=3.7 Lsize=N/A time=00:00:00.04 bitrate=N/A speed= 4.7x
video:12kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
When I open foo.jpg in most applications, such as VLC or Google Chrome, I get exactly what I expected: an image that looks exactly the same as foo.png, the input.
However, this is what is displayed in the Finder preview, and the same this is displayed when I open up the file in "Preview."
~~~I wonder if this has something to do with the deprecated pixel format used, make sure you did set range correctly error, but I'm not sure, especially since the image is fine, the problem seems to be elsewhere.~~~
It seems the deprecated pixel format error is not the issue (that's an internal thing), so I guess I just need to specify pixel formats properly.

Looks like QT / AVFoundation doesn't like fully-sampled chroma in JPEG.
First try
ffmpeg -i foo.png -pix_fmt yuvj422p foo.jpg
else,
ffmpeg -i foo.png -pix_fmt yuvj420p foo.jpg
The warning about deprecated format relates to ffmpeg internals and not the produced output.

You could use the built-in, Apple-supplied sips "Scriptable Image Processing System" tool to do the conversion and thereby avoid the issue and also be less dependent on having to install external tools:
sips -s format jpeg input.png --out output.jpg

Related

Create silent wav and pipe it

I've been through many stackoverflow pages and forums trying to find the answer I want.
I created a virtual microphone and I'm trying to pipe to it some wav sounds created using FFMPEG.
When I want to pipe a keyboard noise I pipe the sound to my virtual sound capture device like this:
ffmpeg -fflags +discardcorrupt -i <Keyboard sound Path> -f s16le -ar 44100 -ac 1 - > /tmp/gapFakeMic
And when I want to pipe some synthetized voice sound using Espeak to my virtual microphone, I do this:
espeak -vbrazil-mbrola-4 <some random text> --stdout | ffmpeg -fflags +discardcorrupt -i pipe:0 -f s16le -ar 44100 -ac 1 - > /tmp/gapFakeMic
The problem is my capture device doesn't record the sound like a normal recorder that still records even when there's no sound being transmited to it. So I'm trying to append the silence to the wav which is being created while my application is running. Always when I try to send the silence to buffer, FFMPEG returns the following response:
[NULL # 0x5579f7921a00] Unable to find a suitable output format for 'pipe:'
FFMPEG is a powerful tool but its documentation lacks to be useful for newbies like me. So, I'd appreciate if anyone could answer this or at least give me any direction or some resource where I could find a way of achieving this.
EDIT:
Here's how I'm producing the silence to my virtual microphone:
ffmpeg -f lavfi -i anullsrc=channel_layout=mono:sample_rate=44100 -t <Time in seconds> - > /tmp/gapFakeMic
Here's the full log:
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
Input #0, lavfi, from 'anullsrc=channel_layout=mono:sample_rate=44100':
Duration: N/A, start: 0.000000, bitrate: 352 kb/s
Stream #0:0: Audio: pcm_u8, 44100 Hz, mono, u8, 352 kb/s
[NULL # 0x560516626f40] Unable to find a suitable output format for 'pipe:'
pipe:: Invalid argument
EDIT 2:
After Gyan provided a solution in the comments the error above doesn't show anymore but my result audio is being broken and doesn't come out as expected. Now the command that generates and appends the silent audio is like this:
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t <Time in seconds> -f s16le - > /tmp/gapFakeMic
Edit 3:
I've made some changes to the command I'm using to pipe silence to the virtual mic. I think the pipe is breaking because of some incompatibility in audio formats. I hope I can find a solution in the next few days. After every little change I realize some improvements. Now I can hear the silence between the keys sounds but it isn't recording all the audios I'm passing to it. Here's how the command is now:
ffmpeg -f lavfi -i anullsrc=channel_layout=mono:sample_rate=44100 -t <Time in seconds> -f s16le -ar 44100 -ac 1 - > /home/icaroerasmo/gapFakeMic`
I also realized that when I pipe the sound to a pipe file created inside my home folder the audio quality improves.
Edit 4:
After all this struggle it's clear now that the named pipe is breaking in the second time it's called. I've already googled how to flush a named pipe but I didn't find anything that worked.

Nvidia Nvenc Video Conversion from mxf to mp4 getting error for multiple streams inside

I am trying to convert a video that have multiple video streams and one audio stream from mxf format to mp4 format and getting an error. How can i solve this problem? Thank you.
E:\video>ffmpeg -loglevel error -y -i E:\video\19_12_2018\Files\MEDIA\media_data.mxf -map 0 -c:v h264_nvenc -acodec copy nvidia_output.mp4
[h264_nvenc # 0000020b30c86e80] OpenEncodeSessionEx failed: out of memory (10)
[h264_nvenc # 0000020b30c86e80] No NVENC capable devices found
Error initializing output stream 0:2 -- Error while opening encoder for output stream #0:2 - maybe incorrect parameters such as bit_rate, rate, width or height
[h264_nvenc # 00000204c1e37040] OpenEncodeSessionEx failed: out of memory (10)
[h264_nvenc # 00000204c1e37040] No NVENC capable devices found
[h264_nvenc # 00000204c1e37040] Nvenc unloaded
[jpeg2000 # 00000204c2d90080] End mismatch 1
Last message repeated 1 times
Error initializing output stream 0:2 -- Error while opening encoder for output stream #0:2 - maybe incorrect parameters such as bit_rate, rate, width or height
My FFPROBE output
E:\video>ffmpeg ffprobe
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181017
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig
--enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype
--enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy
--enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx
--enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp
--enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa
--enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf
--enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec
--enable-dxva2 --enable-avisynth
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
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
The error you're seeing is expected, if you're using a consumer-grade NVIDIA GPU wherein the maximum simultaneous NVENC session limit of 2 is enforced at the firmware and driver level. See the NVIDIA GPU Matrix for more information on this.
There are two ways you can overcome this limitation:
1. Explicitly select the video stream(s) you desire to encode, via -map options, such that only two video streams are encoded at any given time per session. The example below explicitly selects the first and second video stream only:
E:\video>ffmpeg -loglevel error -y -i E:\video\19_12_2018\Files\MEDIA\media_data.mxf -map 0:v:0 -map 0:v:1 -map:0:a -c:v h264_nvenc -acodec copy nvidia_output.mp4
It would be awesome if you'd provide the ffprobe output for the input file you're working with, and that way, we can suggest what to do with the other video streams. An alternative to such would be falling back to a software-based encoder (such as x264) if so needed.
2. Override the aforementioned NVENC session count limit above: This will require you to patch the NVIDIA driver, as documented in this repository. Instructions for Linux are also available here.

Converting DTS to AAC with ffmpeg shifts spoken audio to the right

I am using ffmpeg to convert mkv movies to mp4, like so:
$ ffmpeg -i source.mkv -c:v copy -c:a aac destination.mp4
By doing this, the audio stream gets converted from the original DTS:
Stream #0:1: Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
To AAC:
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 394 kb/s (default)
The resulting file plays just fine, except that the spoken audio (what I am assuming would be sent to the central channel in a 5.1 configuration) sounds clearly shifted to the right, when listening through the MacBook's built-in speakers or my stereo headphones. Note that music and other sound effects appear unaffected, properly balanced. Also note that I have been able to reproduce this behavior with a variety of source files.
Here's ffmpeg's banner:
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
An FFmpeg commit, aacenc: support extended channel layouts using PCEs, in Nov 2017 added support for many more channel layouts than specified in the MPEG standard for AAC. Unfortunately, it seems it has broken encoding for layouts that worked fine before.
The 3.4 release series is the last before the said commit and should be used for multichannel AAC encoding if you encounter an error with more recent builds.
There is an open bug report at https://trac.ffmpeg.org/ticket/7273. You may post a comment in there to showcase your example.

How to keep transparency when converting .avi to .webm with ffmpeg [duplicate]

I am trying to convert a mov with alpha transparency to webm with alpha transparency, as seen here. I followed the steps explained here to no avail.
From this answer I was able to remove all the black in the video, thus making it transparent but this is not what I need as I already have a transparent mov and would like to convert that to transparent webm format.
ffmpeg -i input.mp4 -c:v libvpx -vf "colorkey=0x000000:0.1:0.1,format=yuva420p" out.webm
This is the ffprobe output of the video I would like to convert to webm with transparency.
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/1.5.2_1/include/openjpeg-1.5 --enable-nonfree --enable-vda
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2016-01-17 16:04:07
encoder : Mac OS X v? (AVF 1046.9.1, CM 1731.15.20, x86_64)
encoder-eng : Mac OS X v? (AVF 1046.9.1, CM 1731.15.20, x86_64)
Duration: 00:00:06.63, start: 0.000000, bitrate: 63966 kb/s
Stream #0:0(eng): Video: prores (ap4h / 0x68347061), yuva444p10le(bt470bg/smpte240m/bt709), 1920x1080, 63963 kb/s, 25.03 fps, 25 tbr, 600 tbn, 600 tbc (default)
Metadata:
creation_time : 2016-01-17 16:04:07
handler_name : Core Media Data Handler
encoder : Apple ProRes 4444
I've also tried the following command which didn't work for me either.
ffmpeg -y -i input.mov -c:v libvpx-vp9 -b:v 2000k -pass 1 -an -f webm output.webm
I'm using version 2.8.4 of ffmpeg on a Mac, installed with brew. 2.8.5 is the latest version.
Since 2016-07-13, it's possible to encode VP9/webm videos with alpha channel (VP9a). However, the command you use here will create a VP8a video. Assuming you got a copy of ffmpeg compiled after that date, all you need is change the libvpx to libvpx-vp9. You don't need the yuva420p conversion either (is selected by default).
Try
ffmpeg -i input.mov -c:v libvpx -pix_fmt yuva420p out.webm
All of the other solutions resulted in a video of subpar quality. Please ensure that you define the bitrate to your liking. I changed mine from 1M to 2M and was satisfied.
ffmpeg -i "Model 1 V1.mov" -f webm -c:v libvpx -b:v 2M -acodec libvorbis -auto-alt-ref 0 model1v3.webm -hide_banner
If you're using After Effects or Premiere Pro, there's also this plugin, which can be used in Adobe Media Encoder.
WebM-alpha is only defined for VP8. It doesn't work at all for VP9 right now.
This is the command that worked for me for VP8.
ffmpeg -i input.mov -c:v libvpx -pix_fmt yuva420p -b:v 2M -auto-alt-ref 0 output.webm
Accepted option did not work.

ffmpeg can't find output directory under cygwin

I'm using the windows build of ffmpeg (details below), and when I try to transcode a video with the output file NOT in the local directory, it complains with the error message :
/dtop/out.mp4: No such file or directory
My cygwin mounts are as follows - I have not found any other application which doesn't follow the mounts/links correctly...
[lwobker:/dtop/vertigo]$ mount
C:/Documents and Settings/lwobker/Desktop on /dtop type ntfs (binary)
C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
C:/cygwin on / type ntfs (binary,auto)
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
Here's what I've managed to figure out so far, leading me to believe that for some reason FFMPEG does not like following mount points or links in cygwin. But I'll be damned if I can figure out why...
if I do this, it WORKS:
ffmpeg -i ./input.mp4 ./out.mp4
if I do this, it WORKS (permission and mount/link check):
touch /dtop/out.mp4
however, if I give a file location that is not in the current working directory or a subdirectory of the current working directory, it pukes:
[lwobker:/dtop/vertigo]$ ffmpeg -i 00001.MTS /dtop/out.mp4
ffmpeg version N-64919-ga613257 Copyright (c) 2000-2014 the FFmpeg developers
<snip>
Input #0, mpegts, from '00001.MTS':
Duration: 00:01:41.63, start: 1.033367, bitrate: 10221 kb/s
Program 1
Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1440x1080 [SAR 4:3 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
/dtop/out.mp4: No such file or directory
it also pukes if I give it /cygdrive/c/somefile.mp4 as an argument - it won't find that either.
Any ideas would be really appreciated. I had this working with a version of FFMPEG that I had compiled from source locally within cygwin, but when I moved machines I could not get it to recompile correctly so I'm hoping to figure this out so I can use the pre-compiled binaries for convenience...
FFMPEG version details:
[lwobker:/dtop/vertigo]$ ffmpeg
ffmpeg version N-64919-ga613257 Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 23 2014 00:35:22 with gcc 4.8.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 92.101 / 52. 92.101
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 48.101 / 55. 48.101
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.102 / 4. 11.102
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
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'
You cannot feed Windows native programs Cygwin paths, they do not understand
that. However you can put a wrapper script in the same folder as ffmpeg.exe,
and call it ffmpeg. Like this
#!/bin/sh
for each
do
foo=$(cygpath -w -- "$each")
bar+=("$foo")
done
ffmpeg.exe "${bar[#]}"
Then you go from this
$ ffmpeg.exe -i 1_Les_Nuits.mp3 /tmp/outfile.m4a
/tmp/outfile.m4a: No such file or directory
To this
$ ffmpeg -i 1_Les_Nuits.mp3 /tmp/outfile.m4a
frame=1 fps=0.1 q=33.0 Lsize=6046kB time=00:06:21.52 bitrate= 129.8kbits/s
Another option, if it works for you is to just use Windows paths when dealing
with Windows native programs, example
ffmpeg.exe -i 'C:\1_Les_Nuits.mp3' 'C:\outfile.m4a'

Resources