Skip to content

Videos: Add transcoding config options #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tommcc opened this issue Dec 13, 2020 · 157 comments
Closed

Videos: Add transcoding config options #703

tommcc opened this issue Dec 13, 2020 · 157 comments
Assignees
Labels
idea Feedback wanted / feature request please-test Ready for acceptance test priority Supported by early sponsors or popular demand video Video Formats, Transcoding, FFmpeg, Streaming & Co

Comments

@tommcc
Copy link

tommcc commented Dec 13, 2020

Anytime I browse the library and hit new live photos taken with an iPhone, I end up with gray squares, spinners, and then many (4-8?) ffmpeg processes start up and completely choke my modest PC home server's CPU for 5-15 minutes. Even when uncached thumbnail generation is turned off, processing live photo videos seems to always happen on-demand. This has made a previously satisfactory PhotoPrism instance barely usable.

According to @lastzero in Gitter:

When photoprism doesn't know the codec it transcodes via ffmpeg which needs a lot of cpu
If we do this upfront, users will complain because of the storage it uses.

Proposal 1 - two new config options

Assuming there are two potential issues with live video transcoding (extra disk space used if up-front, and CPU bottleneck on less powerful servers if generated on the spot), a pair of new config options, along with default the live photo feature to "off", might fit most consistently with the existing options.

