converting eac3 to aac with ffmpeg - ffmpeg

I have a number of video files stored on my Synology of which the audio doesn't play on when opening them with DS File. This is because DS File does not support eac3. I would like to convert those files to aac using ffmpeg, but when doing so, all audio is lost.
This is the file info:
Input #0, matroska,webm, from '<file>.mkv':
Metadata:
encoder : libebml v1.4.2 + libmatroska v1.6.4
Duration: 00:48:43.42, start: 0.000000, bitrate: 6566 kb/s
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: eac3, 48000 Hz, 5.1 (default)
Stream #0:2(eng): Subtitle: subrip
Metadata:
title : English [SDH]
Stream #0:3(ara): Subtitle: subrip
Metadata:
title : Arabic
Stream #0:4(chi): Subtitle: subrip
This is my attempt:
ffmpeg -i <file>.mkv -map 0:v -map 0:a:0 -map 0:s -c copy -c:a aac -b:a 640k output.mkv
Subtitles are kept, but audio is completely removed. I would like to automate the process if possible.
This is my ffmpeg configuration:
ffmpeg version 4.1.8 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 8.5.0 (GCC)
configuration: --prefix=/usr --incdir='${prefix}/include/ffmpeg' --arch=i686 --target-os=linux --cross-prefix=/usr/local/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu- --enable-cross-compile --enable-optimizations --enable-pic --enable-gpl --enable-shared --disable-static --disable-stripping --enable-version3 --enable-encoders --enable-pthreads --disable-protocols --disable-protocol=rtp --enable-protocol=file --enable-protocol=pipe --disable-muxer=image2 --disable-muxer=image2pipe --disable-swscale-alpha --disable-ffplay --disable-ffprobe --disable-doc --disable-devices --disable-bzlib --disable-altivec --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libmp3lame --disable-vaapi --disable-cuvid --disable-nvenc --disable-decoder=aac --disable-decoder=aac_fixed --disable-encoder=aac --disable-decoder=amrnb --disable-decoder=ac3 --disable-decoder=ac3_fixed --disable-encoder=zmbv --disable-encoder=dca --disable-decoder=dca --disable-encoder=ac3 --disable-encoder=ac3_fixed --disable-encoder=eac3 --disable-decoder=eac3 --disable-encoder=truehd --disable-decoder=truehd --disable-encoder=hevc_vaapi --disable-decoder=hevc --disable-muxer=hevc --disable-demuxer=hevc --disable-parser=hevc --disable-bsf=hevc_mp4toannexb --x86asmexe=yasm --cc=/usr/local/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-wrap-gcc --enable-yasm --enable-libx264 --enable-encoder=libx264
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
Synology does not support eac3 out of the box. So is this even possible?

Try adding channels for audio as well along side bit rate to the command line after aac.
for 5.1 audio add:
-ac 6 -b:a 384k
For stereo audio add:
-ac 2 -b:a 128k
The final command would be like
ffmpeg -i <file>.mkv -map 0:v -map 0:a:0 -map 0:s -c copy -c:a aac -ac 6 -b:a 640k output.mkv

Found it, I was apparently using the built-in ffmpeg, while I should be using the community package: https://synocommunity.com/packages
/path/to/ffmpeg -i "input.mkv" -map 0 -c:s copy -c:v copy -c:a ac3 -b:a 640k "output.mkv"

Related

Codec h264_cuvid is not supported

