Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 15/06/2025, à 09:10

Jarodd

Ffmpeg : compréhension des options

Bonjour,

J'utilise ffmpeg pour couper des vidéos faite avec un APN, ou des enregistrements sur la TNT. J'ai des interrogations sur ses options.

1/ j'ai un fichier vidéo mp4. Quand je veux supprimer une partie inintéressante, je fais cette commande :*

ffmpeg -i input.mp4 -y -c copy -to 30 output.mp4

-y permet de valider toutes les demandes de confirmation
-c copy permet de recréer le fichier avec les mêmes codecs qu'en entrée (audio, vidéo, sous-titres)
-to 30 coupe la vidéo à la 30e seconde.

Si j'omets -to (ou -t pour spécifier une durée), output.mp4 est censée être identique à input.mp4. Mais j'observe une différence de poids final. Par exemple, input.mp4 fait 105 Mo, mais output.mp4 fait 70 Mo.
Je ne comprends pas pourquoi puisque les codecs et la durée sont les mêmes.

2/ pour certains enregistrements tnt, je souhaite conserver les sous-titres (l'audio-description fournie sur certaines chaînes). Je coupe avec cette commande :

ffmpeg -i input.mp4 -y -c copy -ss 10:00 -to 20:00 output.mp4

Or cette commande crée un fichier sans les sous-titres. Pour les avoir, je dois faire ainsi :

ffmpeg -i input.mp4 -y -c copy -map 0 -scodec copy -ss 10:00 -to 20:00 output.mp4

J'ai trouvé l'astuce suite à une recherche sur le web, mais je ne comprends pas pourquoi il faut ajouter -map 0 -scodec copy, puisque d'après ce que je comprends, -c copy englobe les sous-titres. Je n'ai pas trouvé d'explication ni sur le web, ni dans la doc (qui est très verbeuse).

Merci pour votre aide.


Ubuntu 22.04.3 LTS (64 bits)

Hors ligne

#2 Le 16/06/2025, à 10:08

hotnuma

Re : Ffmpeg : compréhension des options

Pour le point 1 :

En utilisant -c copy il n'y a pas d'encodage, donc pas de codecs mais une copie des flux tels quel, sans modification à part la durée avec -to 30.

La différence de taille est sans doute due à un des flux qui n'est pas copié, des sous-titres, des chapitres, une piste audio ou je ne sais pas quoi qui n'est pas copié.

Pour vérifier ce que contient le fichier ffprobe peut être utile :

ffprobe -hide_banner "fichier.mp4"

En comparant les deux fichiers, la lumière doit normalement jaillir. big_smile

Le point 2 est en rapport.

Il me semble que par défaut, tous les flux ne sont pas copiés, donc il faut spécifier ce qu'on veut inclure.

En utilisant ffprobe vous pouvez lister les flux contenus dans chaque fichier et comprendre aussi le point 2 de cette façon.

Dernière modification par hotnuma (Le 16/06/2025, à 10:22)

Hors ligne

#3 Le 26/06/2025, à 18:04

Jarodd

Re : Ffmpeg : compréhension des options

Oh j'ai une réponse, alors que je n'ai pas reçu de notif big_smile

Voici ce que me donne ffprobe :

$ ffprobe -hide_banner fichier.ts 
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] decode_slice_header error
[h264 @ 0x587a790ddbc0] no frame!
[h264 @ 0x587a790ddbc0] mmco: unref short failure
    Last message repeated 1 times
[h264 @ 0x587a790ddbc0] number of reference frames (0+5) exceeds max (4; probably corrupt input), discarding one
[h264 @ 0x587a790ddbc0] mmco: unref short failure
    Last message repeated 1 times
[mpegts @ 0x587a790b5e40] start time for stream 0 is not set in estimate_timings_from_pts
[mpegts @ 0x587a790b5e40] start time for stream 6 is not set in estimate_timings_from_pts
[mpegts @ 0x587a790b5e40] PES packet size mismatch
[mpegts @ 0x587a790b5e40] Packet corrupt (stream = 2, dts = 6236124433).
[mpegts @ 0x587a790b5e40] PES packet size mismatch
[mpegts @ 0x587a790b5e40] Packet corrupt (stream = 3, dts = 6236124433).
[mpegts @ 0x587a790b5e40] PES packet size mismatch
[mpegts @ 0x587a790b5e40] Packet corrupt (stream = 5, dts = 6236177713).
Input #0, mpegts, from 'fichier.ts':
  Duration: 01:09:58.47, start: 65092.575478, bitrate: 3628 kb/s
  Program 1537 
    Metadata:
      service_name    : TF1
      service_provider: SMR6
  Stream #0:1[0x78]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
  Stream #0:2[0x82](fra): Audio: eac3 ([6][0][0][0] / 0x0006), 48000 Hz, stereo, fltp, 128 kb/s
  Stream #0:3[0x83](qaa): Audio: eac3 ([6][0][0][0] / 0x0006), 48000 Hz, stereo, fltp, 128 kb/s
  Stream #0:4[0x84](fra): Audio: eac3 ([6][0][0][0] / 0x0006), 48000 Hz, stereo, fltp, 96 kb/s (visual impaired) (descriptions)
  Stream #0:5[0x96](fra): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
  Stream #0:6[0x97](fra): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
  Program 1542 
    Metadata:
      service_name    : TMC
      service_provider: SMR6
  Program 1544 
    Metadata:
      service_name    : TFX
      service_provider: SMR6
  Program 1545 
    Metadata:
      service_name    : LCP
      service_provider: SMR6
  Program 1546 
    Metadata:
      service_name    : LCI
      service_provider: SMR6
  No Program
  Stream #0:0[0x12]: Data: epg
Unsupported codec with id 98306 for input stream 0

Ma lecture (peut-être incorrecte) indique :
- 1 piste vidéo
- 3 pistes audio
- 2 pistes sous-titres

Donc le "-c copy" indique bien tous les flux, puisque si on veut spécifier une catégorie, on met "-c:X copy" (avec X=v pour video, a pour audio, s pour les sous-titres) ou bien "-Xcodec copy" (mêmes valeurs).
Donc je ne comprends pas pourquoi video et audio sont bien copiés, mais pas les sous-titres, puisque j'ai besoin d'indiquer explicitement "-scodec copy".


Ubuntu 22.04.3 LTS (64 bits)

Hors ligne