PHOTOPRISM_LIVE_PHOTO_TRANSCODE - decides whether these videos are transcoded at all. If true, converts and caches them during indexing/importing. Default: false (saves disk for those who don't need the live photo feature at all)

PHOTOPRISM_LIVE_PHOTO_TRANSCODE_UNCACHE - if true, transcodes on demand (and either saves them or not? Don't know what's best here). Default: false (saves CPU for those who don't need the feature at all)

Setting either to true would enable live photos, depending on whether disk or CPU is more important, while avoiding the performance and disk space issues if left off. Open to any feedback on this idea!

Proposal 2 - live photo transcoding should respect workers option

It seems like the values of the WORKERS option didn't affect how many ffmpeg processes I saw started at once. If it did, I could set it to 1, and my dual-core server may continue to respond to requests even while slowly generating live videos on demand.

@lastzero
Copy link
Member

Good news: I've enabled the mutex for rendering videos so that only one video is transcoded at a time. Also make sure you have JSON sidecar files enabled as exiftool is used by PhotoPrism to detect the (supposed) codec.

PhotoPrism can't directly decode Video-Metadata yet as that is beyond our (initial) scope... safe to assume we're also going to provide a complete video management solution one day 🥇

@lastzero lastzero changed the title Avoid CPU bottleneck when transcoding live photo videos Config: Add video transcoding options Dec 13, 2020
@lastzero lastzero added the idea Feedback wanted / feature request label Dec 13, 2020
@lastzero
Copy link
Member

@lastzero lastzero self-assigned this Dec 13, 2020
@lastzero lastzero changed the title Config: Add video transcoding options Videos: Add transcoding config options Dec 13, 2020
@tommcc
Copy link
Author

tommcc commented Dec 13, 2020

Thanks @lastzero for the improvement! While I know feature creep is real, I'm glad videos are included, even if their integration is forever minimal. Since the app is providing access to precious memories, it's nice to be able to click to all records of these moments, instead of having to access videos using an entirely different method.

I can confirm that only one ffmpeg process is starting at a time now. While my server is definitely more responsive, unfortunately, the transcoding still effectively blocks browsing for me.

I'm not familiar enough with the code side of this project, but from the outside it seems that if a block of items loading via endless scroll includes an on-demand transcode, the entire chunk is blocked until it finishes. That means all photos from that batch continue to be gray spinners.

I'm sure there are more incremental improvements that can be made on this problem, and I appreciate the swift response!

@tommcc
Copy link
Author

tommcc commented Dec 13, 2020

I should note, the UI blocking I'm talking about refers to loading thumbnail images. After your update, I can now easily click to see individual photos, and switch to other pages in the app easily, so it's a definite improvement. It's just an issue of not being able to continue browsing thumbnails unless 100% of the live photo videos have been cached.

@Stokel
Copy link

Stokel commented Jan 26, 2021

I would really like the option to be able to tell photoprism to transcode and cache every live photo and mov video in advance.
As it stands right now I have to wait for every live video to be transcoded for several seconds, even when I'm running photoprism on my Laptop with an i7. Videos take a really long time to be transcoded and I don't even want to look at them via photoprism. Being able to transcode everything in advance would solve these issues for me as space is not really a problem.

@lastzero
Copy link
Member

You may sponsor this issue so that we can move it to Upcoming ⏳ on our Roadmap.

@alexislefebvre
Copy link
Contributor

PHOTOPRISM_LIVE_PHOTO_TRANSCODE - decides whether these videos are transcoded at all. If true, converts and caches them during indexing/importing. Default: false (saves disk for those who don't need the live photo feature at all)

PHOTOPRISM_LIVE_PHOTO_TRANSCODE_UNCACHE - if true, transcodes on demand (and either saves them or not? Don't know what's best here). Default: false (saves CPU for those who don't need the feature at all)

I think LIVE_PHOTO is confusing, PHOTOPRISM_VIDEO_TRANSCODE and PHOTOPRISM_VIDEO_TRANSCODE_UNCACHE would be easier to understand.

@alexislefebvre
Copy link
Contributor

Here is a workaround to disable video transcoding, by overwriting the path fo ffmpeg:

PHOTOPRISM_FFMPEG_BIN: /dev/null

@david1155
Copy link

It would be great to have feature to cache converted videos/Live Photos during indexing.

@JackyRen
Copy link

JackyRen commented Feb 5, 2021

For transcoding,
FFmpeg support a large variety of Hardware acceleration
In my Jellyfin setup, Intel G4560 can transcode 4K HEVC to 1080p realtime for 30fps with very small CPU usage.
Because its HD610 supports hardware decoding of HEVC and encoding of H264
CPU only decode and encode only get 5fps.
VAAPI should be the one most easy to use, just bind /dev/dri into docker.

With help of proper graphics hardware, transcoding can be much easier,
even a raspberry pi can beat i7 CPU before 7th gen on decoding HEVC.

If grahpics card not available on the server, especially for VPS setup,
I think a method that allow other devices, like a laptop to generate sidecar for video files can help a lot.
And disable video transcoding on server, it is not worthy to freeze the server for 10 minutes for a video that cannot be viewed immediately.

@Stokel
Copy link

Stokel commented Feb 5, 2021

I have an i7-8550U and just mapped the /dev/dri directory into my photoprism docker container, but it doesn't seem to make a difference.
Do I have to change a setting somewhere for FFmpeg inside photoprism to properly use the hardware acceleration or use a subfolder inside /dev/dri?

@JackyRen
Copy link

JackyRen commented Feb 5, 2021

Extra flags needed to use hardware acceleration, please see Jellyfin's Hardware Acceleration for detailed explanation

Also the user runs ffmpeg should be in group video or render.

Photoprism construct ffmpeg command here, Changes can be made with help of Example usages of ffmpeg VAAPI or QuickSync

I have an i7-8550U and just mapped the /dev/dri directory into my photoprism docker container, but it doesn't seem to make a difference.
Do I have to change a setting somewhere for FFmpeg inside photoprism to properly use the hardware acceleration or use a subfolder inside /dev/dri?

@david1155
Copy link

Photoprism construct ffmpeg command here
Thank you very much for explanation. Is there a way to change command and keep photoprism updated to latest version with watchtower?

@lastzero
Copy link
Member

lastzero commented Feb 8, 2021

@david1155
Copy link

Thank you. As I understand, to enable hardware video rendering for ffmpeg, I have to change source code. If I change source code, how to make this changes persistent after automated updates to new versions?

Maybe I should propose to add feature- to add variable to docker-compose where to specify ffmpeg command line options?

@lastzero
Copy link
Member

lastzero commented Feb 8, 2021

We'll add more config params as soon as possible... just can't do everything at the same time :)

@alexislefebvre
Copy link
Contributor

Thank you. As I understand, to enable hardware video rendering for ffmpeg, I have to change source code. If I change source code, how to make this changes persistent after automated updates to new versions?

This should work with PHOTOPRISM_FFMPEG_BIN: https://docs.photoprism.org/getting-started/config-options/

@JackyRen
Copy link

JackyRen commented Feb 8, 2021

It's possible to use PHOTOPRISM_FFMPEG_BIN to inject extra flags . Because it seems this flags is only used by converting video.
Screen Shot 2021-02-08 at 8 22 32 AM

@lastzero
Copy link
Member

lastzero commented Feb 8, 2021

Needs more work. We also use ffmpeg to render preview images.

@lastzero
Copy link
Member

lastzero commented Feb 8, 2021

Anyone willing to sponsor this with a golden label?

@lastzero
Copy link
Member

You may also try reducing the bitrate for 4K, Pi might just be too slow for 50M.

@inthreedee
Copy link

Thanks for the ideas. I’ve tried them and still have others to try. After re-reading through this thread, I see that I’m just running into the same issue @uxusoft had with 4K videos (#703 (comment)). ffmpeg hangs and Photoprism is unable to recover.

Seems to be a ffmpeg problem that may eventually get resolved upstream.

@lastzero
Copy link
Member

Added one more config option for you - let's leave it at that for now please 👯

@david1155
Copy link

david1155 commented Feb 17, 2021

$ dmesg

[29291.774465] bcm2835-codec bcm2835-codec: dma_alloc_coherent of size 2334720 failed
[29291.785512] cma: cma_alloc: alloc failed, req-size: 192 pages, ret: -16
[29291.794249] cma: cma_alloc: alloc failed, req-size: 192 pages, ret: -16
[29291.802120] cma: cma_alloc: alloc failed, req-size: 192 pages, ret: -16
[29291.809939] cma: cma_alloc: alloc failed, req-size: 192 pages, ret: -16
[29291.817966] cma: cma_alloc: alloc failed, req-size: 192 pages, ret: -16
[29291.825869] cma: cma_alloc: alloc failed, req-size: 192 pages, ret: -16
[29291.833689] cma: cma_alloc: alloc failed, req-size: 192 pages, ret: -16
[29291.880737] bcm2835-codec bcm2835-codec: dma_alloc_coherent of size 786432 failed
[31701.267469] cma_alloc: 21 callbacks suppressed
[31701.267512] cma: cma_alloc: alloc failed, req-size: 760 pages, ret: -12
[31701.276948] cma: cma_alloc: alloc failed, req-size: 760 pages, ret: -12
[31701.291186] warn_alloc: 1 callbacks suppressed
[31701.291202] ffmpeg: page allocation failure: order:10, mode:0xcc1(GFP_KERNEL|GFP_DMA), nodemask=(null),cpuset=8575f20f664fd5b911863d5bc8d3ddbedc7ff996b56907ddc510cd84612df956,mems_allowed=0
[31701.291227] CPU: 1 PID: 5220 Comm: ffmpeg Tainted: G         C  E     5.8.0-1015-raspi #18-Ubuntu
[31701.291229] Hardware name: Raspberry Pi 4 Model B Rev 1.4 (DT)
[31701.291233] Call trace:
[31701.291247]  dump_backtrace+0x0/0x1f0
[31701.291251]  show_stack+0x24/0x30
[31701.291259]  dump_stack+0xec/0x168
[31701.291264]  warn_alloc+0x108/0x170
[31701.291268]  __alloc_pages_slowpath.constprop.0+0x7b4/0x7d0
[31701.291271]  __alloc_pages_nodemask+0x2c8/0x340
[31701.291277]  __dma_direct_alloc_pages+0x16c/0x25c
[31701.291280]  dma_direct_alloc_pages+0x154/0x280
[31701.291283]  dma_direct_alloc+0x1c/0x30
[31701.291286]  dma_alloc_attrs+0x88/0xf4
[31701.291301]  vb2_dc_alloc+0x7c/0x150 [videobuf2_dma_contig]
[31701.291313]  __vb2_buf_mem_alloc+0x5c/0x130 [videobuf2_common]
[31701.291320]  __vb2_queue_alloc+0x134/0x33c [videobuf2_common]
[31701.291326]  vb2_core_reqbufs+0x244/0x41c [videobuf2_common]
[31701.291333]  vb2_reqbufs+0x6c/0x90 [videobuf2_v4l2]
[31701.291343]  v4l2_m2m_ioctl_reqbufs+0x44/0x74 [v4l2_mem2mem]
[31701.291371]  v4l_reqbufs+0x58/0x70 [videodev]
[31701.291390]  __video_do_ioctl+0x190/0x3f0 [videodev]
[31701.291408]  video_usercopy+0x19c/0x570 [videodev]
[31701.291425]  video_ioctl2+0x24/0x80 [videodev]
[31701.291442]  v4l2_ioctl+0x4c/0x70 [videodev]
[31701.291446]  ksys_ioctl+0xb4/0xf4
[31701.291449]  __arm64_sys_ioctl+0x2c/0xbc
[31701.291453]  el0_svc_common.constprop.0+0x84/0x200
[31701.291455]  do_el0_svc+0x30/0xa0
[31701.291460]  el0_svc+0x18/0x50
[31701.291463]  el0_sync_handler+0x98/0x354
[31701.291466]  el0_sync+0x17c/0x180
[31701.291470] Mem-Info:
[31701.291482] active_anon:339590 inactive_anon:120553 isolated_anon:0
                active_file:68934 inactive_file:1343126 isolated_file:0
                unevictable:6019 dirty:8 writeback:1
                slab_reclaimable:31059 slab_unreclaimable:16384
                mapped:25795 shmem:1221 pagetables:2571 bounce:0
                free:16856 free_pcp:890 free_cma:183
[31701.291490] Node 0 active_anon:1358360kB inactive_anon:482212kB active_file:275736kB inactive_file:5372504kB unevictable:24076kB isolated(anon):0kB isolated(file):0kB mapped:103180kB dirty:32kB writeback:4kB shmem:4884kB writeback_tmp:0kB all_unreclaimable? no
[31701.291501] DMA free:22968kB min:1132kB low:1928kB high:2724kB reserved_highatomic:0KB active_anon:6800kB inactive_anon:1828kB active_file:52948kB inactive_file:663196kB unevictable:2184kB writepending:4kB present:917504kB managed:831384kB mlocked:2384kB kernel_stack:336kB pagetables:376kB bounce:0kB free_pcp:1292kB local_pcp:1292kB free_cma:732kB
[31701.291503] lowmem_reserve[]: 0 3008 6947 6947
[31701.291517] DMA32 free:33988kB min:4376kB low:7456kB high:10536kB reserved_highatomic:0KB active_anon:178740kB inactive_anon:3000kB active_file:115608kB inactive_file:2692992kB unevictable:1720kB writepending:16kB present:3080192kB managed:3080192kB mlocked:1720kB kernel_stack:984kB pagetables:1444kB bounce:0kB free_pcp:1676kB local_pcp:0kB free_cma:0kB
[31701.291520] lowmem_reserve[]: 0 0 3939 3939
[31701.291534] Normal free:10468kB min:5732kB low:9764kB high:13796kB reserved_highatomic:4096KB active_anon:1172360kB inactive_anon:477384kB active_file:107328kB inactive_file:2016708kB unevictable:19780kB writepending:16kB present:4194304kB managed:4033756kB mlocked:19780kB kernel_stack:5160kB pagetables:8464kB bounce:0kB free_pcp:604kB local_pcp:0kB free_cma:0kB
[31701.291536] lowmem_reserve[]: 0 0 0 0
[31701.291545] DMA: 258*4kB (UEC) 159*8kB (UMEC) 102*16kB (UEC) 110*32kB (UMEC) 28*64kB (UME) 21*128kB (UME) 5*256kB (UE) 7*512kB (UMEC) 2*1024kB (ME) 2*2048kB (UE) 0*4096kB = 22944kB
[31701.291575] DMA32: 778*4kB (UME) 881*8kB (UME) 309*16kB (UME) 594*32kB (UM) 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 34112kB
[31701.291597] Normal: 406*4kB (UMEH) 276*8kB (UMEH) 240*16kB (UMEH) 98*32kB (UMEH) 15*64kB (MH) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 11768kB
[31701.291621] 1400801 total pagecache pages
[31701.291635] 234 pages in swap cache
[31701.291639] Swap cache stats: add 4990, delete 4756, find 237/710
[31701.291643] Free swap  = 16761852kB
[31701.291646] Total swap = 16777212kB
[31701.291649] 2048000 pages RAM
[31701.291652] 0 pages HighMem/MovableOnly
[31701.291655] 61667 pages reserved
[31701.291658] 16384 pages cma reserved

https://github.com/raspberrypi/linux/issues/3390

@david1155
Copy link

david1155 commented Feb 17, 2021

add cma=2048M to the end of /boot/firmware/cmdline.txt to fix ffmpeg memory issues

$ grep Cma /proc/meminfo

@inthreedee
Copy link

@uxusoft CMA is new to me. Looking into it a bit, seems there are some other config options that are needed to enable CMA, and then there are two cma options to be set, a low and a high value. I haven't played with this yet but will see if it makes a difference this weekend.
https://elinux.org/RPiconfig#CMA_-_dynamic_memory_split

MA dynamically allocates memory to the GPU as required. When the amount of free memory available to the GPU falls below the 'low water mark' (cma_lwm), CMA will attempt to re-allocate some of the memory currently available to the ARM to be instead reserved for the GPU. You can think of this as 'minimum free memory' for the GPU.

If the GPU later frees up some resources and finds itself with additional memory available above the 'high water mark' (cma_hwm), the excess memory will be allocated instead to the ARM. You can think of this as 'maximum free memory' for the GPU.
https://raspberrypi.stackexchange.com/questions/7482/how-is-memory-split-by-cma

@lastzero
Copy link
Member

Would one of you like to contribute hardware transcoding docs for our Advanced section in Getting Started?

https://docs.photoprism.org/getting-started/advanced/scalability/

@inthreedee
Copy link

@uxusoft Could you please share your config.txt and cmdline.txt contents? I don't get cma errors anymore, but I'm still trying to fix this one:
bcm2835-codec: dma_alloc_coherent of size 5529600 failed

It causes ffmpeg to spit out this:

[h264_v4l2m2m @ 0xaaaade56d510] output VIDIOC_REQBUFS failed: Cannot allocate memory
[h264_v4l2m2m @ 0xaaaade56d510] no v4l2 output context's buffers
[h264_v4l2m2m @ 0xaaaade56d510] can't configure encoder
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Increasing cma beyond 2048 doesn't seem to take effect; it gets reset to 0.

@david1155
Copy link

@inthreedee I have the same errors:

[h264_v4l2m2m @ 0xaaaad2a08270] Using device /dev/video11
[h264_v4l2m2m @ 0xaaaad2a08270] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0xaaaad2a08270] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0xaaaad2a08270] output VIDIOC_REQBUFS failed: Cannot allocate memory
[h264_v4l2m2m @ 0xaaaad2a08270] no v4l2 output context's buffers
[h264_v4l2m2m @ 0xaaaad2a08270] can't configure encoder

Sometime transcoding freezes forever. But overall, there is a huge improvement. Nearly all Live photos are transcoding instantly. For the long videos I do converting to mp4 before upload and it is ready to play instantly.

config.txt:

gpu_mem=128

cmdline.txt

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc quiet splash cma=2048M cma_lwm=16 cma_hwm=32

@david1155
Copy link

@lastzero

Would one of you like to contribute hardware transcoding docs for our Advanced section in Getting Started?

I am happy to contribute. But it seems that maybe that this feature is not ready for production because of memory errors. The problem that it is sometimes hangs with hardware decoding forever and fallback to libx264 does not happen. Maybe we have to wait until ffmpeg stable release that will work without issues.

@lastzero
Copy link
Member

Wouldn't mind starting with the docs before ffmpeg / ubuntu managed to fix all remaining bugs, which may be never... might be up to us to build our own fixed version. HEIF converter makes trouble as well. Never ending story.

@muzzah
Copy link

muzzah commented Feb 23, 2021

Just want to add, video streaming is completely broken for me. Im using a VPS and not a rasberry PI

I see the following output but none of my videos play anymofre

pp-server      | time="2021-02-23T21:45:40Z" level=info msg="converting iPhone/2019/11/19-11-13 12-48-43 4208.mov to avc (h264_v4l2m2m)"
pp-server      | time="2021-02-23T21:45:40Z" level=warning msg="ffmpeg: ffmpeg version 4.3.1-4ubuntu1 Copyright (c) 2000-2020 the FFmpeg developers\n  built with gcc 10 (Ubuntu 10.2.0-9ubuntu2)\n  configuration: --prefix=/usr --extra-version=4ubuntu1 --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-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared\n  WARNING: library configuration mismatch\n  avcodec     configuration: --prefix=/usr --extra-version=4ubuntu1 --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-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-liblensfun --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc\n  libavutil      56. 51.100 / 56. 51.100\n  libavcodec     58. 91.100 / 58. 91.100\n  libavformat    58. 45.100 / 58. 45.100\n  libavdevice    58. 10.100 / 58. 10.100\n  libavfilter     7. 85.100 /  7. 85.100\n  libavresample   4.  0.  0 /  4.  0.  0\n  libswscale      5.  7.100 /  5.  7.100\n  libswresample   3.  7.100 /  3.  7.100\n  libpostproc    55.  7.100 / 55.  7.100\nInput #0, mov,mp4,m4a,3gp,3g2,mj2, from '/photoprism/originals/iPhone/2019/11/19-11-13 12-48-43 4208.mov':\n  Metadata:\n    major_brand     : qt  \n    minor_version   : 0\n    compatible_brands: qt  \n    creation_time   : 2019-11-13T11:48:43.000000Z\n    com.apple.quicktime.location.ISO6709: +41.0659+029.0183+099.375/\n    com.apple.quicktime.make: Apple\n    com.apple.quicktime.model: iPhone 8 Plus\n    com.apple.quicktime.software: 13.1.3\n    com.apple.quicktime.creationdate: 2019-11-13T14:48:43+0300\n  Duration: 00:00:18.20, start: 0.000000, bitrate: 8278 kb/s\n    Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 1920x1080, 8165 kb/s, 30.01 fps, 30 tbr, 600 tbn, 600 tbc (default)\n    Metadata:\n      rotate          : 90\n      creation_time   : 2019-11-13T11:48:43.000000Z\n      handler_name    : Core Media Video\n      encoder         : HEVC\n    Side data:\n      displaymatrix: rotation of -90.00 degrees\n    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 98 kb/s (default)\n    Metadata:\n      creation_time   : 2019-11-13T11:48:43.000000Z\n      handler_name    : Core Media Audio\n    Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)\n    Metadata:\n      creation_time   : 2019-11-13T11:48:43.000000Z\n      handler_name    : Core Media Metadata\n    Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)\n    Metadata:\n      creation_time   : 2019-11-13T11:48:43.000000Z\n      handler_name    : Core Media Metadata\nCodec AVOption crf (Select the quality for constant quality mode) specified for output file #0 (/photoprism/storage/sidecar/iPhone/2019/11/19-11-13 12-48-43 4208.mov.avc) 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.\nStream mapping:\n  Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_v4l2m2m))\n  Stream #0:1 -> #0:1 (aac (native) -> aac (native))\nPress [q] to stop, [?] for help\n[h264_v4l2m2m @ 0x55a578a78500] Could not find a valid device\n[h264_v4l2m2m @ 0x55a578a78500] can't configure encoder\nError initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height\n[aac @ 0x55a578a5a580] Qavg: 8103.546\n[aac @ 0x55a578a5a580] 2 frames left in the queue on closing\nConversion failed!\n"
pp-server      | time="2021-02-23T21:45:40Z" level=info msg="converting iPhone/2019/11/19-11-13 12-48-43 4208.mov to avc (libx264)"
pp-server      | time="2021-02-23T21:46:06Z" level=info msg="converting iPhone/2019/11/19-11-16 13-42-45 4242.mov to avc (h264_v4l2m2m)"
pp-server      | time="2021-02-23T21:46:39Z" level=info msg="converting iPhone/2019/11/19-11-30 14-56-48 4330.mov to avc (h264_v4l2m2m)"

Can you clarify, are these changes targeted at Rasberry PI's? Is on the fly transcoding meant to be improved in anyway or can we request to convert files prior to streaming? Right now I see a regression from before where some videos would play but now none play whatsoever.

@david1155
Copy link

david1155 commented Feb 23, 2021

@muzzah Hi!
You have to pass hardware encoding device into docker or use libx264 instead of h264_v4l2m2m (check config file).
To convert files prior streaming please use "photoprism convert" command.

@inthreedee
Copy link

@muzzah I'm not sure which device you'd need to pass for your setup, but for a RPi, the docker-compose needs:

devices:
 - "/dev/video11:/dev/video11"

Your system logs may give you a clue as to which device it's trying to use. Otherwise, if you try running ffmpeg in debug mode separately from Photoprism, it will cycle through all the devices until it finds one compatible with the h264_v4l2m2m encoder, and from that you'd know which device to pass.

If you know your hardware supports that codec and you've given the container permission for the correct device, then this looks very much like the issue we've been running into where the FFmpeg process freezes, the fallback to libx264 fails to kick in, and transcoding gets broken.

As far as we can tell, it might be an upstream FFmpeg issue. I've yet to have the fallback to libx264 kick in correctly though, so I don't know if that's a problem with the Photoprism fallback code or not.

@muzzah
Copy link

muzzah commented Feb 24, 2021

Thanks for the info, I will look into it but as mentioned Im not using a RPI but a hosted VPS. Im no ffmpeg expert but I looked into the dev fold er but there are no video device since its headless. So I am not sure I will be able to provide a video device, in this situation should I not bother providing a specific codec and just use the libx264 codec?

@inthreedee
Copy link

Yes, it sounds like you should stick with the defaults.

@tautomer
Copy link

tautomer commented Mar 29, 2021

Not sure if I should open a new issue, but is it possible to manually encode a video and tell PhotoPrism to use and stream this video as the transcoded one? The original one is kept alongside as the one going to be downloaded, and this encoded one for playing in the browser.

The main thing is that I'm running the container on a Windows machine on a Celeron N3150... The CPU is pretty weak. The iGPU does have Quick Sync, but currently it's not possible to access the GPU from a container on Windows version Docker. That being said, even if I do photoprism convert, it will still take quite some time to transcode everything.

The workaround I'm thinking is that I can go through all the videos and find HEVC ones or the ones with very high (say 50K) bitrate. Then I encode them on my desktop with ffmpeg and move the original videos outside PhotoPrism library folders. I believe this will allow me to play all my videos, but I will lose the ability to download the original ones if I want to keep the original one locally somehow.

@alexislefebvre
Copy link
Contributor

alexislefebvre commented Mar 29, 2021

A MP4 file with H264 video and AAC audio codecs will be playable without transcoding.

I used this command to convert my files : find ./ -type f ! -regex '.+.mp4$' -exec ffmpeg -i {} -c:v h264 -c:a aac {}.mp4 \; (I removed the original files once I checked that the new files were playable).

@lastzero
Copy link
Member

While we also try to detect the exact codecs, it's best to use .mp4 or .avc as extension for MPEG4 / AVC / AAC files. They don't need transcoding then. We use .avc for sidecar AVC files to avoid naming conflicts with user generated MP4 files - if you write a script, it makes sense to do the same.

@tautomer
Copy link

A MP4 file with H264 video and AAC audio codecs will be playable without transcoding.

I used this command to convert my files : find ./ -type f ! -regex '.+.mp4$' -exec ffmpeg -i {} -c:v h264 -c:a aac {}.mp4 \; (I removed the original files once I checked that the new files were playable).

Indeed! I thought high bitrate H264 ones would have been transcoded as well, but it turns out to be just my impatience. At least all the 50Mbps H264 videos can load without any problem other than a few seconds loading time.

@tautomer
Copy link

tautomer commented Mar 31, 2021

While we also try to detect the exact codecs, it's best to use .mp4 or .avc as extension for MPEG4 / AVC / AAC files. They don't need transcoding then. We use .avc for sidecar AVC files to avoid naming conflicts with user generated MP4 files - if you write a script, it makes sense to do the same.

Nice to know the .avc extension is used for this purpose.

So I converted an HEVC videos to .avc, so I have video.mp4 and video.avc side by side in the folder. Upon I re-indexed the folder, the avc one seems to "overwrote" the original HEVC mp4 in PhotoPrism's database. I mean I can't access the original video anymore through PhotoPrism.
The video properties show that the video is the avc one and I can play it with through the browser, but if I click the download button, it's also this avc being downloaded not the original mp4. The mp4 doesn't have a separate entry either.

Is this the intended behavior? I thin it's ok if this is the case. I would just move the original one outside the folder and completely forget about it.

But thanks for the replies and also @alexislefebvre. At least this is a good workaround for me before I can switch to a Linux host.

@timdonovanuk
Copy link

I don't suppose anyone has got hardware transcoding working on Intel NUCs? I imagine this is too broad of a question as there are lots of different models with lots of different GPUs but wondered if some general advice would work for all (to help others). Cheers!

@alexislefebvre
Copy link
Contributor

@timdonovanuk I suggest to add a new issue or discussion specifically about Intel NUC. A message after a very long thread will easily be missed.

@lastzero lastzero added the video Video Formats, Transcoding, FFmpeg, Streaming & Co label Jul 7, 2022
@lastzero lastzero moved this to Released 🌈 in Roadmap 🚀✨ Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Feedback wanted / feature request please-test Ready for acceptance test priority Supported by early sponsors or popular demand video Video Formats, Transcoding, FFmpeg, Streaming & Co
Projects
Status: Release 🌈
Development

No branches or pull requests