======================= Environment =======================
System: ubuntu 18.04
Architecture: x86_64
Display Card: NVIDIA GeForce 820m
Display Card Driver: NVIDIA-Linux-x86_64-390.87
gcc: 6.5.0
CUDA: 9.1.85 (also tried 9.0.176)
FFmpeg: 3.4 (also tried 4.0, 4.1)
==================== FFmpeg Compilation ====================
./configure \
--prefix="$DIR_BUILD" \
--bindir="$DIR_BIN" \
--enable-cuda \
--enable-cuvid \
--enable-nvenc \
--enable-nonfree \
--enable-libnpp \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64
======================= Verification =======================
Driver Verification:
(I have downgrade my gcc from 7.3 to 6.5, I don't know why there still shows gcc version 7.3)
$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 390.87 Tue Aug 21 12:33:05 PDT 2018
GCC version: gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
CUDA Verification:
$nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
$./deviceQuery
Rsult = PASS
$./bandwidthTest
Result = PASS
FFmpeg Decoder Verification:
$ ffmpeg -codecs | grep cuvid
ffmpeg version 3.4.5 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.5.0 (Ubuntu 6.5.0-2ubuntu1~18.04) 20181026
configuration: --prefix=/home/cavalry/Downloads/compile_ffmpeg/ffmpeg_build --bindir=/home/cavalry/Downloads/compile_ffmpeg/bin --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
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
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_vdpau h264_cuvid ) (encoders: h264_nvenc h264_v4l2m2m h264_vaapi nvenc nvenc_h264 )
DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_cuvid ) (encoders: nvenc_hevc hevc_nvenc hevc_vaapi )
DEVIL. mjpeg Motion JPEG (decoders: mjpeg mjpeg_cuvid ) (encoders: mjpeg mjpeg_vaapi )
DEV.L. mpeg1video MPEG-1 video (decoders: mpeg1video mpeg1video_vdpau mpeg1_v4l2m2m mpeg1_cuvid )
DEV.L. mpeg2video MPEG-2 video (decoders: mpeg2video mpegvideo mpegvideo_vdpau mpeg2_v4l2m2m mpeg2_cuvid ) (encoders: mpeg2video mpeg2_vaapi )
DEV.L. mpeg4 MPEG-4 part 2 (decoders: mpeg4 mpeg4_v4l2m2m mpeg4_vdpau mpeg4_cuvid ) (encoders: mpeg4 mpeg4_v4l2m2m )
D.V.L. vc1 SMPTE VC-1 (decoders: vc1 vc1_vdpau vc1_v4l2m2m vc1_cuvid )
DEV.L. vp8 On2 VP8 (decoders: vp8 vp8_v4l2m2m vp8_cuvid ) (encoders: vp8_v4l2m2m vp8_vaapi )
DEV.L. vp9 Google VP9 (decoders: vp9 vp9_v4l2m2m vp9_cuvid ) (encoders: vp9_vaapi )
FFmpeg Encoder Verification:
$ ffmpeg -codecs | grep nvenc
ffmpeg version 3.4.5 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.5.0 (Ubuntu 6.5.0-2ubuntu1~18.04) 20181026
configuration: --prefix=/home/cavalry/Downloads/compile_ffmpeg/ffmpeg_build --bindir=/home/cavalry/Downloads/compile_ffmpeg/bin --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
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
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_vdpau h264_cuvid ) (encoders: h264_nvenc h264_v4l2m2m h264_vaapi nvenc nvenc_h264 )
DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_cuvid ) (encoders: nvenc_hevc hevc_nvenc hevc_vaapi )
================== Exec ffmepg command line ===================
All things seem goes right, then I executed the following command:
ffmpeg -c:v h264_cuvid -i ./holidy.mp4 output.mkv
But it turns out:
[h264_cuvid # 0x55f93a512200] Codec h264_cuvid is not supported.
Here is the whole information:
$ ffmpeg -c:v h264_cuvid -i ./holidy.mp4 output.mkv
ffmpeg version 3.4.5 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.5.0 (Ubuntu 6.5.0-2ubuntu1~18.04) 20181026
configuration: --prefix=/home/cavalry/Downloads/compile_ffmpeg/ffmpeg_build --bindir=/home/cavalry/Downloads/compile_ffmpeg/bin --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
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
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './holidy.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isomavc1iso6
creation_time : 2018-01-29T09:18:23.000000Z
album : Yinyuetai
artist : yinyuetai.com
comment : Yinyuetai-1TR1166
date : 01/29/18 17:18:23
Duration: 00:04:15.21, start: 0.000000, bitrate: 4210 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 4087 kb/s, 24 fps, 24 tbr, 24k tbn, 48 tbc (default)
Metadata:
creation_time : 2018-01-29T09:18:23.000000Z
handler_name : 264#GPAC0.5.1-DEV-rev5472
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 120 kb/s (default)
Metadata:
creation_time : 2018-01-29T09:17:31.000000Z
handler_name : Sound Media Handler
[h264_cuvid # 0x55f3e05ca1c0] Codec h264_cuvid is not supported.
Stream mapping:
Stream #0:0 -> #0:0 (h264 (h264_cuvid) -> mpeg4 (native))
Stream #0:1 -> #0:1 (aac (native) -> ac3 (native))
Error while opening decoder for input stream #0:0 : Invalid argument
I have tried width CUDA9.0, CUDA9.1, FFmpeg3.4, FFmpeg4.0, FFmpeg 4.1, but it reports the same error. Can anyone help me? I will appreciate you greatly !
According to Nvidia Video Encode and Decode GPU Support Matrix(snapshot),
GeForce 820m support NVENC & NVDEC. If my understanding is correct, a Nvidia graphic card that support NVENC & NVDEC should support h264_cuvid decoder in FFmpeg as well. So I think the answer of #halfelf was wrong.
Just give up.
Unfortunately, GeForce 820m is a Fermi based GPU without cuvid at all.

ffmpeg demux into audio and video resets PTS

Demuxing
I am demuxing TS segments into audio and video as follows.
ffmpeg -y -i input.ts -vcodec copy -an output_video.ts
ffmpeg -y -i input.ts -acodec copy -vn output_audio.aac
Inspecting Input
The start_pts and start_time on input.ts are as shown below. I was able to inspect these values using ffprobe -show_streams -print_format json input.ts
"start_pts": 8306558438,
"start_time": "92295.093756",
Inspecting output video
The output .ts has some default start_pts and start_time values as shown below. These were also obtained using the same ffprobe command as indicated above.
"start_pts": 126000,
"start_time": "1.400000",
Inspecting output audio
The same ffprobe command on output_audio.aac shows that the output aac has invalid codec_tag and codec_tag_string as shown below. The start_pts and start_time are not present in the output_audio.aac.
"codec_tag_string": "[0][0][0][0]", (should have been [15][0][0][0])
"codec_tag": "0x0000", (should have been 0xf000)
Questions
Wondering if this difference in the start_pts, start_time, codec_tag is expected?
If it is expected, what can I do to ensure that the all of these parameters get retained on the output?
If it is not expected, is there some more information I can share to track this down?
Note
There were other outputs that I found inconsistent in the ffprobe command for the output_audio.aac like duration etc.. I shared what I thought are most valuable at this point. If required I can share complete outputs from all of the above executions.
[EDIT 07/30/2018 - 08:00 MST]
logs for ffmpeg -y -i input.ts -vcodec copy -an output_video.ts -acodec copy -vn output_audio.aacare as shown below.
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.0.0 (clang-900.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-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.3.0/include/openjpeg-2.3 --enable-nonfree
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
[mpegts # 0x7f88ed803000] start time for stream 0 is not set in estimate_timings_from_pts
Input #0, mpegts, from 'i7h9456s_media_46185.ts':
Duration: 00:00:06.05, start: 86216.852667, bitrate: 2898 kb/s
Program 1
Stream #0:0[0x102]: Data: timed_id3 (ID3 / 0x20334449)
Stream #0:1[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte170m, progressive), 640x360 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:2[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 190 kb/s
Output #0, mpegts, to '../output_video.ts':
Metadata:
encoder : Lavf58.12.100
Stream #0:0: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte170m, progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
Output #1, adts, to '../output_audio.aac':
Metadata:
encoder : Lavf58.12.100
Stream #1:0: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 190 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Stream #0:2 -> #1:0 (copy)
Press [q] to stop, [?] for help
frame= 180 fps=0.0 q=-1.0 Lsize= 2088kB time=00:00:06.03 bitrate=2833.8kbits/s speed= 904x
video:1918kB audio:142kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.349750%
All the differences are expected. FFmpeg removes input timestamp offset unless set otherwise. The MPEG-TS muxer also adds a timestamp offset.
You can preserve source timestamps when remuxing TS, and also avoid the muxer's offset, like this,
ffmpeg -y -copyts -i input.ts -vcodec copy -an -muxdelay 0 -muxpreload 0 output_video.ts
As .aac is a raw ADTS stream, there is no codec tag string present. This is expected. Mux to .m4a or .mka or a similar container if tags are needed.

how to stream live m3u8 file using ffmpeg to youtube rtmp

i want to restream a live m3u8 file to youtube
.i used following code
fmpeg -re -i <http://mypanel.tv:8080/live/****/slyv0955k9/14131.m3u8
> -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 3000k -f flv "<rtmp://live-dfw.twitch.tv/app/{live_231566994_FS4BN0qoJMeXEuWklm6j0l1ODQj9u6}>"
and i return i get this from my linux server
[root#server ~]# ffmpeg -re -i http://mypanel.tv:8080/live/****/slyv0955k9/14131.m3u8
-c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 3000k -f flv "<rtmp://live-dfw.twitch.tv/app/{live_23156556994_FS4BN0qoJMeXEuWklm6j0l1ODQj9u6}>"ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
[h264 # 0x1029ba0] non-existing SPS 0 referenced in buffering period
Last message repeated 1 times
[h264 # 0x1073680] non-existing SPS 0 referenced in buffering period
Input #0, hls,applehttp, from 'http://mypanel.tv:8080/live/***/slyv0955k9/14131.m3u8':
Duration: N/A, start: 39062.400000, bitrate: N/A
Program 0
Metadata:
variant_bitrate : 0
Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 133 kb/s
At least one output file must be specified
so can anyone help me with this?please note i'm not an expert in linux so please give me specific commands to restream a live m3u8 file
Try it:
#! /bin/bash
PRESET="ultrafast" # ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
SOURCE="http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8"
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"
KEY="xxxx-xxxx-xxxx-xxxx" # Your youtube key. (https://www.youtube.com/live_dashboard > encoder config > name/key)
ffmpeg \
-re -i "$SOURCE" -vcodec libx264 -preset $PRESET -maxrate 3000k -b:v 2500k \
-bufsize 600k -pix_fmt yuv420p -g 60 -c:a aac -b:a 160k -ac 2 \
-ar 44100 -f flv -s 1280x720 "$YOUTUBE_URL/$KEY"

thread_queue_size during Live Streaming from ffmpeg

I'm trying to stream a webcam stream froma RaspberryPi-B to Youtube. The webcam used is a Logitech C920. If I use the h264 stream from the camera itself, it works fine using
ffmpeg -f alsa -i hw:1,0 -f v4l2 -vcodec h264 -video_size 854x480 -r 25 -i /dev/video0 -acodec aac -b:a 64000 -ar 48000 -bufsize 64k -b:v 1200k -bufsize 1024k -maxrate 1800k -vcodec copy -g 60 -r 30 -f flv
rtmp://a.rtmp.youtube.com/live2/stream_here
So, for this to work with other non h264 cameras like the Pi Cam or any other cheaper webcam, it needs to work with the raw stream and get converted to h264 using libx264. This is the whole point of using the Pi. Hence the second command set.
ffmpeg -f alsa -ac 2 -i hw:1,0 -f v4l2 -i /dev/video0 -framerate 25 -video_size 1280x720 -c:v libx264 -preset veryfast -maxrate 1984k -bufsize 3968k -vf "format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 -f flv rtmp://a.rtmp.youtube.com/live2/stream_name
So this results in the following issue.
ffmpeg version git-2017-03-03-68ee800 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration: --arch=armhf --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --extra-libs=-lasound --enable-pthreads
libavutil 55. 47.101 / 55. 47.101
libavcodec 57. 82.100 / 57. 82.100
libavformat 57. 66.103 / 57. 66.103
libavdevice 57. 3.100 / 57. 3.100
libavfilter 6. 74.100 / 6. 74.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:1,0':
Duration: N/A, start: 1488650966.446293, bitrate: 1024 kb/s
Stream #0:0: Audio: pcm_s16le, 32000 Hz, stereo, s16, 1024 kb/s
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 2227.042654, bitrate: 159252 kb/s
Stream #1:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 864x480, 159252 kb/s, 24 fps, 24 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[video4linux2,v4l2 # 0x2e42310] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Illegal instruction
pi#raspberrypi:~ $
If I add
thread_queue_size 512
I end up with
pi#raspberrypi:~ $ ffmpeg -f alsa -ac 2 -i hw:1,0 -f v4l2 -thread_queue_size 512 -i /dev/video0 -framerate 25 -video_size 1280x720 -c:v libx264 -preset veryfast -maxrate 1984k -bufsize 3968k -vf "format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 -f flv rtmp://a.rtmp.youtube.com/live2/zqg7-98wy-60b6-f2yx
ffmpeg version git-2017-03-03-68ee800 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration: --arch=armhf --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --extra-libs=-lasound --enable-pthreads
libavutil 55. 47.101 / 55. 47.101
libavcodec 57. 82.100 / 57. 82.100
libavformat 57. 66.103 / 57. 66.103
libavdevice 57. 3.100 / 57. 3.100
libavfilter 6. 74.100 / 6. 74.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:1,0':
Duration: N/A, start: 1488651430.836193, bitrate: 1024 kb/s
Stream #0:0: Audio: pcm_s16le, 32000 Hz, stereo, s16, 1024 kb/s
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 2691.407641, bitrate: 159252 kb/s
Stream #1:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 864x480, 159252 kb/s, 24 fps, 24 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
Illegal instruction
pi#raspberrypi:~ $
Where exactly does
thread_queue_size
Belong?
Notes:
ffmpeg was built using this reference
–extra-libs=-lasound & --enable=pthreads was used
I totally forgot that the RaspberryPI had hardware support for H264.
So I followed this tutorial and we're live on 30% CPU usage with realtime streaming on the Raspberry Pi B (ARMV6).

ffmpeg: Image2 => Error while opening encoder

I get the following error ffmpeg.
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
ffmpeg -f image2 -i %05d.jpg -vcodec libx264 foo.mp4
I'm pretty sure I've used this exact command before and it's been fine. This is my terminal output. Any help would be appreciated.
$ ffmpeg -f image2 -i %05d.jpg -vcodec libx264 foo.mp4
ffmpeg version 1.0 Copyright (c) 2000-2012 the FFmpeg developers
built on Nov 22 2012 17:59:05 with Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libfreetype --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid
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 '%05d.jpg':
Duration: 00:00:04.44, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p, 1201x900 [SAR 1:1 DAR 1201:900], 25 fps, 25 tbr, 25 tbn, 25 tbc
[libx264 # 0x7fab0881aa00] width not divisible by 2 (1201x900)
Output #0, mp4, to 'foo.mp4':
Stream #0:0: Video: h264, yuvj420p, 1201x900 [SAR 1:1 DAR 1201:900], q=-1--1, 90k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg -> libx264)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
You have to crop the input image so that the resulting width and height was divided by 2
Crop filter:
-vf "crop=in_w-1:in_h"
$ ffmpeg -f image2 -i %05d.jpg -vf "crop=in_w-1:in_h" -vcodec libx264 foo.mp4
UPD
We can write the formula for the general case, which leads to the even sides
$ ffmpeg -f image2 -i %05d.jpg -vf "crop=((in_w/2)*2):((in_h/2)*2)" -vcodec libx264 foo.mp4
A solution which worked for me was to use
-vf scale=1920:1080
As an option before the output video, i.e.
ffmpeg -y -loop 1 -i "input.png" -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=1920:1080 out.mp4
It automatically resizes images correctly, though I never tested what happens when the resolution was larger than 1920:1080 (TBD).

Resources