Recherche avancée

Médias (91)

Autres articles (66)

  • Use, discuss, criticize

    13 avril 2011, par

    Talk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
    The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
    A discussion list is available for all exchanges between users.

  • Gestion des droits de création et d’édition des objets

    8 février 2011, par

    Par défaut, beaucoup de fonctionnalités sont limitées aux administrateurs mais restent configurables indépendamment pour modifier leur statut minimal d’utilisation notamment : la rédaction de contenus sur le site modifiables dans la gestion des templates de formulaires ; l’ajout de notes aux articles ; l’ajout de légendes et d’annotations sur les images ;

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

Sur d’autres sites (11326)

  • ffmpeg lags when streaming video+audio from RPi Zero W with Logitech C920

    7 janvier 2021, par Ema

    I've been trying to setup a baby monitor with a Raspberry Pi Zero and a Logitech C920 webcam. I does work with VLC (cvlc) but it lags too much and gets worse over time.

    


    So I am playing around with ffmpeg and I am getting some better results. This is what I've done so far.

    


    First I set the webcam to output h264 1080p natively (the Pi Zero W can't afford to do any transcoding).

    


    v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=1


    


    Now, if I stream audio only with

    


    ffmpeg \
-f alsa \
-i hw:1,0 \
-vn \
-flags +global_header \
-acodec aac \
-ac 1 \
-ar 16000 \
-ab 16k \
-f rtp rtp://192.168.0.10:5002 > audio.sdp


    


    it works great and the lag is about 1 second (definitely acceptable).

    


    If I stream video only with

    


    ffmpeg \
-f v4l2 \
-vcodec h264 \
-i /dev/video0 \
-an \
-vcodec copy \
-pix_fmt yuv420p \
-r 30 \
-b:v 512k \
-flags +global_header \
-f rtp rtp://192.168.0.10:5000 > video.sdp


    


    same result, very little lag (for some reason the first -vcodec is necessary to force the webcam to output h264).

    


    However, when I stream both with

    


    ffmpeg \
-f v4l2 \
-vcodec h264 \
-i /dev/video0 \
-f alsa \
-i hw:1,0 \
-an \
-preset ultrafast \
-tune zerolatency \
-vcodec copy \
-pix_fmt yuv420p \
-r 30 \
-b:v 512k \
-flags +global_header \
-f rtp rtp://192.168.0.10:5000 \
-vn \
-flags +global_header \
-acodec aac \
-ac 1 \
-ar 16000 \
-ab 16k \
-f rtp rtp://192.168.0.10:5002 > both.sdp


    


    the lag ramps up to 10 seconds and audio and video are out of sync. Does anybody know why ?

    


    I've tried UDP and TCP instead of RTP but then the lag is always high, even with audio/video only.

    


    Any suggestion is much appreciated.

    


    P.S. On the client side (MacOS) I'm receiving with

    


    ffplay -protocol_whitelist file,rtp,udp -i file.sdp


    


  • scripting massive number of files with ffmpeg [closed]

    2 décembre 2020, par 8Liter

    Alright, I've got over 5000 MP4 files in a single directory that I would ultimately like to process using ffmpeg. I've got a few different solutions that all work by themselves, but put together do not make my job any easier.
The current file list looks like this, in one single directory :

    


      

    • 10-1.mp4
    • 


    • 10-2.mp4
    • 


    • 10123-1.mp4
    • 


    • 10123-2.mp4
    • 


    • 10123-3.mp4
    • 


    • 10123-4.mp4
    • 


    • 10123-5.mp4
    • 


    • 10123-6.mp4
    • 


    • 102-1.mp4
    • 


    • 103-1.mp4
    • 


    • 103-2.mp4
    • 


    • 103-3.mp4
    • 


    • 107-1.mp4
    • 


    • 107-2.mp4
    • 


    • 107-3.mp4
    • 


    • 107-4.mp4
    • 


    • 107-5.mp4
    • 


    • 107-6.mp4
    • 


    • 11-1.mp4
    • 


    • 11-2.mp4
    • 


    


    The ideal process I would like is the following :

    


    A. Take however many files in the directory have a particular prefix, for example the two "11" files at the bottom, and concatenate them into a single MP4 file. The end result is a single "11.MP4"

    


    B. Delete the original two "11-1.mp4" and "11-2.mp4", keeping only the new "11.mp4" complete file.

    


    C. Repeat steps A-B for all other files in this directory

    


    This is not apparently possible right now from what I can glean from other threads, but I've tested a more manual approach which is not clean OR fast, and this is what my workflow looks like in real life...

    


      

    1. move files with same prefix into new folder (I have a working bat file that will do this for me)
    2. 


    3. run a ffmpeg bat file to process an "output.mp4" file (I have a working bat file that will do this for me)
    4. 


    5. delete the original files
    6. 


    7. rename the output.mp4 file to the prefix name (i.e. 11.mp4)
    8. 


    9. copy that file back into the new directory
    10. 


    11. repeat steps 1-5 a thousand times.
    12. 


    


    I've also looked into creating all new directories BASED on the filename (I have a working bat file that will do this for me) and then copy my ffmpeg bat file into each directory, and run each bat file manually... but again it's a ton of work.

    


    (FROM STEP 1 ABOVE)

    


    @echo off
setlocal

set "basename=."
for /F "tokens=1* delims=.*" %%a in ('dir /B /A-D ^| sort /R') do (
   set "filename=%%a"
   setlocal EnableDelayedExpansion
   for /F "delims=" %%c in ("!basename!") do if "!filename:%%c=!" equ "!filename!" (
      set "basename=!filename!"
      md "!basename!"
   )
   move "!filename!.%%b" "!basename!"
   for /F "delims=" %%c in ("!basename!") do (
      endlocal
      set "basename=%%c

   )
)


    


    (FROM STEP 2 ABOVE)

    


    :: Create File List
del "F:\videos\*.txt" /s /f /q
for %%i in (*.mp4) do echo file '%%i'>> mylist.txt

:: Concatenate Files
ffmpeg.exe -f concat -safe 0 -i mylist.txt -c copy output.mp4


    


    Any ideas how I can approach this ? I'm open to powershell, batch, even python if I need to.

    


  • FFMPEG on AWS Lambda works selectively

    20 novembre 2020, par Arindam Baral

    I am using FFMpeg on AWS Lambda to convert mp4 files to m3u8 format.

    


    Here's my code :

    


    ENCODE_SIZE = {
    '360p': ('360:640', '1000000'),
    '540p': ('540:960', '2000000'),
    '720p': ('720:1280', '5000000')
}
@app.route('/encode', methods=['GET'])
@token_required
def encodeVideo(current_user):
    try:
        userEmail = current_user.emailID
        
        courseID = request.args.get('courseID')
        fileKey = request.args.get('fileKey')
        print ('Input file key received ', fileKey)
        convType = 'all'
        if 'convType' in request.args:
            convType = request.args.get('convType')
        print ('Conv Type::::', convType)
        instiID = Course.query.filter_by(id=courseID).first().instiID
        adminEmail = Institute.query.filter_by(id=instiID).first().adminEmail
        if adminEmail != userEmail:
            return jsonify({'message': 'Not authorized'}), 403
        
        bucket = app.config['S3_CONTENT_FOLDER']
        folder = '/'.join(fileKey.split('/')[:-1])
        
        os.system('cp /var/task/ffmpeg /tmp/; chmod 755 /tmp/ffmpeg;')
        FFMPEG_STATIC = '/tmp/ffmpeg' #"/opt/bin/ffmpeg" # 
        # FFMPEG_STATIC = 'ffmpeg' #"/opt/bin/ffmpeg" # 
        
        preSignURL = getPreSignedS3URL(fileKey, bucket)
        print (preSignURL)
        
        outputFlag = []
        
        # outFileName = 'final_out.m3u8'
        outFileName = '/tmp/final_out.m3u8'
        with open(outFileName, 'a') as outFile:
            outFile.write('#EXTM3U\n')
            
            if convType == 'all':
                for ver in ENCODE_SIZE:
                    print ('Starting for ver ', ver)
                    outFileNameM3 = '/tmp/%s_out.m3u8' %(ver) 
                    # outFileNameM3 = '%s_out.m3u8' %(ver) 
                    
                    subprocess.call([FFMPEG_STATIC, '-i', preSignURL, '-c:a', 'aac', '-c:v', 'libx264', '-s', ENCODE_SIZE[ver][0], '-f', 'hls', '-hls_list_size', '0', '-hls_time', '10', outFileNameM3])
                    
                    outFile.write('#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=%s %s\n' %(
                        ENCODE_SIZE[ver][1], outFileName
                    ))
                    # ret = os.system(commandStr)
                    # outputFlag.append(ret)
                    print ('Encoding completed for ver ', ver)
            else:
                ver = convType
                outFileNameM3 = '/tmp/%s_out.m3u8' %(ver) 
                # outFileNameM3 = '%s_out.m3u8' %(ver) 

                subprocess.call([FFMPEG_STATIC, '-i', preSignURL, '-c:a', 'aac', '-c:v', 'libx264', '-s', ENCODE_SIZE[ver][0], '-f', 'hls', '-hls_list_size', '0', '-hls_time', '10', outFileNameM3])  
                    
                outFile.write('#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=%s %s\n' %(
                        ENCODE_SIZE[ver][1], outFileName
                ))
                # ret = os.system(commandStr)
                # outputFlag.append(ret)
        outFile.close()
        print ('File Key Generated')
        #Upload files to s3
        streamFiles = glob.glob('/tmp/*.ts')
        print (streamFiles)
        for fl in streamFiles:
            finFileName = fl.split('/')[-1]
            fileKeyName = folder + '/' + finFileName
            uploadFileToS3(fl, fileKeyName, app.config['S3_CONTENT_FOLDER'])
        # m3u8Files = glob.glob('/tmp/*.m3u8')
        # print (m3u8Files)
        # for fl in m3u8Files:
        #     finFileName = fl.split('/')[-1]
        #     fileKeyName = folder + '/' + finFileName
        #     uploadFileToS3(fl, fileKeyName, app.config['S3_CONTENT_FOLDER'])
        # print ('S3 upload completed')
        
        # files = glob.glob('/tmp/*')
        # for f in files:
        #     os.remove(f)
        return jsonify({'message': 'Completed file encoding'}), 201
    except:
        print (traceback.format_exc())
        return jsonify({'message': 'Error in encoding file'}), 504
if __name__ == '__main__':
    app.run(debug=True,host="0.0.0.0", port=5000)



    


    When I request for "540p", the m3u8 file gets converted perfectly.
However, when I request for "360p" and "720p", I see only the first 1 second of the video.

    


    Please note - All the tls files are generated in all the cases. The problem is only in creation of the m3u8 playlist file.

    


    Can someone please help in this regard ?

    


    EDIT 1 : I am quite new to FFMPEG. So any help here will be very welcome

    


    The log files are present here :
https://drive.google.com/file/d/1QFgi-4jDIN3f6mWLoR999mlXzZ-Ij83R/view?usp=sharing