ffpmeg force overwrite (badly) detected input framerate - input

I am running IP Webcam on Android which provides an mpjpeg video stream. I have to limit the capture frame rate to 5fps to save on battery.
However ffmpeg will still detect the input stream to be 25 fps, which causes it to be saved in the wrong speed causing timestamps and audio to be desynchronized.
Input #0, mpjpeg, from 'https://***:***#smarthome:8080/video':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Input #1, ogg, from 'https://***:***#smarthome:8080/audio.opus':
Duration: N/A, start: 0.006500, bitrate: N/A
Stream #1:0: Audio: opus, 48000 Hz, mono, fltp
Metadata:
ENCODER : Lavf58.12.100
[stream_segment,ssegment # 0x19b49a0] Opening '/mnt/nas/SecurityCamera/2020-06-20_14-26-04.mkv' for writing
Output #0, stream_segment,ssegment, to '/mnt/nas/SecurityCamera/%Y-%m-%d_%H-%M-%S.mkv':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 tbr, 1k tbn, 25 tbc
Stream #0:1: Audio: opus, 48000 Hz, mono, fltp
Metadata:
ENCODER : Lavf58.12.100
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[ogg # 0x1753e00] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame= 8 fps=7.9 q=-1.0 size=N/A time=00:00:00.49 bitrate=N/A speed=0.489x
As you can see it detects Input #0 to be 25 tbr, 25 tbn, 25 tbc which results in an expected 25 fps, however the fps (shown high right now but it slowly approaching 5fps) is way below 25 which causes the speed to be <1x.
I have tried to use -r 5 -i ... and -vsync 2 and different values for -enc_time_base none of which had any impact. From https://trac.ffmpeg.org/ticket/403 I've learned that -r only works on inputs with unknown fps. But my input doesn't have unknown fps, it has the wrong fps.
Is there any way to force overwrite the input fps so that I can get a proper speed of 1x and synchronized timestamps and audio?

Related

How do you set the fps to 60 for the coral mipi camera

I am trying to set the fps of the coral mipi camera to 60fps. From the datasheet, it says it can run 720p at 60fps so i know the camera is capable.
I have set the resolution using the following command which works.
v4l2-ctl --device=/dev/video1 --set-fmt-video=width=1280,height=720
but when I set the fps to 60, the max limit seem to be 30.
mendel#mocha-calf:~$ v4l2-ctl --device=/dev/video1 -p 60
Frame rate set to 30.000 fps
There are no option to set exposure or gain. Would I have to rebuild the driver to be able to have these options?
Regards
Paul
60 FPS not supported. Please see the supported formats below.
mendel#tuned-rabbit:~$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
[0]: 'YUYV' (YUYV 4:2:2)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 720x480
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1920
And for changing/setting exposure and gain, you may need to make modifications in the current driver code and rebuild the kernel image. Driver code can be found at:
https://coral.googlesource.com/linux-imx/+/refs/heads/master/drivers/media/platform/mxc/capture/ov5645_mipi_v2.c#2774
And instructions to build the kernel image can be seen at : https://coral.googlesource.com/docs/+/refs/heads/master/GettingStarted.md

Rigaya's NVEnc encodes file with no video or audio track

My source video file (1h 30min movie) is playable in both PotPlayer and VLC: h264, 8-bit color and 7755kb/s bitrate.
The NVEnc command I'm using is this:
.\nvencc\NVEncC64.exe --avhw -i "input.mkv" --codec hevc --preset quality --bframes 4 --ref 7 --cu-max 32 --cu-min 8 --output-depth 10 --audio-copy --sub-copy -o "output.mkv"
Encoding works fine (I believe):
NVEncC (x64) 5.26 (r1786) by rigaya, Jan 31 2021 09:23:04 (VC 1928/Win/avx2)
OS Version Windows 10 x64 (19042)
CPU AMD Ryzen 5 1600 Six-Core Processor [3.79GHz] (6C/12T)
GPU #0: GeForce GTX 1660 (1408 cores, 1830 MHz)[PCIe3x16][457.51]
NVENC / CUDA NVENC API 11.0, CUDA 11.1, schedule mode: auto
Input Buffers CUDA, 21 frames
Input Info avcuvid: H.264/AVC, 1920x800, 24000/1001 fps
AVSync vfr
Vpp Filters cspconv(nv12 -> p010)
Output Info H.265/HEVC main10 # Level auto
1920x800p 1:1 23.976fps (24000/1001fps)
avwriter: hevc, eac3, subtitle#1 => matroska
Encoder Preset quality
Rate Control CQP I:20 P:23 B:25
Lookahead off
GOP length 240 frames
B frames 4 frames [ref mode: disabled]
Ref frames 7 frames, MultiRef L0:auto L1:auto
AQ off
CU max / min 32 / 8
Others mv:auto
encoded 142592 frames, 219.97 fps, 1549.90 kbps, 1098.83 MB
encode time 0:10:48, CPU: 8.7%, GPU: 5.2%, VE: 98.3%, VD: 21.5%, GPUClock: 1966MHz, VEClock: 1816MHz
frame type IDR 595
frame type I 595, avgQP 20.00, total size 39.44 MB
frame type P 28519, avgQP 23.00, total size 471.93 MB
frame type B 113478, avgQP 25.00, total size 587.45 MB
but when I try to play it in either PotPlayer or VLC it says there is no video track or it just doesn't play at all.
MediaInfo also doesn't show any video, audio, or subtitle tracks either, just the name of the file and the file size. Am I missing something?
Switching --avhw to --avsw solved the problem.

Safari progress bar incomplete on HLS stream

I'm transcoding videos to HLS and am able to validate the stream via:
$mediastreamvalidator <url-to-master-playlist.m3u8>
Mediastreamvalidator gives no errors and all segments seem ok.
However on many videos the progress bar contains a small white/unloaded segment which never changes despite the video segments fully loading. Does this have to do with my encoding properties?
Here is the mediastreamvalidator output for one of the errant segments:
Processed 3 out of 3 segments
Average segment duration: 3.686918
Total segment bitrates (all discontinuities): average: 2293.51 kb/s, max: 2562.78 kb/s
Playlist max bitrate: 2374.000000 kb/s
Audio Group ID: AUDIO
Discontinuity: sequence: 0, parsed segment count: 3 of 3, duration: 11.061 sec, average: 2293.51 kb/s, max: 2562.78 kb/s
Track ID: 1
Audio Codec: AAC-LC
Audio sample rate: 44100 Hz
Audio channel layout: Stereo (L R)
Track ID: 2
Video Codec: avc1
Video profile: Main
Video level: 3.1
Video resolution: 480x360
Video average IDR interval: 3.409137, Standard deviation: 0.000005
Video frame rate: 26.400

Determine if a file is a valid video quickly

What is the fastest way to determine if a file is playable video? I am not concerned with it being corrupt or not but just whether it is a mime-type that should be playable on the iPad.
I have played with pushing the file through a NSURL as suggested by another question but that can take > 1 second per file which is too slow.
I am currently looking at the file extension but would much rather have something that is more certain.
update
I would love to use UTIs internally to the app but I have not found any exposed way to come at it from that direction either. If anyone knows of a way to get at the UTI of a file on 3.2 that would work.
The file(1) command (and associated libmagic) can do this job on standard Unix systems; if Apple didn't include it into the phone OS, you can probably get it to run on the phone yourself. (On my x86-64 Linux system, the library is 109k.)
On my computer, it classified 146 easily-accessible videos into 18 different formats in under seven seconds. (120 gigabytes.) It got some wrong:
$ sort -u /tmp/out
data
ISO Media, MPEG v4 system, version 1
Matroska data
Microsoft ASF
MPEG transport stream data
RIFF (little-endian) data, AVI, 384 x 240, 25.00 fps, video: DivX 5, audio: MPEG-1 Layer 3 (mono, 44100 Hz)
RIFF (little-endian) data, AVI, 384 x 288, 25.00 fps, video: DivX 3 Low-Motion, audio: DivX (stereo, 44100 Hz)
RIFF (little-endian) data, AVI, 512 x 272, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 512 x 288, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 44100 Hz)
RIFF (little-endian) data, AVI, 512 x 288, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 512 x 328, 25.00 fps, video: DivX 5, audio: MPEG-1 Layer 3 (stereo, 32000 Hz)
RIFF (little-endian) data, AVI, 512 x 328, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 32000 Hz)
RIFF (little-endian) data, AVI, 572 x 304, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 576 x 320, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 608 x 336, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 624 x 352, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 640 x 352, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
TeX font metric data (\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377
At those speeds, perhaps you can tolerate a little noise and fall back to a slower mechanism; or perhaps fill out the rules with formats it doesn't yet know.
Read the header and look for codec details?
Mediainfo is an opensource video file info analyser
Sorry don't know any ipad specific stuff
I'd say what you need to do is get the UTI of the file, which on the desktop would be done using LaunchServices. I don't know if apple exposed an API to do so on iOS.
On top of checking the file extension, should you not be able to simply play the file and the movie player object will signal to the delegate that it could not be played? Or in the worst case you can try a nasty try/catch.
In general, the first few bytes of the file will tell you the file type. That's what libmagic and the file command do. If you don't want to build libmagic on iOS, you could simply look at what it's doing, and pull in the subset of the lookup table that you care about.

codes to convert from avi to asf

No matter what library/SDK to use, I want to convert from avi to asf very quickly (I could even sacrifice some quality of video and audio). I am working on Windows platform (Vista and 2008 Server), better .Net SDK/code, C++ code is also fine. :-)
I learned from the below link, that there could be a very quick way to convert from avi to asf to support streaming better, as mentioned "could convert the video from AVI to ASF format using a simple copy (i.e. the content is the same, but container changes).". My question is after some hours of study and trial various SDK/tools, as a newbie, I do not know how to begin with so I am asking for reference sample code to do this task. :-)
(as this is a different issue, we decide to start a new topic. :-) )
Issue with streaming AVI files
thanks in advance,
George
EDIT 1:
I have tried to get the binary of ffmpeg from,
http://ffmpeg.arrozcru.org/autobuilds/ffmpeg-latest-mingw32-static.tar.bz2
then run the following command,
C:\software\ffmpeg-latest-mingw32-static\bin>ffmpeg.exe -i test.avi -acodec copy
-vcodec copy test.asf
FFmpeg version SVN-r18506, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-memalign-hack --prefix=/mingw --cross-prefix=i686-ming
w32- --cc=ccache-i686-mingw32-gcc --target-os=mingw32 --arch=i686 --cpu=i686 --e
nable-avisynth --enable-gpl --enable-zlib --enable-bzlib --enable-libgsm --enabl
e-libfaac --enable-pthreads --enable-libvorbis --enable-libmp3lame --enable-libo
penjpeg --enable-libtheora --enable-libspeex --enable-libxvid --enable-libfaad -
-enable-libschroedinger --enable-libx264
libavutil 50. 3. 0 / 50. 3. 0
libavcodec 52.25. 0 / 52.25. 0
libavformat 52.32. 0 / 52.32. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0. 7. 1 / 0. 7. 1
built on Apr 14 2009 04:04:47, gcc: 4.2.4
Input #0, avi, from 'test.avi':
Duration: 00:00:44.86, start: 0.000000, bitrate: 5291 kb/s
Stream #0.0: Video: msvideo1, rgb555le, 1280x1024, 5 tbr, 5 tbn, 5 tbc
Stream #0.1: Audio: pcm_s16le, 22050 Hz, mono, s16, 352 kb/s
Output #0, asf, to 'test.asf':
Stream #0.0: Video: CRAM / 0x4D415243, rgb555le, 1280x1024, q=2-31, 1k tbn,
5 tbc
Stream #0.1: Audio: pcm_s16le, 22050 Hz, mono, s16, 352 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 224 fps=222 q=-1.0 Lsize= 29426kB time=44.80 bitrate=5380.7kbits/s
video:26910kB audio:1932kB global headers:0kB muxing overhead 2.023317%
C:\software\ffmpeg-latest-mingw32-static\bin>
http://www.microsoft.com/windows/windowsmedia/player/webhelp/default.aspx?&mpver=11.0.6001.7000&id=C00D11B1&contextid=230&originalid=C00D36E6
then have the following error when using Windows Media Player to play it, does anyone have any ideas?
http://www.microsoft.com/windows/windowsmedia/player/webhelp/default.aspx?&mpver=11.0.6001.7000&id=C00D11B1&contextid=230&originalid=C00D36E6
Maybe you could use FFMPEG and run a command like this (I haven't tried):
ffmpeg.exe -i test.avi -acodec copy -vcodec copy test.asf