@@ -1517,6 +1517,7 @@ int main(int argc, const char *argv[])
15171517 mkv_timestamp_t PrevTimestamp ;
15181518 bool_t CuesChanged ;
15191519 bool_t KeepCues = 0 , Remux = 0 , CuesCreated = 0 , Optimize = 0 , OptimizeVideo = 1 , UnOptimize = 0 , ClustersNeedRead = 0 , Regression = 0 ;
1520+ MatroskaTrackEncodingCompAlgo CompressionAlgo = MATROSKA_TRACK_ENCODING_COMP_ZLIB ;
15201521 int InputPathIndex = 1 ;
15211522 int64_t TimestampScale = 0 , OldTimestampScale ;
15221523 size_t MaxTrackNum = 0 ;
@@ -1623,6 +1624,26 @@ int main(int argc, const char *argv[])
16231624 else if (tcsisame_ascii (Path ,T ("--unsafe" ))) { Unsafe = 1 ; InputPathIndex = i + 1 ; }
16241625 else if (tcsisame_ascii (Path ,T ("--optimize" ))) { Optimize = 1 ; OptimizeVideo = 1 ; InputPathIndex = i + 1 ; }
16251626 else if (tcsisame_ascii (Path ,T ("--optimize_nv" ))) { Optimize = 1 ; OptimizeVideo = 0 ; InputPathIndex = i + 1 ; }
1627+ else if (tcsisame_ascii (Path ,T ("--compalgo" )) && i + 1 < argc - 1 )
1628+ {
1629+ #if defined(TARGET_WIN ) && defined(UNICODE )
1630+ Node_FromWcs (& p ,Path ,TSIZEOF (Path ),argv [++ i ]);
1631+ #else
1632+ Node_FromStr (& p ,Path ,TSIZEOF (Path ),argv [++ i ]);
1633+ #endif
1634+ if (tcsisame_ascii (Path ,T ("0" )))
1635+ CompressionAlgo = MATROSKA_TRACK_ENCODING_COMP_ZLIB ;
1636+ else if (tcsisame_ascii (Path ,T ("4" )))
1637+ CompressionAlgo = MATROSKA_TRACK_ENCODING_COMP_ZSTD ;
1638+ else
1639+ {
1640+ TextPrintf (StdErr ,T ("Unknown compression algorithm %s (0: zlib, 4: Zstd)\r\n" ),Path );
1641+ Path [0 ] = 0 ;
1642+ Result = -8 ;
1643+ goto exit ;
1644+ }
1645+ InputPathIndex = i + 1 ;
1646+ }
16261647 else if (tcsisame_ascii (Path ,T ("--regression" ))) { Regression = 1 ; InputPathIndex = i + 1 ; }
16271648 else if (tcsisame_ascii (Path ,T ("--no-optimize" ))) { UnOptimize = 1 ; InputPathIndex = i + 1 ; }
16281649 else if (tcsisame_ascii (Path ,T ("--quiet" ))) { Quiet = 1 ; InputPathIndex = i + 1 ; }
@@ -1650,6 +1671,7 @@ int main(int argc, const char *argv[])
16501671 TextWrite (StdErr ,T (" --live the output file resembles a live stream\r\n" ));
16511672 TextWrite (StdErr ,T (" --timecodescale <v> force the global TimestampScale to <v> (1000000 is a good value)\r\n" ));
16521673 TextWrite (StdErr ,T (" --unsafe don't output elements that are used for file recovery (saves more space)\r\n" ));
1674+ TextWrite (StdErr ,T (" --compalgo <v> force compression algorithm of all tracks\r\n" ));
16531675 TextWrite (StdErr ,T (" --optimize use all possible optimization for the output file\r\n" ));
16541676 TextWrite (StdErr ,T (" --optimize_nv use all possible optimization for the output file, except video tracks\r\n" ));
16551677 TextWrite (StdErr ,T (" --no-optimize disable some optimization for the output file\r\n" ));
@@ -2809,13 +2831,24 @@ int main(int argc, const char *argv[])
28092831 if (CodecPrivate != NULL )
28102832 {
28112833 size_t ExtraCompHeaderBytes = (encoding == MATROSKA_TRACK_ENCODING_COMP_NONE ) ? 13 : 3 ; // extra bytes needed to add the comp header to the track
2834+ if (CompressionAlgo != MATROSKA_TRACK_ENCODING_COMP_ZLIB )
2835+ ExtraCompHeaderBytes += 1 ; // extra for the non default algo
28122836 size_t CompressedSize = (size_t )EBML_ElementDataSize ((ebml_element * )CodecPrivate , 1 );
28132837 size_t origCompressedSize = CompressedSize ;
28142838 uint8_t * Compressed = malloc (CompressedSize );
2815- if (CompressFrameZLib (EBML_BinaryGetData (CodecPrivate ), origCompressedSize , & Compressed , & CompressedSize )== ERR_NONE
2816- && (CompressedSize + ExtraCompHeaderBytes ) < origCompressedSize )
2839+ uint8_t * NewCompressed = Compressed ;
2840+ int comp_err ;
2841+ if (CompressionAlgo == MATROSKA_TRACK_ENCODING_COMP_ZSTD )
2842+ {
2843+ comp_err = CompressFrameZstd (EBML_BinaryGetData (CodecPrivate ), origCompressedSize , & NewCompressed , & CompressedSize );
2844+ }
2845+ else
28172846 {
2818- encoding = MATROSKA_TRACK_ENCODING_COMP_ZLIB ;
2847+ comp_err = CompressFrameZLib (EBML_BinaryGetData (CodecPrivate ), origCompressedSize , & NewCompressed , & CompressedSize );
2848+ }
2849+ if (comp_err == ERR_NONE && (CompressedSize + ExtraCompHeaderBytes ) < origCompressedSize )
2850+ {
2851+ encoding = CompressionAlgo ;
28192852 compress_scope |= MATROSKA_CONTENTENCODINGSCOPE_PRIVATE ;
28202853 }
28212854 free (Compressed );
@@ -2830,6 +2863,12 @@ int main(int argc, const char *argv[])
28302863 if (MATROSKA_TrackSetCompressionAlgo ((matroska_trackentry * )RLevel1 , compress_scope ,DstProfile , MATROSKA_TRACK_ENCODING_COMP_ZLIB ))
28312864 ClustersNeedRead = 1 ;
28322865 break ;
2866+ #if defined(CONFIG_ZSTD )
2867+ case MATROSKA_TRACK_ENCODING_COMP_ZSTD :
2868+ if (MATROSKA_TrackSetCompressionAlgo ((matroska_trackentry * )RLevel1 , compress_scope ,DstProfile , MATROSKA_TRACK_ENCODING_COMP_ZSTD ))
2869+ ClustersNeedRead = 1 ;
2870+ break ;
2871+ #endif
28332872 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP :
28342873 if (!HeaderData || MATROSKA_TrackSetCompressionHeader ((matroska_trackentry * )RLevel1 , ARRAYBEGIN (* HeaderData ,uint8_t ), ARRAYCOUNT (* HeaderData ,uint8_t ), DstProfile ))
28352874 ClustersNeedRead = 1 ;
0 commit comments