Skip to content
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

Problem with h264_v4l2m2m #1

Open
ForsakenNGS opened this issue Feb 10, 2022 · 4 comments
Open

Problem with h264_v4l2m2m #1

ForsakenNGS opened this issue Feb 10, 2022 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ForsakenNGS
Copy link
Owner

In some cases (mainly observed when streaming to one of my tablets) plex will set the option -segment_format matroska which will cause the encoding to fail if h264_v4l2m2m is used instead of libx264.

Commandline example:

ffmpeg -codec:0 hevc -analyzeduration 20000000 -probesize 20000000 -i '/path/to/my/video.mkv' 
  -filter_complex '[0:0]scale=w=1920:h=1080:force_divisible_by=4[0];[0]format=pix_fmts=yuv420p|nv12[1]' -map '[1]' -metadata:s:0 language=jpn 
  -codec:0 h264_v4l2m2m -crf:0 10 -maxrate:0 50M -bufsize:0 10M -r:0 23.809999999999999 -preset:0 veryfast -level:0 4.0 
  -x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none 
  -force_key_frames:0 'expr:gte(t,n_forced*1)' -map 0:1 -metadata:s:1 language=jpn -codec:1 copy -copypriorss:1 0 
  -segment_format matroska -f ssegment -individual_header_trailer 0 -flags +global_header -segment_header_filename header 
  -segment_time 1 -segment_start_number 0 -segment_copyts 1 -segment_time_delta 0.0625 
  -segment_list 'http://127.0.0.1:32400/video/:/transcode/session/somehash-com-plexapp-android/sessionid/manifest?X-Plex-Http-Pipeline=infinite' 
  -segment_list_type csv -segment_list_size 5 -segment_list_separate_stream_times 1 -segment_list_unfinished 1 
  -segment_format_options output_ts_offset=10 -max_delay 5000000 -avoid_negative_ts disabled -map_metadata:g -1 
  -map_metadata:c -1 -map_chapters -1 media-%05d.ts -start_at_zero -copyts -vsync cfr -y -nostats -loglevel_plex error 
  -progressurl http://127.0.0.1:32400/video/:/transcode/session/somehash-com-plexapp-android/sessionid/progress

The output is the following:

[h264_v4l2m2m @ 0x2344880] Using device /dev/video11
[h264_v4l2m2m @ 0x2344880] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x2344880] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x2344880] Failed to set gop size: Invalid argument
[stream_segment,ssegment @ 0x38bf3d0] Opening 'header' for writing
Output #0, stream_segment,ssegment, to 'media-%05d.ts':
  Metadata:
    encoder         : Lavf58.65.101
    Stream #0:0(jpn): Video: h264, yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.81 fps, 1k tbn (default)
    Metadata:
      encoder         : Lavc58.117.101 h264_v4l2m2m
    Stream #0:1(jpn): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
    Metadata:
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      title           : Japanese (FUNIMATION)
      BPS             : 256000
      DURATION        : 00:23:40.117000000
      NUMBER_OF_FRAMES: 66568
      NUMBER_OF_BYTES : 45443755
      _STATISTICS_WRITING_APP: mkvmerge v61.0.0 ('So') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2021-12-20 12:39:52
av_interleaved_write_frame(): Invalid data found when processing input
Error writing trailer of media-%05d.ts: Invalid data found when processing input
frame=    2 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=   0x    
video:0kB audio:16kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

When running the exact same commandline and only swapping out h264_v4l2m2m for libx264 everything works fine.

@ForsakenNGS ForsakenNGS added bug Something isn't working help wanted Extra attention is needed labels Feb 10, 2022
@tmm1
Copy link

tmm1 commented Feb 10, 2022

You can try adding -bsf:v h264_mp4toannexb

ForsakenNGS pushed a commit that referenced this issue Feb 10, 2022
@ForsakenNGS
Copy link
Owner Author

You can try adding -bsf:v h264_mp4toannexb

Thanks for the tip. Unfortunally that did not help. I now implemented the feature to remove arguments and just removed -segment_format matroska alltogether. I'm not sure why plex sets this option in this case, so unfortunally this could have consequences I am not aware of. For now it is certainly better than a non-working transcode I guess :D

@ForsakenNGS ForsakenNGS removed the bug Something isn't working label Feb 10, 2022
@ForsakenNGS
Copy link
Owner Author

This definitly needs a cleaner solution. When trying to download the episode I get the same error for the commandline

ffmpeg -codec:0 hevc -analyzeduration 20000000 -probesize 20000000 -i '/path/to/my/video.mkv' -map_inlineass 0:2 
  -filter_complex '[0:0]scale=w=1920:h=1080:force_divisible_by=4[0];[0]format=pix_fmts=yuv420p|nv12[1];[1]inlineass=font_scale=1.000000:font_path=/usr/lib/plexmediaserver/Resources/Fonts/NotoSans-Medium.otf:fontconfig_file=/usr/lib/plexmediaserver/Resources/fonts.conf:language=en[2]' 
  -map '[2]' -metadata:s:0 language=jpn -codec:0 h264_v4l2m2m -crf:0 10 -maxrate:0 50M -bufsize:0 10M -r:0 23.975999999999999 -preset:0 veryfast -level:0 5.2 
  -x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none -map 0:1 
  -metadata:s:1 language=jpn -codec:1 copy -copypriorss:1 0 -f matroska -map_metadata -1 -map_chapters -1 Output.mkv 
  -map 0:2 -f null -codec ass nullfile -y -nostats -loglevel quiet -loglevel_plex error 
  -progressurl http://127.0.0.1:32400/video/:/transcode/session/sessionid/sessionid/progress

@ForsakenNGS ForsakenNGS added the bug Something isn't working label Feb 11, 2022
@ForsakenNGS
Copy link
Owner Author

ForsakenNGS commented Feb 11, 2022

For now I replaced the offending flags by -segment_format mpegts and -f mpegts respectively, that does seem to work in most cases. Yet I still consider this an issue. Most likely this will have impact on the available features like multiple audio-streams, subtitles, meta-data and similar things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants