
Recherche avancée
Médias (1)
-
Sintel MP4 Surround 5.1 Full
13 mai 2011, par
Mis à jour : Février 2012
Langue : English
Type : Video
Autres articles (96)
-
Configuration spécifique d’Apache
4 février 2011, parModules spécifiques
Pour la configuration d’Apache, il est conseillé d’activer certains modules non spécifiques à MediaSPIP, mais permettant d’améliorer les performances : mod_deflate et mod_headers pour compresser automatiquement via Apache les pages. Cf ce tutoriel ; mode_expires pour gérer correctement l’expiration des hits. Cf ce tutoriel ;
Il est également conseillé d’ajouter la prise en charge par apache du mime-type pour les fichiers WebM comme indiqué dans ce tutoriel.
Création d’un (...) -
Organiser par catégorie
17 mai 2013, parDans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...) -
Submit bugs and patches
13 avril 2011Unfortunately a software is never perfect.
If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
You may also (...)
Sur d’autres sites (6489)
-
How to get .mp4 videos from motion on a Raspberry Pi ?
3 novembre 2017, par MaartiI use motion on my laptop and it works perfectly in any format. But when I use it on my Raspberry Pi 3 (Raspbian Jessie) with the Raspberry Camera V2, the only formats that work are :
.avi
and.swf
.When I choose any other format, the output video is a "0 sec video" that is played and closed instantly.
I would like to have
.mp4
or.ogg
output so I can read it easily with HTML5.Here is the motion codec documentation.
Here is my config file :
############################################################
# Daemon
############################################################
# Start in daemon (background) mode and release terminal (default: off)
daemon on
# File to store the process ID, also called pid file. (default: not defined)
process_id_file /var/run/motion/motion.pid
############################################################
# Basic Setup Mode
############################################################
# Start in Setup-Mode, daemon disabled. (default: off)
setup_mode off
# Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined)
#logfile /mnt/camshare/Cam1/motion.log
logfile /tmp/motion.log
# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, INF, DBG, ALL). (default: 6 / NTC)
log_level 2
# Filter to log messages by type (COR, STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL)
log_type all
###########################################################
# Capture device options
############################################################
# Videodevice to be used for capturing (default /dev/video0)
# for FreeBSD default is /dev/bktr0
#videodevice /dev/video0
# v4l2_palette allows to choose preferable palette to be use by motion
# to capture from those supported by your videodevice. (default: 17)
# E.g. if your videodevice supports both V4L2_PIX_FMT_SBGGR8 and
# V4L2_PIX_FMT_MJPEG then motion will by default use V4L2_PIX_FMT_MJPEG.
# Setting v4l2_palette to 2 forces motion to use V4L2_PIX_FMT_SBGGR8
# instead.
#
# Values :
# V4L2_PIX_FMT_SN9C10X : 0 'S910'
# V4L2_PIX_FMT_SBGGR16 : 1 'BYR2'
# V4L2_PIX_FMT_SBGGR8 : 2 'BA81'
# V4L2_PIX_FMT_SPCA561 : 3 'S561'
# V4L2_PIX_FMT_SGBRG8 : 4 'GBRG'
# V4L2_PIX_FMT_SGRBG8 : 5 'GRBG'
# V4L2_PIX_FMT_PAC207 : 6 'P207'
# V4L2_PIX_FMT_PJPG : 7 'PJPG'
# V4L2_PIX_FMT_MJPEG : 8 'MJPEG'
# V4L2_PIX_FMT_JPEG : 9 'JPEG'
# V4L2_PIX_FMT_RGB24 : 10 'RGB3'
# V4L2_PIX_FMT_SPCA501 : 11 'S501'
# V4L2_PIX_FMT_SPCA505 : 12 'S505'
# V4L2_PIX_FMT_SPCA508 : 13 'S508'
# V4L2_PIX_FMT_UYVY : 14 'UYVY'
# V4L2_PIX_FMT_YUYV : 15 'YUYV'
# V4L2_PIX_FMT_YUV422P : 16 '422P'
# V4L2_PIX_FMT_YUV420 : 17 'YU12'
#
v4l2_palette 7
# Tuner device to be used for capturing using tuner as source (default /dev/tuner0)
# This is ONLY used for FreeBSD. Leave it commented out for Linux
; tunerdevice /dev/tuner0
# The video input to be used (default: -1)
# Should normally be set to 0 or 1 for video/TV cards, and -1 for USB cameras
input -1
# The video norm to use (only for video capture and TV tuner cards)
# Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default: 0 (PAL)
norm 0
# The frequency to set the tuner to (kHz) (only for TV tuner cards) (default: 0)
frequency 0
# Rotate image this number of degrees. The rotation affects all saved images as
# well as movies. Valid values: 0 (default = no rotation), 90, 180 and 270.
rotate 0
# Image width (pixels). Valid range: Camera dependent, default: 352
#width 1024
width 640
# Image height (pixels). Valid range: Camera dependent, default: 288
#height 576
height 480
# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 15
# Minimum time in seconds between capturing picture frames from the camera.
# Default: 0 = disabled - the capture rate is given by the camera framerate.
# This option is used when you want to capture images at a rate lower than 2 per second.
minimum_frame_time 0
# URL to use if you are using a network camera, size will be autodetected (incl http:// ftp:// mjpg:// or file:///)
# Must be a URL that returns single jpeg pictures or a raw mjpeg stream. Default: Not defined
;netcam_url http://127.0.0.1/cgi-bin/raspicam.sh
# Username and password for network camera (only if required). Default: not defined
# Syntax is user:password
; netcam_userpass value
# The setting for keep-alive of network socket, should improve performance on compatible net cameras.
# off: The historical implementation using HTTP/1.0, closing the socket after each http request.
# force: Use HTTP/1.0 requests with keep alive header to reuse the same connection.
# on: Use HTTP/1.1 requests that support keep alive as default.
# Default: off
netcam_keepalive off
# URL to use for a netcam proxy server, if required, e.g. "http://myproxy".
# If a port number other than 80 is needed, use "http://myproxy:1234".
# Default: not defined
; netcam_proxy value
# Set less strict jpeg checks for network cameras with a poor/buggy firmware.
# Default: off
netcam_tolerant_check off
# Let motion regulate the brightness of a video device (default: off).
# The auto_brightness feature uses the brightness option as its target value.
# If brightness is zero auto_brightness will adjust to average brightness value 128.
# Only recommended for cameras without auto brightness
auto_brightness off
# Set the initial brightness of a video device.
# If auto_brightness is enabled, this value defines the average brightness level
# which Motion will try and adjust to.
# Valid range 0-255, default 0 = disabled
brightness 0
# Set the contrast of a video device.
# Valid range 0-255, default 0 = disabled
contrast 0
# Set the saturation of a video device.
# Valid range 0-255, default 0 = disabled
saturation 0
# Set the hue of a video device (NTSC feature).
# Valid range 0-255, default 0 = disabled
hue 0
############################################################
# File "camera" support - read raw YUV data from a file
############################################################
#filecam_path /home/pi/test-cap/motion-mmal.capture
############################################################
# OpenMax/MMAL camera support for Raspberry Pi
############################################################
mmalcam_name vc.ril.camera
#mmalcam_control_params
#mmalcam_raw_capture_file /home/pi/motion-mmal.capture
# Switch this setting to "on" to use the still image mode of the Pi's camera
# instead of video. This gives a wider field of view, but requires
# a much slower frame-rate to achieve exposure stability
# (e.g. 0.25 fps or slower). You can use the minimum_frame_time
# parameter above to achieve this
mmalcam_use_still off
############################################################
# Round Robin (multiple inputs on same video device name)
############################################################
# Number of frames to capture in each roundrobin step (default: 1)
roundrobin_frames 1
# Number of frames to skip before each roundrobin step (default: 1)
roundrobin_skip 1
# Try to filter out noise generated by roundrobin (default: off)
switchfilter off
############################################################
# Motion Detection Settings:
############################################################
# Threshold for number of changed pixels in an image that
# triggers motion detection (default: 1500)
threshold 1500
# Automatically tune the threshold down if possible (default: off)
threshold_tune off
# Noise threshold for the motion detection (default: 32)
noise_level 32
# Automatically tune the noise threshold (default: on)
noise_tune on
# Despeckle motion image using (e)rode or (d)ilate or (l)abel (Default: not defined)
# Recommended value is EedDl. Any combination (and number of) of E, e, d, and D is valid.
# (l)abeling must only be used once and the 'l' must be the last letter.
# Comment out to disable
despeckle_filter EedDl
# Detect motion in predefined areas (1 - 9). Areas are numbered like that: 1 2 3
# A script (on_area_detected) is started immediately when motion is 4 5 6
# detected in one of the given areas, but only once during an event. 7 8 9
# One or more areas can be specified with this option. Take care: This option
# does NOT restrict detection to these areas! (Default: not defined)
; area_detect value
# PGM file to use as a sensitivity mask.
# Full path name to. (Default: not defined)
; mask_file value
# Dynamically create a mask file during operation (default: 0)
# Adjust speed of mask changes from 0 (off) to 10 (fast)
smart_mask_speed 0
# Ignore sudden massive light intensity changes given as a percentage of the picture
# area that changed intensity. Valid range: 0 - 100 , default: 0 = disabled
lightswitch 0
# Picture frames must contain motion at least the specified number of frames
# in a row before they are detected as true motion. At the default of 1, all
# motion is detected. Valid range: 1 to thousands, recommended 1-5
minimum_motion_frames 1
# Specifies the number of pre-captured (buffered) pictures from before motion
# was detected that will be output at motion detection.
# Recommended range: 0 to 5 (default: 0)
# Do not use large values! Large values will cause Motion to skip video frames and
# cause unsmooth movies. To smooth movies use larger values of post_capture instead.
pre_capture 2
# Number of frames to capture after motion is no longer detected (default: 0)
post_capture 2
# Event Gap is the seconds of no motion detection that triggers the end of an event.
# An event is defined as a series of motion images taken within a short timeframe.
# Recommended value is 60 seconds (Default). The value -1 is allowed and disables
# events causing all Motion to be written to one single movie file and no pre_capture.
# If set to 0, motion is running in gapless mode. Movies don't have gaps anymore. An
# event ends right after no more motion is detected and post_capture is over.
event_gap 60
# Maximum length in seconds of an mpeg movie
# When value is exceeded a new movie file is created. (Default: 0 = infinite)
# ATTENTION: when you're not using the motion build from the tutorial, it might fail with error 'Unknown config option "max_mpeg_time"'
# the use this line instead:
# max_movie_time 60
max_movie_time 60
# Always save images even if there was no motion (default: off)
emulate_motion off
############################################################
# Image File Output
############################################################
# Output 'normal' pictures when motion is detected (default: on)
# Valid values: on, off, first, best, center
# When set to 'first', only the first picture of an event is saved.
# Picture with most motion of an event is saved when set to 'best'.
# Picture with motion nearest center of picture is saved when set to 'center'.
# Can be used as preview shot for the corresponding movie.
output_pictures best
# Output pictures with only the pixels moving object (ghost images) (default: off)
output_debug_pictures off
# The quality (in percent) to be used by the jpeg compression (default: 75)
quality 75
# Type of output images
# Valid values: jpeg, ppm (default: jpeg)
picture_type jpeg
############################################################
# FFMPEG related options
# Film (movies) file output, and deinterlacing of the video input
# The options movie_filename and timelapse_filename are also used
# by the ffmpeg feature
############################################################
# Use ffmpeg to encode movies in realtime (default: off)
ffmpeg_output_movies on
# Use ffmpeg to make movies with only the pixels moving
# object (ghost images) (default: off)
ffmpeg_output_debug_movies off
# Use ffmpeg to encode a timelapse movie
# Default value 0 = off - else save frame every Nth second
ffmpeg_timelapse 0
# The file rollover mode of the timelapse video
# Valid values: hourly, daily (default), weekly-sunday, weekly-monday, monthly, manual
ffmpeg_timelapse_mode daily
# Bitrate to be used by the ffmpeg encoder (default: 400000)
# This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled)
ffmpeg_bps 500000
# Enables and defines variable bitrate for the ffmpeg encoder.
# ffmpeg_bps is ignored if variable bitrate is enabled.
# Valid values: 0 (default) = fixed bitrate defined by ffmpeg_bps,
# or the range 2 - 31 where 2 means best quality and 31 is worst.
ffmpeg_variable_bitrate 5
# Codec to used by ffmpeg for the video compression.
# Timelapse mpegs are always made in mpeg1 format independent from this option.
# Supported formats are: mpeg1 (ffmpeg-0.4.8 only), mpeg4 (default), and msmpeg4.
# mpeg1 - gives you files with extension .mpg
# mpeg4 or msmpeg4 - gives you files with extension .avi
# msmpeg4 is recommended for use with Windows Media Player because
# it requires no installation of codec on the Windows client.
# swf - gives you a flash film with extension .swf
# flv - gives you a flash video with extension .flv
# ffv1 - FF video codec 1 for Lossless Encoding ( experimental )
# mov - QuickTime ( testing )
# ogg - Ogg/Theora ( testing )
#ffmpeg_video_codec msmpeg4
ffmpeg_video_codec mp4
# Use ffmpeg to deinterlace video. Necessary if you use an analog camera
# and see horizontal combing on moving objects in video or pictures.
# (default: off)
ffmpeg_deinterlace off
############################################################
# SDL Window
############################################################
# Number of motion thread to show in SDL Window (default: 0 = disabled)
#sdl_threadnr 0
############################################################
# External pipe to video encoder
# Replacement for FFMPEG builtin encoder for ffmpeg_output_movies only.
# The options movie_filename and timelapse_filename are also used
# by the ffmpeg feature
#############################################################
# Bool to enable or disable extpipe (default: off)
use_extpipe off
# External program (full path and opts) to pipe raw video to
# Generally, use '-' for STDIN...
;extpipe mencoder -demuxer rawvideo -rawvideo w=320:h=240:i420 -ovc x264 -x264encopts bframes=4:frameref=1:subq=1:scenecut=-1:nob_adapt:threads=1:keyint=1000:8x8dct:vbv_bufsize=4000:crf=24:partitions=i8x8,i4x4:vbv_maxrate=800:no-chroma-me -vf denoise3d=16:12:48:4,pp=lb -of avi -o %f.avi - -fps %fps
############################################################
# Snapshots (Traditional Periodic Webcam File Output)
############################################################
# Make automated snapshot every N seconds (default: 0 = disabled)
snapshot_interval 0
############################################################
# Text Display
# %Y = year, %m = month, %d = date,
# %H = hour, %M = minute, %S = second, %T = HH:MM:SS,
# %v = event, %q = frame number, %t = thread (camera) number,
# %D = changed pixels, %N = noise level, \n = new line,
# %i and %J = width and height of motion area,
# %K and %L = X and Y coordinates of motion center
# %C = value defined by text_event - do not use with text_event!
# You can put quotation marks around the text to allow
# leading spaces
############################################################
# Locate and draw a box around the moving object.
# Valid values: on, off, preview (default: off)
# Set to 'preview' will only draw a box in preview_shot pictures.
locate_motion_mode off
# Set the look and style of the locate box if enabled.
# Valid values: box, redbox, cross, redcross (default: box)
# Set to 'box' will draw the traditional box.
# Set to 'redbox' will draw a red box.
# Set to 'cross' will draw a little cross to mark center.
# Set to 'redcross' will draw a little red cross to mark center.
locate_motion_style box
# Draws the timestamp using same options as C function strftime(3)
# Default: %Y-%m-%d\n%T = date in ISO format and time in 24 hour clock
# Text is placed in lower right corner
text_right %d.%m.%Y\n%T
# Draw a user defined text on the images using same options as C function strftime(3)
# Default: Not defined = no text
# Text is placed in lower left corner
; text_left CAMERA %t
text_left HofCam
# Draw the number of changed pixed on the images (default: off)
# Will normally be set to off except when you setup and adjust the motion settings
# Text is placed in upper right corner
text_changes off
# This option defines the value of the special event conversion specifier %C
# You can use any conversion specifier in this option except %C. Date and time
# values are from the timestamp of the first image in the current event.
# Default: %Y%m%d%H%M%S
# The idea is that %C can be used filenames and text_left/right for creating
# a unique identifier for each event.
text_event %Y%m%d%H%M%S
# Draw characters at twice normal size on images. (default: off)
text_double on
# Text to include in a JPEG EXIF comment
# May be any text, including conversion specifiers.
# The EXIF timestamp is included independent of this text.
;exif_text %i%J/%K%L
############################################################
# Target Directories and filenames For Images And Films
# For the options snapshot_, picture_, movie_ and timelapse_filename
# you can use conversion specifiers
# %Y = year, %m = month, %d = date,
# %H = hour, %M = minute, %S = second,
# %v = event, %q = frame number, %t = thread (camera) number,
# %D = changed pixels, %N = noise level,
# %i and %J = width and height of motion area,
# %K and %L = X and Y coordinates of motion center
# %C = value defined by text_event
# Quotation marks round string are allowed.
############################################################
# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
target_dir /home/pi
# File path for snapshots (jpeg or ppm) relative to target_dir
# Default: %v-%Y%m%d%H%M%S-snapshot
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-snapshot
# File extension .jpg or .ppm is automatically added so do not include this.
# Note: A symbolic link called lastsnap.jpg created in the target_dir will always
# point to the latest snapshot, unless snapshot_filename is exactly 'lastsnap'
snapshot_filename %v-%Y%m%d%H%M%S-snapshot
# File path for motion triggered images (jpeg or ppm) relative to target_dir
# Default: %v-%Y%m%d%H%M%S-%q
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-%q
# File extension .jpg or .ppm is automatically added so do not include this
# Set to 'preview' together with best-preview feature enables special naming
# convention for preview shots. See motion guide for details
picture_filename %v-%Y%m%d%H%M%S-%q
# File path for motion triggered ffmpeg films (movies) relative to target_dir
# Default: %v-%Y%m%d%H%M%S
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H%M%S
# File extension .mpg or .avi is automatically added so do not include this
# This option was previously called ffmpeg_filename
movie_filename %v-%Y%m%d%H%M%S
# File path for timelapse movies relative to target_dir
# Default: %Y%m%d-timelapse
# Default value is near equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d-timelapse
# File extension .mpg is automatically added so do not include this
timelapse_filename %Y%m%d-timelapse
############################################################
# Global Network Options
############################################################
# Enable or disable IPV6 for http control and stream (default: off )
ipv6_enabled off
############################################################
# Live Stream Server
############################################################
# The mini-http server listens to this port for requests (default: 0 = disabled)
stream_port 8080
# Quality of the jpeg (in percent) images produced (default: 50)
stream_quality 50
# Output frames at 1 fps when no motion is detected and increase to the
# rate given by stream_maxrate when motion is detected (default: off)
stream_motion on
# Maximum framerate for stream streams (default: 1)
stream_maxrate 4
# Restrict stream connections to localhost only (default: on)
stream_localhost off
# Limits the number of images per connection (default: 0 = unlimited)
# Number can be defined by multiplying actual stream rate by desired number of seconds
# Actual stream rate is the smallest of the numbers framerate and stream_maxrate
stream_limit 0
# Set the authentication method (default: 0)
# 0 = disabled
# 1 = Basic authentication
# 2 = MD5 digest (the safer authentication)
stream_auth_method 0
# Authentication for the stream. Syntax username:password
# Default: not defined (Disabled)
; stream_authentication username:password
############################################################
# HTTP Based Control
############################################################
# TCP/IP port for the http server to listen on (default: 0 = disabled)
webcontrol_port 8081
# Restrict control connections to localhost only (default: on)
webcontrol_localhost off
# Output for http server, select off to choose raw text plain (default: on)
webcontrol_html_output on
# Authentication for the http based control. Syntax username:password
# Default: not defined (Disabled)
; webcontrol_authentication username:password
############################################################
# Tracking (Pan/Tilt)
#############################################################
# Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo)
# The generic type enables the definition of motion center and motion size to
# be used with the conversion specifiers for options like on_motion_detected
track_type 0
# Enable auto tracking (default: off)
track_auto off
# Serial port of motor (default: none)
;track_port /dev/ttyS0
# Motor number for x-axis (default: 0)
;track_motorx 0
# Set motorx reverse (default: 0)
;track_motorx_reverse 0
# Motor number for y-axis (default: 0)
;track_motory 1
# Set motory reverse (default: 0)
;track_motory_reverse 0
# Maximum value on x-axis (default: 0)
;track_maxx 200
# Minimum value on x-axis (default: 0)
;track_minx 50
# Maximum value on y-axis (default: 0)
;track_maxy 200
# Minimum value on y-axis (default: 0)
;track_miny 50
# Center value on x-axis (default: 0)
;track_homex 128
# Center value on y-axis (default: 0)
;track_homey 128
# ID of an iomojo camera if used (default: 0)
track_iomojo_id 0
# Angle in degrees the camera moves per step on the X-axis
# with auto-track (default: 10)
# Currently only used with pwc type cameras
track_step_angle_x 10
[...] -
ffmpeg filename output format
21 août 2024, par Yuval AdamWhen using
ffmpeg
to output a series of frames as images, the only format I can find documentation for isframe_%d.jpg
. The%d
identifier is replaced by the sequential frame count.


Are there other parameters I can use in the output file format ? Specifically, I need the ability to add the timestamp of the specific frame.


-
How to encode images to h264 stream using ffmpeg c api ? [on hold]
8 septembre 2017, par TarhanEdit :
Is it possible to create series of H264 packets (complete NALs with starting code0x00 0x00 0x00 0x01
) in FFMPEG and in memory only without direct usage of libx264 for encoding frames ?
If so how to specify FFMPEG’s format context correctly so I can useAVPacket
’s data without writing to file ?As described below (I’m sorry for a long explanation). When I use only codec context and encode frames using avcodec_send_frame/avcodec_send_frame FFMPEG produce odd output. At least first packet(s) contains header which looks like FFMPEG logo message (hex dump provided below).
Is it possible to receive packets which contains only NALs ? I think FFMPEG birary provide expected output when I encode in file with.h264
extension. So bottom line I need to setup format context and codec context to reproduce FFMPEG binary behaviour but only in memory.Original long explanation :
I have several devices which I could not modify and do not have complete source code.
Devices receive UDP stream in custom format. Some UDP frames contains H264 video in some kind of header wrapper.
After I unwrap packets I have list of complete H264 NALs (all video payload packets starts with0x00 0x00 0x00 0x01
).
My test decoding similar to one in devices looks like this :
InitH264Parser::H264Parser(IMatConsumer& receiver) :
_receiver(receiver)
{
av_register_all();
_codec = avcodec_find_decoder(AV_CODEC_ID_H264);
_codecContext = avcodec_alloc_context3(_codec);
_codecContext->refcounted_frames = 0;
_codecContext->bit_rate = 0;
_codecContext->flags |= CODEC_FLAG_INPUT_PRESERVED | CODEC_FLAG_LOW_DELAY | CODEC_FLAG_LOOP_FILTER;
if (_codec->capabilities & CODEC_CAP_TRUNCATED)
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
_codecContext->flags2 |= CODEC_FLAG2_CHUNKS | CODEC_FLAG2_NO_OUTPUT | CODEC_FLAG2_FAST;
_codecContext->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE | CODEC_FLAG2_IGNORE_CROP | CODEC_FLAG2_SHOW_ALL;
_codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
_codecContext->field_order = AV_FIELD_UNKNOWN;
_codecContext->request_sample_fmt = AV_SAMPLE_FMT_NONE;
_codecContext->workaround_bugs = FF_BUG_AUTODETECT;
_codecContext->strict_std_compliance = FF_COMPLIANCE_NORMAL;
_codecContext->error_concealment = FF_EC_DEBLOCK;
_codecContext->idct_algo = FF_IDCT_AUTO;
_codecContext->thread_count = 0;
_codecContext->thread_type = FF_THREAD_FRAME;
_codecContext->thread_safe_callbacks = 0;
_codecContext->skip_loop_filter = AVDISCARD_DEFAULT;
_codecContext->skip_idct = AVDISCARD_DEFAULT;
_codecContext->skip_frame = AVDISCARD_DEFAULT;
_codecContext->pkt_timebase.num = 1;
_codecContext->pkt_timebase.den = -1;
if (avcodec_open2(_codecContext, _codec, nullptr) != 0) {
L_ERROR("Could not open codec");
}
L_INFO("H264 codec opened succesfully");
_frame = av_frame_alloc();
if (_frame == nullptr) {
L_ERROR("Could not allocate single frame");
}
_rgbFrame = av_frame_alloc();
int frameBytesCount = avpicture_get_size(AV_PIX_FMT_BGR24, INITIAL_PICTURE_WIDTH, INITIAL_PICTURE_HEIGHT);
_buffer = (uint8_t*)av_malloc(frameBytesCount * sizeof(frameBytesCount));
avpicture_fill((AVPicture*)_rgbFrame, _buffer, AV_PIX_FMT_BGR24, INITIAL_PICTURE_WIDTH, INITIAL_PICTURE_HEIGHT);
_packet.dts = AV_NOPTS_VALUE;
_packet.stream_index = 0;
_packet.flags = 0;
_packet.side_data = nullptr;
_packet.side_data_elems = 0;
_packet.duration = 0;
_packet.pos = -1;
_packet.convergence_duration = AV_NOPTS_VALUE;
if (avpicture_alloc(&_rgbPicture, AV_PIX_FMT_BGR24, INITIAL_PICTURE_WIDTH, INITIAL_PICTURE_HEIGHT) != 0) {
L_ERROR("Could not allocate RGB picture");
}
_width = INITIAL_PICTURE_WIDTH;
_height = INITIAL_PICTURE_HEIGHT;
_convertContext = sws_getContext(INITIAL_PICTURE_WIDTH, INITIAL_PICTURE_HEIGHT, AV_PIX_FMT_YUV420P,
INITIAL_PICTURE_WIDTH, INITIAL_PICTURE_HEIGHT, AV_PIX_FMT_BGR24,
SWS_BILINEAR, nullptr, nullptr, nullptr);
if (_convertContext == nullptr) {
L_ERROR("Faild to initialize SWS convert context");
}
_skipBad = false;
_initialized = true;
}Decoding NALs received from unwrapper :
void H264Parser::handle(const uint8_t * nalUnit, int size)
{
static int packetIndex = 0;
bool result = false;
if (!_initialized)
return;
_packet.buf = nullptr;
_packet.pts = packetIndex;
_packet.data = (uint8_t*)nalUnit;
_packet.size = size;
int frameFinished = 0;
int length = avcodec_decode_video2(_codecContext, _frame, &frameFinished, &_packet);
if (_skipBad) {
L_ERROR("We should not skip bad frames");
}
int width = 0;
int height = 0;
if (((_frame->pict_type == AV_PICTURE_TYPE_I) ||
(_frame->pict_type == AV_PICTURE_TYPE_P) ||
(_frame->pict_type == AV_PICTURE_TYPE_B)) &&
(length > 0) && (frameFinished > 0)) {
L_DEBUG("Found picture type: %d", _frame->pict_type);
if ((_codecContext->width != _width) && (_codecContext->height != _height)) {
if (_convertContext != nullptr) {
sws_freeContext(_convertContext);
_convertContext = nullptr;
}
_convertContext = sws_getContext(_codecContext->width, _codecContext->height, AV_PIX_FMT_YUV420P,
_codecContext->width, _codecContext->height, AV_PIX_FMT_BGR24,
SWS_BILINEAR, nullptr, nullptr, nullptr);
if (_convertContext == nullptr) {
L_ERROR("Could not create SWS convert context for new width and height");
return;
}
avpicture_free(&_rgbPicture);
if (avpicture_alloc(&_rgbPicture, AV_PIX_FMT_BGR24, _codecContext->width, _codecContext->height) != 0) {
L_ERROR("Could not allocate picture for new width and height");
}
_width = _codecContext->width;
_height = _codecContext->height;
}
if (sws_scale(_convertContext, _frame->data, _frame->linesize, 0, _codecContext->height, _rgbPicture.data, _rgbPicture.linesize) == _codecContext->height) {
width = _codecContext->width;
height = _codecContext->height;
cv::Mat mat(height, width, CV_8UC3, _rgbPicture.data[0], _rgbPicture.linesize[0]);
_receiver.onImage(mat);
}
}
}It workings and decode images correctly from existing encoding devices.
P.S. : There small issue with FFMPEG print warning to console "[h264 @ 00000000024ad860] data partitioning is not implemented.". But I suppose it is problem with encoding devices.How is question part.
I need to create another encoding device with settings compatible with decoding described above.
From tutorials or other Stack Overflow questions people mostly need to write H264 stream to file or direct to UDP without custom wrapping.
I need to create NALs packets in memory.Can someone provide correct code for initialization and encoding series of images into series of complete NALs packets ?
I’ve tried to create encoding using following code :
InitH264Encoder::H264Encoder(int width, int height, int fpsRationalHigh, int fpsRationalLow) :
_frameCounter(0),
_output("video_encoded.h264", std::ios::binary)
{
av_register_all();
avcodec_register_all();
_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!_codec) {
L_ERROR("Could not find H264 encoder");
throw std::runtime_error("Could not find H264 encoder");
}
_codecContext = avcodec_alloc_context3(_codec);
if (!_codecContext) {
L_ERROR("Cound not open codec context for H264 encoder");
throw std::runtime_error("Cound not open codec context for H264 encoder");
}
_codecContext->width = width;
_codecContext->height = height;
_codecContext->time_base = AVRational{ fpsRationalLow, fpsRationalHigh };
_codecContext->framerate = AVRational{ fpsRationalHigh, fpsRationalLow };
_codecContext->bit_rate = BIT_RATE;
_codecContext->bit_rate_tolerance = 0;
_codecContext->rc_max_rate = 0;
_codecContext->gop_size = GOP_SIZE;
_codecContext->flags |= CODEC_FLAG_LOOP_FILTER;
// _codecContext->refcounted_frames = 0;
av_opt_set(_codecContext->priv_data, "preset", "fast", 0);
av_opt_set(_codecContext->priv_data, "tune", "zerolatency", 0);
av_opt_set(_codecContext->priv_data, "vprofile", "baseline", 0);
_codecContext->max_b_frames = 1;
_codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
//_codecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
if (avcodec_open2(_codecContext, _codec, nullptr) != 0) {
L_ERROR("Could not open codec");
throw std::runtime_error("Could not open codec");
}
L_INFO("H264 codec opened succesfully");
_frame = av_frame_alloc();
if (_frame == nullptr) {
L_ERROR("Could not allocate single frame");
}
_frame->format = _codecContext->pix_fmt;
_frame->width = width;
_frame->height = height;
av_frame_get_buffer(_frame, 1);
_rgbFrame = av_frame_alloc();
_rgbFrame->format = AV_PIX_FMT_BGR24;
_rgbFrame->width = width;
_rgbFrame->height = height;
av_frame_get_buffer(_rgbFrame, 1);
_width = width;
_height = height;
_convertContext = sws_getContext(width, height, AV_PIX_FMT_BGR24,
width, height, AV_PIX_FMT_YUV420P,
SWS_BILINEAR, nullptr, nullptr, nullptr);
if (_convertContext == nullptr) {
L_ERROR("Faild to initialize SWS convert context");
}
_skipBad = false;
_initialized = true;
}Encoding
void H264Encoder::processImage(const cv::Mat & mat)
{
av_init_packet(&_packet);
_packet.data = nullptr;
_packet.size = 0;
_packet.pts = _frameCounter;
_rgbFrame->data[0] = (uint8_t*)mat.data;
// av_image_fill_arrays(_rgbFrame->data, _rgbFrame->linesize, _buffer, (AVPixelFormat)_rgbFrame->format, _rgbFrame->width, _rgbFrame->height, 1);
if (sws_scale(_convertContext, _rgbFrame->data, _rgbFrame->linesize, 0, _codecContext->height, _frame->data, _frame->linesize) == _codecContext->height) {
L_DEBUG("BGR frame converted to YUV");
}
else {
L_DEBUG("Could not convert BGR frame to YUV");
}
int retSendFrame = avcodec_send_frame(_codecContext, _frame);
int retReceivePacket = avcodec_receive_packet(_codecContext, &_packet);
if (retSendFrame == AVERROR(EAGAIN)) {
L_DEBUG("Buffers are filled");
}
if (retReceivePacket == 0) {
_packet.pts = _frameCounter;
L_DEBUG("Got frame (Frame index: %4d)", _frameCounter);
_output.write((char*)_packet.data, _packet.size);
av_packet_unref(&_packet);
}
else {
L_DEBUG("No frame at moment. (Frame index: %4d)", _frameCounter);
}
_frameCounter++;
}But this code produce incorrect output. FFMPEG itself could not understand test ```video_encoded.h264`` file.
It output errors like this :[h264 @ 00000000006da940] decode_slice_header error
[h264 @ 00000000006da940] non-existing PPS 0 referenced
[h264 @ 00000000006da940] decode_slice_header error
[h264 @ 00000000006da940] non-existing PPS 0 referenced
[h264 @ 00000000006da940] decode_slice_header error
[h264 @ 00000000006da940] non-existing PPS 0 referenced
[h264 @ 00000000006da940] decode_slice_header error
[h264 @ 00000000006da940] non-existing PPS 0 referenced
[h264 @ 00000000006da940] decode_slice_header error
[h264 @ 00000000006da940] non-existing PPS 0 referenced
[h264 @ 00000000006da940] decode_slice_header error
[h264 @ 00000000006da940] non-existing PPS 0 referenced
[h264 @ 00000000006da940] decode_slice_header error
[h264 @ 00000000006da940] no frame!
[h264 @ 00000000006da940] non-existing PPS 0 referenced
[h264 @ 00000000026196a0] decoding for stream 0 failed
[h264 @ 00000000026196a0] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, h264, from 'video_encoded.h264':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264, none, 25 fps, 25 tbr, 1200k tbn, 50 tbc
[mp4 @ 00000000026d00a0] dimensions not set
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Last message repeated 1 timesWhen I’ve opened file in HEX editor I found FFMPEG logo text (WHY ??) in beginning. It looks like this
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000 00 00 00 01 67 64 00 1F AC EC 05 00 5B A1 00 00 gd ¬ì [¡
00000010 03 00 01 00 00 03 00 32 8F 18 31 38 00 00 00 01 2 18
00000020 68 EA EC B2 2C 00 00 01 06 05 FF FF BE DC 45 E9 hêì², ÿÿ¾ÜEé
00000030 BD E6 D9 48 B7 96 2C D8 20 D9 23 EE EF 78 32 36 ½æÙH·–,Ø Ù#îïx26
00000040 34 20 2D 20 63 6F 72 65 20 31 35 32 20 72 32 38 4 - core 152 r28
00000050 35 31 20 62 61 32 34 38 39 39 20 2D 20 48 2E 32 51 ba24899 - H.2
00000060 36 34 2F 4D 50 45 47 2D 34 20 41 56 43 20 63 6F 64/MPEG-4 AVC co
00000070 64 65 63 20 2D 20 43 6F 70 79 6C 65 66 74 20 32 dec - Copyleft 2
00000080 30 30 33 2D 32 30 31 37 20 2D 20 68 74 74 70 3A 003-2017 - http:
00000090 2F 2F 77 77 77 2E 76 69 64 65 6F 6C 61 6E 2E 6F //www.videolan.o
000000A0 72 67 2F 78 32 36 34 2E 68 74 6D 6C 20 2D 20 6F rg/x264.html - o
000000B0 70 74 69 6F 6E 73 3A 20 63 61 62 61 63 3D 31 20 ptions: cabac=1
000000C0 72 65 66 3D 32 20 64 65 62 6C 6F 63 6B 3D 31 3A ref=2 deblock=1:
000000D0 30 3A 30 20 61 6E 61 6C 79 73 65 3D 30 78 33 3A 0:0 analyse=0x3:
000000E0 30 78 31 31 33 20 6D 65 3D 68 65 78 20 73 75 62 0x113 me=hex sub
000000F0 6D 65 3D 36 20 70 73 79 3D 31 20 70 73 79 5F 72 me=6 psy=1 psy_r
00000100 64 3D 31 2E 30 30 3A 30 2E 30 30 20 6D 69 78 65 d=1.00:0.00 mixe
00000110 64 5F 72 65 66 3D 31 20 6D 65 5F 72 61 6E 67 65 d_ref=1 me_range
00000120 3D 31 36 20 63 68 72 6F 6D 61 5F 6D 65 3D 31 20 =16 chroma_me=1
00000130 74 72 65 6C 6C 69 73 3D 31 20 38 78 38 64 63 74 trellis=1 8x8dct
00000140 3D 31 20 63 71 6D 3D 30 20 64 65 61 64 7A 6F 6E =1 cqm=0 deadzon
00000150 65 3D 32 31 2C 31 31 20 66 61 73 74 5F 70 73 6B e=21,11 fast_psk
00000160 69 70 3D 31 20 63 68 72 6F 6D 61 5F 71 70 5F 6F ip=1 chroma_qp_o
00000170 66 66 73 65 74 3D 2D 32 20 74 68 72 65 61 64 73 ffset=-2 threads
00000180 3D 38 20 6C 6F 6F 6B 61 68 65 61 64 5F 74 68 72 =8 lookahead_thr
00000190 65 61 64 73 3D 38 20 73 6C 69 63 65 64 5F 74 68 eads=8 sliced_th
000001A0 72 65 61 64 73 3D 31 20 73 6C 69 63 65 73 3D 38 reads=1 slices=8
000001B0 20 6E 72 3D 30 20 64 65 63 69 6D 61 74 65 3D 31 nr=0 decimate=1
000001C0 20 69 6E 74 65 72 6C 61 63 65 64 3D 30 20 62 6C interlaced=0 bl
000001D0 75 72 61 79 5F 63 6F 6D 70 61 74 3D 30 20 63 6F uray_compat=0 co
000001E0 6E 73 74 72 61 69 6E 65 64 5F 69 6E 74 72 61 3D nstrained_intra=
000001F0 30 20 62 66 72 61 6D 65 73 3D 31 20 62 5F 70 79 0 bframes=1 b_py
00000200 72 61 6D 69 64 3D 30 20 62 5F 61 64 61 70 74 3D ramid=0 b_adapt=
00000210 31 20 62 5F 62 69 61 73 3D 30 20 64 69 72 65 63 1 b_bias=0 direc
00000220 74 3D 31 20 77 65 69 67 68 74 62 3D 31 20 6F 70 t=1 weightb=1 op
00000230 65 6E 5F 67 6F 70 3D 30 20 77 65 69 67 68 74 70 en_gop=0 weightp
00000240 3D 31 20 6B 65 79 69 6E 74 3D 35 20 6B 65 79 69 =1 keyint=5 keyi
00000250 6E 74 5F 6D 69 6E 3D 31 20 73 63 65 6E 65 63 75 nt_min=1 scenecu
00000260 74 3D 34 30 20 69 6E 74 72 61 5F 72 65 66 72 65 t=40 intra_refre
00000270 73 68 3D 30 20 72 63 3D 61 62 72 20 6D 62 74 72 sh=0 rc=abr mbtr
00000280 65 65 3D 30 20 62 69 74 72 61 74 65 3D 31 32 30 ee=0 bitrate=120
00000290 30 20 72 61 74 65 74 6F 6C 3D 31 2E 30 20 71 63 0 ratetol=1.0 qc
000002A0 6F 6D 70 3D 30 2E 36 30 20 71 70 6D 69 6E 3D 30 omp=0.60 qpmin=0
000002B0 20 71 70 6D 61 78 3D 36 39 20 71 70 73 74 65 70 qpmax=69 qpstep
000002C0 3D 34 20 69 70 5F 72 61 74 69 6F 3D 31 2E 34 30 =4 ip_ratio=1.40
000002D0 20 70 62 5F 72 61 74 69 6F 3D 31 2E 33 30 20 61 pb_ratio=1.30 a
000002E0 71 3D 31 3A 31 2E 30 30 00 80 00 q=1:1.00 €I support additional I need to create AVFormatContext and create stream. But I don’t know how to create it for RAW H264 and most important to not write output to file but to memory buffer.
Can someone help me ?